745 |
745 |
746 /******************************************/ |
746 /******************************************/ |
747 /* B 1.4.3 - Declaration & Initialisation */ |
747 /* B 1.4.3 - Declaration & Initialisation */ |
748 /******************************************/ |
748 /******************************************/ |
749 |
749 |
|
750 /* When handling the declaration of variables the fill/narrow algorithm will simply visit the objects |
|
751 * in the abstract syntax tree defining the desired datatype for the variables. Tis is to set the |
|
752 * symbol->datatype to the basetype of that datatype. |
|
753 * |
|
754 * Note that we do not currently set the symbol->datatype annotation for the identifier_c objects naming the |
|
755 * variables inside the variable declaration. However, this is liable to change in the future, so do not write |
|
756 * any code that depends on this! |
|
757 * |
|
758 * example: |
|
759 * VAR var1, var2, var3 : my_type; END_VAR |
|
760 * (* ^^^^ ^^^^ ^^^^ -> will NOT have the symbol->datatype set (for now, may change in the future!) *) |
|
761 * (* ^^^^^^^ -> WILL have the symbol->datatype set *) |
|
762 * |
|
763 * (remeber too that the identifier_c objects identifying variables inside ST/IL/SFC code *will* have their |
|
764 * symbol->datatype annotation filled by the fill/narrow algorithm) |
|
765 */ |
|
766 void *narrow_candidate_datatypes_c::narrow_var_declaration(symbol_c *type) { |
|
767 if (type->candidate_datatypes.size() == 1) |
|
768 type->datatype = type->candidate_datatypes[0]; |
|
769 type->accept(*this); |
|
770 return NULL; |
|
771 } |
|
772 |
|
773 |
|
774 void *narrow_candidate_datatypes_c::visit(var1_init_decl_c *symbol) {return narrow_var_declaration(symbol->spec_init);} |
|
775 void *narrow_candidate_datatypes_c::visit(array_var_init_decl_c *symbol) {return narrow_var_declaration(symbol->array_spec_init);} |
|
776 void *narrow_candidate_datatypes_c::visit(structured_var_init_decl_c *symbol) {return narrow_var_declaration(symbol->initialized_structure);} |
|
777 void *narrow_candidate_datatypes_c::visit(fb_name_decl_c *symbol) {return narrow_var_declaration(symbol->fb_spec_init);} |
|
778 void *narrow_candidate_datatypes_c::visit(array_var_declaration_c *symbol) {return narrow_var_declaration(symbol->array_specification);} |
|
779 void *narrow_candidate_datatypes_c::visit(structured_var_declaration_c *symbol) {return narrow_var_declaration(symbol->structure_type_name);} |
|
780 void *narrow_candidate_datatypes_c::visit(external_declaration_c *symbol) {return narrow_var_declaration(symbol->specification);} |
|
781 void *narrow_candidate_datatypes_c::visit(global_var_decl_c *symbol) {return narrow_var_declaration(symbol->type_specification);} |
|
782 void *narrow_candidate_datatypes_c::visit(incompl_located_var_decl_c *symbol) {return narrow_var_declaration(symbol->var_spec);} |
|
783 //void *narrow_candidate_datatypes_c::visit(single_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->single_byte_string_spec);} |
|
784 //void *narrow_candidate_datatypes_c::visit(double_byte_string_var_declaration_c *symbol) {return handle_var_declaration(symbol->double_byte_string_spec);} |
|
785 |
|
786 |
|
787 |
750 void *narrow_candidate_datatypes_c::visit(var1_list_c *symbol) { |
788 void *narrow_candidate_datatypes_c::visit(var1_list_c *symbol) { |
751 #if 0 /* We don't really need to set the datatype of each variable. We just check the declaration itself! */ |
789 #if 0 /* We don't really need to set the datatype of each variable. We just check the declaration itself! */ |
752 for(int i = 0; i < symbol->n; i++) { |
790 for(int i = 0; i < symbol->n; i++) { |
753 if (symbol->elements[i]->candidate_datatypes.size() == 1) |
791 if (symbol->elements[i]->candidate_datatypes.size() == 1) |
754 symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[0]; |
792 symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[0]; |
854 |
892 |
855 /********************************/ |
893 /********************************/ |
856 /* B 1.7 Configuration elements */ |
894 /* B 1.7 Configuration elements */ |
857 /********************************/ |
895 /********************************/ |
858 void *narrow_candidate_datatypes_c::visit(configuration_declaration_c *symbol) { |
896 void *narrow_candidate_datatypes_c::visit(configuration_declaration_c *symbol) { |
859 // TODO !!! |
897 if (debug) printf("Narrowing candidate data types list in configuration %s\n", ((token_c *)(symbol->configuration_name))->value); |
860 /* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */ |
898 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
861 return NULL; |
899 symbol->global_var_declarations->accept(*this); |
862 } |
900 symbol->resource_declarations ->accept(*this); // points to a single_resource_declaration_c or a resource_declaration_list_c |
|
901 // symbol->access_declarations ->accept(*this); // TODO |
|
902 // symbol->instance_specific_initializations->accept(*this); // TODO |
|
903 delete search_varfb_instance_type; |
|
904 search_varfb_instance_type = NULL; |
|
905 return NULL; |
|
906 } |
|
907 |
|
908 |
|
909 void *narrow_candidate_datatypes_c::visit(resource_declaration_c *symbol) { |
|
910 if (debug) printf("Narrowing candidate data types list in resource %s\n", ((token_c *)(symbol->resource_name))->value); |
|
911 search_varfb_instance_type_c *prev_search_varfb_instance_type = search_varfb_instance_type; |
|
912 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
913 symbol->global_var_declarations->accept(*this); |
|
914 symbol->resource_declaration ->accept(*this); // points to a single_resource_declaration_c! |
|
915 delete search_varfb_instance_type; |
|
916 search_varfb_instance_type = prev_search_varfb_instance_type; |
|
917 return NULL; |
|
918 } |
|
919 |
|
920 |
|
921 void *narrow_candidate_datatypes_c::visit(single_resource_declaration_c *symbol) { |
|
922 // symbol->task_configuration_list ->accept(*this); // TODO |
|
923 // symbol->program_configuration_list ->accept(*this); // TODO |
|
924 return NULL; |
|
925 } |
|
926 |
863 |
927 |
864 |
928 |
865 /****************************************/ |
929 /****************************************/ |
866 /* B.2 - Language IL (Instruction List) */ |
930 /* B.2 - Language IL (Instruction List) */ |
867 /****************************************/ |
931 /****************************************/ |