671 /* helper symbol for structure_initialization */ |
671 /* helper symbol for structure_initialization */ |
672 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
672 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
673 /* structure_element_initialization_list ',' structure_element_initialization */ |
673 /* structure_element_initialization_list ',' structure_element_initialization */ |
674 // SYM_LIST(structure_element_initialization_list_c) |
674 // SYM_LIST(structure_element_initialization_list_c) |
675 void *narrow_candidate_datatypes_c::visit(structure_element_initialization_list_c *symbol) { |
675 void *narrow_candidate_datatypes_c::visit(structure_element_initialization_list_c *symbol) { |
676 if (get_datatype_info_c::is_type_valid(symbol->datatype)) { |
676 symbol_c *type = NULL; |
677 /* Note that in principle structure_element_initialization_list_c will have at most 1 candidate_datatype |
677 |
678 * (the FB or structure in the type specification). However, our algorithm is more generic and will |
678 // first try to narrow with the correct type, if valid. |
679 * assume that more than 1 candidate_datatype is possible. In this case we need to iterate and check each |
679 if (!get_datatype_info_c::is_type_valid(type)) type = symbol->datatype; |
680 * candidate_datatype whether it is feasible, as they may all be feasible but not for the same ... |
680 // to reduce number of error messages, we try to narrow with parent's spec_init->datatype |
681 */ |
681 if (!get_datatype_info_c::is_type_valid(type)) type = symbol->parent->datatype; |
682 // assume symbol->datatype is a FB type |
682 |
683 search_varfb_instance_type_c search_varfb_instance_type(symbol->datatype); |
683 if (get_datatype_info_c::is_type_valid(type)) { |
|
684 // We need to iterate and determine the required datatype of each structure element |
|
685 // assume type is a FB type |
|
686 search_varfb_instance_type_c search_varfb_instance_type(type); |
|
687 // assume type is a STRUCT type |
|
688 structure_element_declaration_list_c *struct_decl = dynamic_cast<structure_element_declaration_list_c *>(type); |
684 for (int k = 0; k < symbol->n; k++) { |
689 for (int k = 0; k < symbol->n; k++) { |
685 structure_element_initialization_c *struct_elem = (structure_element_initialization_c *)symbol->get_element(k); |
690 structure_element_initialization_c *struct_elem = (structure_element_initialization_c *)symbol->get_element(k); |
686 symbol_c *type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name); |
691 symbol_c *type = NULL; |
|
692 if (struct_decl == NULL) { |
|
693 // type is not a struct. Must be a FB. |
|
694 type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name); |
|
695 } else { |
|
696 // type is a struct. |
|
697 type = search_base_type_c::get_basetype_decl(struct_decl->find_element(struct_elem->structure_element_name)); |
|
698 } |
687 set_datatype(type, struct_elem); |
699 set_datatype(type, struct_elem); |
688 struct_elem->accept(*this); |
700 struct_elem->accept(*this); |
689 if (struct_elem->datatype == NULL) ERROR; // should never occur. Already checked in fill_candidate_datatypes_c |
701 /* We do best effort narrowing, even in the presence of errors, to reduce number of error messages |
|
702 * so the following two assertions are not always met. |
|
703 */ |
|
704 // if (!get_datatype_info_c::is_type_valid(type)) ERROR; |
|
705 // if (struct_elem->datatype == NULL) ERROR; // should never occur. Already checked in fill_candidate_datatypes_c |
690 } |
706 } |
691 } |
707 } |
692 return NULL; |
708 return NULL; |
693 } |
709 } |
694 |
710 |
695 /* structure_element_name ASSIGN value */ |
711 /* structure_element_name ASSIGN value */ |
696 // SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
712 // SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
697 void *narrow_candidate_datatypes_c::visit(structure_element_initialization_c *symbol) {set_datatype(symbol->datatype, symbol->value); return NULL;} |
713 void *narrow_candidate_datatypes_c::visit(structure_element_initialization_c *symbol) {set_datatype(symbol->datatype, symbol->value); symbol->value->accept(*this); return NULL;} |
698 |
714 |
699 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
715 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
700 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) |
716 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) |
701 |
717 |
702 |
718 |