681 /*********************/ |
680 /*********************/ |
682 /* B 1.4 - Variables */ |
681 /* B 1.4 - Variables */ |
683 /*********************/ |
682 /*********************/ |
684 // SYM_REF1(symbolic_variable_c, var_name) |
683 // SYM_REF1(symbolic_variable_c, var_name) |
685 void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) { |
684 void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) { |
686 symbol->scope = current_scope; // the scope in which this variable was declared! |
|
687 symbol->var_name->datatype = symbol->datatype; |
685 symbol->var_name->datatype = symbol->datatype; |
688 return NULL; |
686 return NULL; |
689 } |
687 } |
690 /********************************************/ |
688 /********************************************/ |
691 /* B 1.4.1 - Directly Represented Variables */ |
689 /* B 1.4.1 - Directly Represented Variables */ |
705 symbol->subscripted_variable->accept(*this); // visit recursively |
703 symbol->subscripted_variable->accept(*this); // visit recursively |
706 |
704 |
707 if (symbol->subscripted_variable->candidate_datatypes.size() == 1) |
705 if (symbol->subscripted_variable->candidate_datatypes.size() == 1) |
708 symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype |
706 symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype |
709 |
707 |
710 // the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !) |
|
711 symbol->scope = symbol->subscripted_variable->scope; |
|
712 return NULL; |
708 return NULL; |
713 } |
709 } |
714 |
710 |
715 |
711 |
716 /* subscript_list ',' subscript */ |
712 /* subscript_list ',' subscript */ |
798 void *narrow_candidate_datatypes_c::visit(function_declaration_c *symbol) { |
793 void *narrow_candidate_datatypes_c::visit(function_declaration_c *symbol) { |
799 /* set the function_declaration_c->datatype to the datatype returned by the function! */ |
794 /* set the function_declaration_c->datatype to the datatype returned by the function! */ |
800 symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name); |
795 symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name); |
801 symbol->datatype = symbol->type_name->datatype; |
796 symbol->datatype = symbol->type_name->datatype; |
802 |
797 |
803 current_scope = symbol; |
|
804 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
798 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
805 symbol->var_declarations_list->accept(*this); |
799 symbol->var_declarations_list->accept(*this); |
806 if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
800 if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
807 symbol->function_body->accept(*this); |
801 symbol->function_body->accept(*this); |
808 delete search_varfb_instance_type; |
802 delete search_varfb_instance_type; |
809 search_varfb_instance_type = NULL; |
803 search_varfb_instance_type = NULL; |
810 current_scope = NULL; |
|
811 return NULL; |
804 return NULL; |
812 } |
805 } |
813 |
806 |
814 /***************************/ |
807 /***************************/ |
815 /* B 1.5.2 Function blocks */ |
808 /* B 1.5.2 Function blocks */ |
816 /***************************/ |
809 /***************************/ |
817 void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) { |
810 void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) { |
818 current_scope = symbol; |
|
819 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
811 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
820 symbol->var_declarations->accept(*this); |
812 symbol->var_declarations->accept(*this); |
821 if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
813 if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
822 symbol->fblock_body->accept(*this); |
814 symbol->fblock_body->accept(*this); |
823 delete search_varfb_instance_type; |
815 delete search_varfb_instance_type; |
824 search_varfb_instance_type = NULL; |
816 search_varfb_instance_type = NULL; |
825 current_scope = NULL; |
|
826 |
817 |
827 // A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such! |
818 // A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such! |
828 if (symbol->candidate_datatypes.size() == 1) |
819 if (symbol->candidate_datatypes.size() == 1) |
829 symbol->datatype = symbol->candidate_datatypes[0]; |
820 symbol->datatype = symbol->candidate_datatypes[0]; |
830 return NULL; |
821 return NULL; |
832 |
823 |
833 /********************/ |
824 /********************/ |
834 /* B 1.5.3 Programs */ |
825 /* B 1.5.3 Programs */ |
835 /********************/ |
826 /********************/ |
836 void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) { |
827 void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) { |
837 current_scope = symbol; |
|
838 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
828 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
839 symbol->var_declarations->accept(*this); |
829 symbol->var_declarations->accept(*this); |
840 if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value); |
830 if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value); |
841 symbol->function_block_body->accept(*this); |
831 symbol->function_block_body->accept(*this); |
842 delete search_varfb_instance_type; |
832 delete search_varfb_instance_type; |
843 search_varfb_instance_type = NULL; |
833 search_varfb_instance_type = NULL; |
844 current_scope = NULL; |
|
845 return NULL; |
834 return NULL; |
846 } |
835 } |
847 |
836 |
848 /********************************************/ |
837 /********************************************/ |
849 /* B 1.6 Sequential function chart elements */ |
838 /* B 1.6 Sequential function chart elements */ |