956 // use top->down algorithm!! |
956 // use top->down algorithm!! |
957 type_spec->candidate_datatypes = symbol->candidate_datatypes; |
957 type_spec->candidate_datatypes = symbol->candidate_datatypes; |
958 type_spec->accept(*this); |
958 type_spec->accept(*this); |
959 |
959 |
960 // use bottom->up algorithm!! |
960 // use bottom->up algorithm!! |
961 if (NULL != init_value) init_value->accept(*this); |
961 /* NOTE: In special cases we will run a modified bottom->up algorithm, i.e. with a top->down indication of |
|
962 * tentative candidate_datatypes... |
|
963 * (e.g. structure_element_initialization_list_c). The tentative candidate_datatypes (a list of |
|
964 * candidate_datatypes to consider while running the bottom->up algorithm) will actually be the |
|
965 * datatypes in symbol->parent->candidate_datatpes |
|
966 * This implies that we can only run this bottom->up algorithm on the initial values _after_ |
|
967 * having set the symbol->candidate_datatpes of the type specification (i.e. the symbol parameter) |
|
968 */ |
|
969 if (NULL != init_value) init_value->accept(*this); |
962 /* NOTE: Even if the constant and the type are of incompatible data types, we let the |
970 /* NOTE: Even if the constant and the type are of incompatible data types, we let the |
963 * ***_spec_init_c object inherit the data type of the type declaration (simple_specification) |
971 * ***_spec_init_c object inherit the data type of the type declaration (simple_specification) |
964 * This will let us produce more informative error messages when checking data type compatibility |
972 * This will let us produce more informative error messages when checking data type compatibility |
965 * with located variables (AT %QW3.4 : WORD). |
973 * with located variables (AT %QW3.4 : WORD). |
966 */ |
974 */ |
1161 |
1169 |
1162 /* helper symbol for structure_initialization */ |
1170 /* helper symbol for structure_initialization */ |
1163 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
1171 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
1164 /* structure_element_initialization_list ',' structure_element_initialization */ |
1172 /* structure_element_initialization_list ',' structure_element_initialization */ |
1165 // SYM_LIST(structure_element_initialization_list_c) |
1173 // SYM_LIST(structure_element_initialization_list_c) |
|
1174 void *fill_candidate_datatypes_c::visit(structure_element_initialization_list_c *symbol) { |
|
1175 // use bottom->up algorithm -> first let all elements determine their candidate_datatypes |
|
1176 iterator_visitor_c::visit(symbol); // call visit(structure_element_initialization_c *) on all elements |
|
1177 |
|
1178 for (unsigned int i = 0; i < symbol->parent->candidate_datatypes.size(); i++) { // size() should always be 1 here -> a single structure or FB type! |
|
1179 // assume symbol->parent is a FB type |
|
1180 search_varfb_instance_type_c search_varfb_instance_type(symbol->parent->candidate_datatypes[i]); |
|
1181 // flag indicating all struct_elem->structure_element_name are structure elements found in the symbol->parent->candidate_datatypes[i] datatype |
|
1182 int flag_all_elem_ok = 1; // assume all found |
|
1183 for (int k = 0; k < symbol->n; k++) { |
|
1184 // assume symbol->parent->candidate_datatypes[i] is a FB type... |
|
1185 structure_element_initialization_c *struct_elem = (structure_element_initialization_c *)symbol->elements[k]; |
|
1186 symbol_c *type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name); |
|
1187 if (!get_datatype_info_c::is_type_valid(type)) { |
|
1188 // either get_datatype_info_c::is_type_valid(type) is not a FB type, or the element is not declared in that FB |
|
1189 // Lets try a struct type!! |
|
1190 // TODO... |
|
1191 } |
|
1192 if (!get_datatype_info_c::is_ANY_ELEMENTARY(type) && get_datatype_info_c::is_type_valid(type)) { |
|
1193 add_datatype_to_candidate_list(struct_elem, type); // for non-elementary datatypes, we must use a top->down algorithm!! |
|
1194 struct_elem->accept(*this); |
|
1195 } |
|
1196 if (search_in_candidate_datatype_list(type, struct_elem->candidate_datatypes) < 0) { |
|
1197 flag_all_elem_ok = 0; // the necessary datatype for structure init element is not a candidate_datatype of that element |
|
1198 } |
|
1199 } |
|
1200 if (flag_all_elem_ok) { |
|
1201 add_datatype_to_candidate_list(symbol, symbol->parent->candidate_datatypes[i]); |
|
1202 fprintf(stderr, "ADDED DATAYPE type--->\n"); |
|
1203 debug_c::print(symbol); |
|
1204 } |
|
1205 } |
|
1206 return NULL; |
|
1207 } |
|
1208 |
1166 |
1209 |
1167 /* structure_element_name ASSIGN value */ |
1210 /* structure_element_name ASSIGN value */ |
1168 // SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
1211 // SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
|
1212 void *fill_candidate_datatypes_c::visit(structure_element_initialization_c *symbol) { |
|
1213 symbol->value->accept(*this); |
|
1214 symbol->candidate_datatypes = symbol->value->candidate_datatypes; |
|
1215 // Note that candidate_datatypes of symbol->structure_element_name are left empty! |
|
1216 return NULL; |
|
1217 } |
|
1218 |
1169 |
1219 |
1170 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
1220 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
1171 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) |
1221 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) |
1172 |
1222 |
1173 |
1223 |