1174 void *fill_candidate_datatypes_c::visit(structure_element_initialization_list_c *symbol) { |
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 |
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 |
1176 iterator_visitor_c::visit(symbol); // call visit(structure_element_initialization_c *) on all elements |
1177 |
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! |
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 |
1179 // assume symbol->parent->candidate_datatypes[i] is a FB type |
1180 search_varfb_instance_type_c search_varfb_instance_type(symbol->parent->candidate_datatypes[i]); |
1180 search_varfb_instance_type_c search_varfb_instance_type(symbol->parent->candidate_datatypes[i]); |
|
1181 // assume symbol->parent->candidate_datatypes[i] is a STRUCT data type |
|
1182 structure_element_declaration_list_c *struct_decl = dynamic_cast<structure_element_declaration_list_c *>(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 |
1183 // 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 |
1184 int flag_all_elem_ok = 1; // assume all found |
1183 for (int k = 0; k < symbol->n; k++) { |
1185 for (int k = 0; k < symbol->n; k++) { |
1184 // assume symbol->parent->candidate_datatypes[i] is a FB type... |
1186 structure_element_initialization_c *struct_elem = dynamic_cast<structure_element_initialization_c *>(symbol->get_element(k)); |
1185 structure_element_initialization_c *struct_elem = (structure_element_initialization_c *)symbol->get_element(k); |
1187 if (struct_elem == NULL) ERROR; |
1186 symbol_c *type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name); |
1188 |
1187 if (!get_datatype_info_c::is_type_valid(type)) { |
1189 // assume symbol->parent is a FB 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 |
1190 symbol_c *type = NULL; |
1189 // Lets try a struct type!! |
1191 if (struct_decl != NULL) { |
1190 // TODO... |
1192 // search in the struct!! |
|
1193 type = search_base_type_c::get_basetype_decl(struct_decl->find_element(struct_elem->structure_element_name)); |
|
1194 } else { |
|
1195 // parent is a FB type. Lets search there!! |
|
1196 type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name); |
1191 } |
1197 } |
1192 if (!get_datatype_info_c::is_ANY_ELEMENTARY(type) && get_datatype_info_c::is_type_valid(type)) { |
1198 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!! |
1199 // for non-elementary datatypes, we must use a top->down algorithm!! |
|
1200 add_datatype_to_candidate_list(struct_elem, type); |
1194 struct_elem->accept(*this); |
1201 struct_elem->accept(*this); |
1195 } |
1202 } |
1196 if (search_in_candidate_datatype_list(type, struct_elem->candidate_datatypes) < 0) { |
1203 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 |
1204 flag_all_elem_ok = 0; // the necessary datatype for structure init element is not a candidate_datatype of that element |
1198 } |
1205 } |