474 |
474 |
475 |
475 |
476 /* enumerated_type_name ':' enumerated_spec_init */ |
476 /* enumerated_type_name ':' enumerated_spec_init */ |
477 // SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init) |
477 // SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init) |
478 void *narrow_candidate_datatypes_c::visit(enumerated_type_declaration_c *symbol) { |
478 void *narrow_candidate_datatypes_c::visit(enumerated_type_declaration_c *symbol) { |
479 symbol->datatype = search_base_type_c::get_basetype_decl(symbol); |
479 if (symbol->candidate_datatypes.size() != 1) ERROR; |
480 symbol->enumerated_type_name->datatype = symbol->datatype; |
480 |
481 symbol->enumerated_spec_init->datatype = symbol->datatype; |
481 symbol->datatype = symbol->candidate_datatypes[0]; |
|
482 set_datatype(symbol->datatype, symbol->enumerated_type_name); |
|
483 set_datatype(symbol->datatype, symbol->enumerated_spec_init); |
482 |
484 |
483 symbol->enumerated_spec_init->accept(*this); |
485 symbol->enumerated_spec_init->accept(*this); |
484 return NULL; |
486 return NULL; |
485 } |
487 } |
486 |
488 |
489 // SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value) |
491 // SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value) |
490 void *narrow_candidate_datatypes_c::visit(enumerated_spec_init_c *symbol) { |
492 void *narrow_candidate_datatypes_c::visit(enumerated_spec_init_c *symbol) { |
491 /* If we are handling an anonymous datatype (i.e. a datatype implicitly declared inside a VAR ... END_VAR declaration) |
493 /* If we are handling an anonymous datatype (i.e. a datatype implicitly declared inside a VAR ... END_VAR declaration) |
492 * then the symbol->datatype has not yet been set by the previous visit(enumerated_spec_init_c) method! |
494 * then the symbol->datatype has not yet been set by the previous visit(enumerated_spec_init_c) method! |
493 */ |
495 */ |
494 if (NULL == symbol->datatype) |
496 if (NULL == symbol->datatype) { |
495 symbol->datatype = search_base_type_c::get_basetype_decl(symbol); |
497 if (symbol->candidate_datatypes.size() != 1) ERROR; |
496 symbol->enumerated_specification->datatype = symbol->datatype; |
498 symbol->datatype = symbol->candidate_datatypes[0]; |
|
499 } |
|
500 set_datatype(symbol->datatype, symbol->enumerated_specification); |
497 if (NULL != symbol->enumerated_value) |
501 if (NULL != symbol->enumerated_value) |
498 /* the enumerated_value_c object to which this list points to has both the datatype and the candidate_datatype_list filled in, so we |
|
499 * call set_datatype() instead of setting the datatype directly! |
|
500 * If the desired datatype does not match the datatypes in the candidate list, then the source code has a bug that will be caught by |
|
501 * print_datatypes_error_c |
|
502 */ |
|
503 set_datatype(symbol->datatype, symbol->enumerated_value); |
502 set_datatype(symbol->datatype, symbol->enumerated_value); |
504 |
503 |
505 symbol->enumerated_specification->accept(*this); /* calls enumerated_value_list_c (or identifier_c, which we ignore!) visit method */ |
504 symbol->enumerated_specification->accept(*this); /* calls enumerated_value_list_c (or identifier_c, which we ignore!) visit method */ |
506 return NULL; |
505 return NULL; |
507 } |
506 } |