stage3/narrow_candidate_datatypes.cc
changeset 726 9b61eb4f00dc
parent 718 a9f8cc778444
child 728 3700fd83e5de
equal deleted inserted replaced
725:bfbe4aca6b77 726:9b61eb4f00dc
   412 	/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used in the code. */
   412 	/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used in the code. */
   413 	if (symbol == NULL) return NULL;
   413 	if (symbol == NULL) return NULL;
   414 	return search_base_type_c::get_basetype_decl(symbol);
   414 	return search_base_type_c::get_basetype_decl(symbol);
   415 }
   415 }
   416 
   416 
   417 /*********************/
   417 
   418 /* B 1.2 - Constants */
   418 
   419 /*********************/
       
   420 
   419 
   421 /**********************/
   420 /**********************/
   422 /* B 1.3 - Data types */
   421 /* B 1.3 - Data types */
   423 /**********************/
   422 /**********************/
   424 /********************************/
   423 /********************************/
   425 /* B 1.3.3 - Derived data types */
   424 /* B 1.3.3 - Derived data types */
   426 /********************************/
   425 /********************************/
       
   426 /*  TYPE type_declaration_list END_TYPE */
       
   427 // SYM_REF1(data_type_declaration_c, type_declaration_list)
       
   428 /* NOTE: Not required. already handled by iterator_visitor_c base class */
       
   429 
       
   430 /* helper symbol for data_type_declaration */
       
   431 // SYM_LIST(type_declaration_list_c)
       
   432 /* NOTE: Not required. already handled by iterator_visitor_c base class */
       
   433 
       
   434 /*  simple_type_name ':' simple_spec_init */
       
   435 // SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init)
       
   436 /* NOTE: Not required. already handled by iterator_visitor_c base class */
       
   437 
   427 /* simple_specification ASSIGN constant */
   438 /* simple_specification ASSIGN constant */
   428 // SYM_REF2(simple_spec_init_c, simple_specification, constant)
   439 // SYM_REF2(simple_spec_init_c, simple_specification, constant)
   429 void *narrow_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {
   440 void *narrow_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {
   430 	if (symbol->candidate_datatypes.size() == 1)
   441 	if (symbol->candidate_datatypes.size() == 1)
   431 	  symbol->datatype = symbol->candidate_datatypes[0];
   442 	  symbol->datatype = symbol->candidate_datatypes[0];
   439 	}
   450 	}
   440 	return NULL;
   451 	return NULL;
   441 }
   452 }
   442 
   453 
   443 
   454 
       
   455 /*  subrange_type_name ':' subrange_spec_init */
       
   456 // SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init)
       
   457 
       
   458 /* subrange_specification ASSIGN signed_integer */
       
   459 // SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer)
       
   460 
       
   461 /*  integer_type_name '(' subrange')' */
       
   462 // SYM_REF2(subrange_specification_c, integer_type_name, subrange)
   444 
   463 
   445 /*  signed_integer DOTDOT signed_integer */
   464 /*  signed_integer DOTDOT signed_integer */
   446 // SYM_REF2(subrange_c, lower_limit, upper_limit)
   465 /* dimension will be filled in during stage 3 (array_range_check_c) with the number of elements in this subrange */
       
   466 // SYM_REF2(subrange_c, lower_limit, upper_limit, unsigned long long int dimension;)
   447 void *narrow_candidate_datatypes_c::visit(subrange_c *symbol) {
   467 void *narrow_candidate_datatypes_c::visit(subrange_c *symbol) {
   448 	symbol->lower_limit->datatype = symbol->datatype;
   468 	symbol->lower_limit->datatype = symbol->datatype;
   449 	symbol->lower_limit->accept(*this);
   469 	symbol->lower_limit->accept(*this);
   450 	symbol->upper_limit->datatype = symbol->datatype;
   470 	symbol->upper_limit->datatype = symbol->datatype;
   451 	symbol->upper_limit->accept(*this);
   471 	symbol->upper_limit->accept(*this);
   452 	return NULL;
   472 	return NULL;
   453 }
   473 }
       
   474 
       
   475 
       
   476 /*  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) {
       
   479   symbol->datatype = search_base_type_c::get_basetype_decl(symbol);
       
   480   symbol->enumerated_type_name->datatype = symbol->datatype;
       
   481   symbol->enumerated_spec_init->datatype = symbol->datatype;
       
   482   
       
   483   symbol->enumerated_spec_init->accept(*this);
       
   484   return NULL;
       
   485 }
       
   486 
       
   487 
       
   488 /* enumerated_specification ASSIGN enumerated_value */
       
   489 // SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value)
       
   490 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)
       
   492    * then the symbol->datatype has not yet been set by the previous visit(enumerated_spec_init_c) method!
       
   493    */
       
   494   if (NULL == symbol->datatype)
       
   495     symbol->datatype = search_base_type_c::get_basetype_decl(symbol);
       
   496   symbol->enumerated_specification->datatype = symbol->datatype;
       
   497   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);
       
   504 
       
   505   symbol->enumerated_specification->accept(*this); /* calls enumerated_value_list_c (or identifier_c, which we ignore!) visit method */
       
   506   return NULL;
       
   507 }
       
   508 
       
   509 /* helper symbol for enumerated_specification->enumerated_spec_init */
       
   510 /* enumerated_value_list ',' enumerated_value */
       
   511 // SYM_LIST(enumerated_value_list_c)
       
   512 void *narrow_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) {
       
   513   if (NULL == symbol->datatype) ERROR;
       
   514   
       
   515   for(int i = 0; i < symbol->n; i++) {
       
   516     /* the enumerated_value_c objects to which this list points to has both the datatype and the candidate_datatype_list filled in, so we 
       
   517      * call set_datatype() instead of setting the datatype directly!
       
   518      */
       
   519     set_datatype(symbol->datatype, symbol->elements[i]);
       
   520     if (NULL == symbol->elements[i]->datatype) ERROR;
       
   521   }
       
   522   return NULL;  
       
   523 }
       
   524 
       
   525 
       
   526 /* enumerated_type_name '#' identifier */
       
   527 // SYM_REF2(enumerated_value_c, type, value)
       
   528 // void *narrow_candidate_datatypes_c::visit(enumerated_value_c *symbol) {/* do nothing! */ return NULL;}
       
   529 
       
   530 
       
   531 /*  identifier ':' array_spec_init */
       
   532 // SYM_REF2(array_type_declaration_c, identifier, array_spec_init)
       
   533 
       
   534 /* array_specification [ASSIGN array_initialization} */
       
   535 /* array_initialization may be NULL ! */
       
   536 // SYM_REF2(array_spec_init_c, array_specification, array_initialization)
       
   537 
       
   538 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
       
   539 // SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name)
       
   540 
       
   541 /* helper symbol for array_specification */
       
   542 /* array_subrange_list ',' subrange */
       
   543 // SYM_LIST(array_subrange_list_c)
       
   544 
       
   545 /* array_initialization:  '[' array_initial_elements_list ']' */
       
   546 /* helper symbol for array_initialization */
       
   547 /* array_initial_elements_list ',' array_initial_elements */
       
   548 // SYM_LIST(array_initial_elements_list_c)
       
   549 
       
   550 /* integer '(' [array_initial_element] ')' */
       
   551 /* array_initial_element may be NULL ! */
       
   552 // SYM_REF2(array_initial_elements_c, integer, array_initial_element)
       
   553 
       
   554 /*  structure_type_name ':' structure_specification */
       
   555 // SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification)
       
   556 
       
   557 /* structure_type_name ASSIGN structure_initialization */
       
   558 /* structure_initialization may be NULL ! */
       
   559 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
       
   560 
       
   561 /* helper symbol for structure_declaration */
       
   562 /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
       
   563 /* structure_element_declaration_list structure_element_declaration ';' */
       
   564 // SYM_LIST(structure_element_declaration_list_c)
       
   565 
       
   566 /*  structure_element_name ':' *_spec_init */
       
   567 // SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init)
       
   568 
       
   569 /* helper symbol for structure_initialization */
       
   570 /* structure_initialization: '(' structure_element_initialization_list ')' */
       
   571 /* structure_element_initialization_list ',' structure_element_initialization */
       
   572 // SYM_LIST(structure_element_initialization_list_c)
       
   573 
       
   574 /*  structure_element_name ASSIGN value */
       
   575 // SYM_REF2(structure_element_initialization_c, structure_element_name, value)
       
   576 
       
   577 /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
       
   578 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) 
       
   579 
       
   580 
   454 
   581 
   455 
   582 
   456 /*********************/
   583 /*********************/
   457 /* B 1.4 - Variables */
   584 /* B 1.4 - Variables */
   458 /*********************/
   585 /*********************/