stage3/fill_candidate_datatypes.cc
changeset 717 44f74fad2cc0
parent 716 eb9aad0c3627
child 718 a9f8cc778444
equal deleted inserted replaced
716:eb9aad0c3627 717:44f74fad2cc0
   184 
   184 
   185 fill_candidate_datatypes_c::fill_candidate_datatypes_c(symbol_c *ignore) {
   185 fill_candidate_datatypes_c::fill_candidate_datatypes_c(symbol_c *ignore) {
   186 	il_operand = NULL;
   186 	il_operand = NULL;
   187 	prev_il_instruction = NULL;
   187 	prev_il_instruction = NULL;
   188 	search_varfb_instance_type = NULL;
   188 	search_varfb_instance_type = NULL;
       
   189 	current_enumerated_spec_type = NULL;
   189 }
   190 }
   190 
   191 
   191 fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) {
   192 fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) {
   192 }
   193 }
   193 
   194 
   697 /* B 1.3 - Data types */
   698 /* B 1.3 - Data types */
   698 /**********************/
   699 /**********************/
   699 /********************************/
   700 /********************************/
   700 /* B 1.3.3 - Derived data types */
   701 /* B 1.3.3 - Derived data types */
   701 /********************************/
   702 /********************************/
       
   703 /*  TYPE type_declaration_list END_TYPE */
       
   704 // SYM_REF1(data_type_declaration_c, type_declaration_list)
       
   705 /* NOTE: Not required. already handled by iterator_visitor_c base class */
       
   706 
       
   707 /* helper symbol for data_type_declaration */
       
   708 // SYM_LIST(type_declaration_list_c)
       
   709 /* NOTE: Not required. already handled by iterator_visitor_c base class */
       
   710 
       
   711 /*  simple_type_name ':' simple_spec_init */
       
   712 // SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init)
       
   713 /* NOTE: Not required. already handled by iterator_visitor_c base class */
   702 
   714 
   703 /* simple_specification ASSIGN constant */
   715 /* simple_specification ASSIGN constant */
   704 // SYM_REF2(simple_spec_init_c, simple_specification, constant)
   716 // SYM_REF2(simple_spec_init_c, simple_specification, constant)
   705 void *fill_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {
   717 void *fill_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {
   706 	if (NULL != symbol->constant) symbol->constant->accept(*this);
   718 	if (NULL != symbol->constant) symbol->constant->accept(*this);
   713 	 */
   725 	 */
   714 	// if (NULL != symbol->constant) intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->constant /*with*/);
   726 	// if (NULL != symbol->constant) intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->constant /*with*/);
   715 	return NULL;
   727 	return NULL;
   716 }
   728 }
   717 
   729 
       
   730 
       
   731 /*  subrange_type_name ':' subrange_spec_init */
       
   732 // SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init)
       
   733 
       
   734 /* subrange_specification ASSIGN signed_integer */
       
   735 // SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer)
       
   736 
       
   737 /*  integer_type_name '(' subrange')' */
       
   738 // SYM_REF2(subrange_specification_c, integer_type_name, subrange)
       
   739 
   718 /*  signed_integer DOTDOT signed_integer */
   740 /*  signed_integer DOTDOT signed_integer */
   719 // SYM_REF2(subrange_c, lower_limit, upper_limit)
   741 /* dimension will be filled in during stage 3 (array_range_check_c) with the number of elements in this subrange */
       
   742 // SYM_REF2(subrange_c, lower_limit, upper_limit, unsigned long long int dimension;)
   720 void *fill_candidate_datatypes_c::visit(subrange_c *symbol) {
   743 void *fill_candidate_datatypes_c::visit(subrange_c *symbol) {
   721 	symbol->lower_limit->accept(*this);
   744 	symbol->lower_limit->accept(*this);
   722 	symbol->upper_limit->accept(*this);
   745 	symbol->upper_limit->accept(*this);
   723 	
   746 	
   724 	for (unsigned int u = 0; u < symbol->upper_limit->candidate_datatypes.size(); u++) {
   747 	for (unsigned int u = 0; u < symbol->upper_limit->candidate_datatypes.size(); u++) {
   728 		}
   751 		}
   729 	}
   752 	}
   730 	return NULL;
   753 	return NULL;
   731 }
   754 }
   732 
   755 
   733 /*  TYPE type_declaration_list END_TYPE */
   756 
   734 // SYM_REF1(data_type_declaration_c, type_declaration_list)
   757 /*  enumerated_type_name ':' enumerated_spec_init */
       
   758 // SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init)
   735 /* NOTE: Not required. already handled by iterator_visitor_c base class */
   759 /* NOTE: Not required. already handled by iterator_visitor_c base class */
   736 /*
   760 
   737 void *fill_candidate_datatypes_c::visit(data_type_declaration_c *symbol) {
   761 
   738 	symbol->type_declaration_list->accept(*this);
   762 /* enumerated_specification ASSIGN enumerated_value */
   739 	return NULL;
   763 // SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value)
   740 }
   764 void *fill_candidate_datatypes_c::visit(enumerated_spec_init_c *symbol) {
   741 */
   765   current_enumerated_spec_type = symbol;
   742 
   766   symbol->enumerated_specification->accept(*this); /* calls enumerated_value_list_c (or identifier_c, which we ignore!) visit method */
       
   767   current_enumerated_spec_type = NULL;  
       
   768   if (NULL != symbol->enumerated_value) symbol->enumerated_value->accept(*this);
       
   769   return NULL;
       
   770 }
       
   771 
       
   772 /* helper symbol for enumerated_specification->enumerated_spec_init */
       
   773 /* enumerated_value_list ',' enumerated_value */
       
   774 // SYM_LIST(enumerated_value_list_c)
       
   775 void *fill_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) {
       
   776   if (NULL == current_enumerated_spec_type) ERROR;
       
   777   
       
   778   /* Actually, all this passing of symbol_c * through the  current_enumerated_spec_type is actually useless, as the base type
       
   779    * is actually this enumerated_value_list_c symbol!!! However, it is safer to do it this way, as we can then later change 
       
   780    * search_base_type_c without having to change this fill_candidate_datatypes_c class too!!
       
   781    */
       
   782   current_enumerated_spec_type = base_type(current_enumerated_spec_type);
       
   783   if (NULL == current_enumerated_spec_type) ERROR;
       
   784   
       
   785   /* We already know the datatype of the enumerated_value(s) in the list, so we set them directly instead of recursively calling the enumerated_value_c visit method! */
       
   786   for(int i = 0; i < symbol->n; i++) {
       
   787     add_datatype_to_candidate_list(symbol->elements[i], current_enumerated_spec_type);
       
   788     symbol->elements[i]->datatype = current_enumerated_spec_type; // To be consistent, this should really be done in the narrow_candidate_datatypes_c !!
       
   789   }
       
   790   return NULL;  
       
   791 }
       
   792 
       
   793 
       
   794 /* enumerated_type_name '#' identifier */
       
   795 // SYM_REF2(enumerated_value_c, type, value)
       
   796 /* WARNING: The enumerated_value_c is used when delcaring an enumerated datatype
       
   797  *          (e.g.   TYPE enumT: (xxx1, xxx2); END_TYPE ---> xxx1 and xxx2 will be enumerated_value_c)
       
   798  *          as well as in the source code of POU bodies
       
   799  *          (e.g.    enumVar := xxx1    ---> xxx1 will be enumerated_value_c)
       
   800  *
       
   801  *          The following method will only be used to visit enumerated_value_c that show up inside the 
       
   802  *          source code of POU bodies (or the initial values of an enumerated type). When used inside an 
       
   803  *          enumerated type declaration to list the possible enum values (whether inside
       
   804  *          a TYPE ... END_TYPE, or inside a VAR .. END_VAR), the visitor method for enumerated_value_list_c
       
   805  *          will NOT recursively call the following enumerated_value_c visitor method!
       
   806  */
   743 void *fill_candidate_datatypes_c::visit(enumerated_value_c *symbol) {
   807 void *fill_candidate_datatypes_c::visit(enumerated_value_c *symbol) {
   744 	symbol_c *global_enumerated_type;
   808 	symbol_c *global_enumerated_type;
   745 	symbol_c *local_enumerated_type;
   809 	symbol_c *local_enumerated_type;
   746 	symbol_c *enumerated_type;
   810 	symbol_c *enumerated_type;
   747 
   811 
   767 		add_datatype_to_candidate_list(symbol, enumerated_type);
   831 		add_datatype_to_candidate_list(symbol, enumerated_type);
   768 
   832 
   769 	if (debug) std::cout << "ENUMERATE [" << symbol->candidate_datatypes.size() << "]\n";
   833 	if (debug) std::cout << "ENUMERATE [" << symbol->candidate_datatypes.size() << "]\n";
   770 	return NULL;
   834 	return NULL;
   771 }
   835 }
       
   836 
       
   837 
       
   838 /*  identifier ':' array_spec_init */
       
   839 // SYM_REF2(array_type_declaration_c, identifier, array_spec_init)
       
   840 
       
   841 /* array_specification [ASSIGN array_initialization} */
       
   842 /* array_initialization may be NULL ! */
       
   843 // SYM_REF2(array_spec_init_c, array_specification, array_initialization)
       
   844 
       
   845 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
       
   846 // SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name)
       
   847 
       
   848 /* helper symbol for array_specification */
       
   849 /* array_subrange_list ',' subrange */
       
   850 // SYM_LIST(array_subrange_list_c)
       
   851 
       
   852 /* array_initialization:  '[' array_initial_elements_list ']' */
       
   853 /* helper symbol for array_initialization */
       
   854 /* array_initial_elements_list ',' array_initial_elements */
       
   855 // SYM_LIST(array_initial_elements_list_c)
       
   856 
       
   857 /* integer '(' [array_initial_element] ')' */
       
   858 /* array_initial_element may be NULL ! */
       
   859 // SYM_REF2(array_initial_elements_c, integer, array_initial_element)
       
   860 
       
   861 /*  structure_type_name ':' structure_specification */
       
   862 // SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification)
       
   863 
       
   864 /* structure_type_name ASSIGN structure_initialization */
       
   865 /* structure_initialization may be NULL ! */
       
   866 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
       
   867 
       
   868 /* helper symbol for structure_declaration */
       
   869 /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
       
   870 /* structure_element_declaration_list structure_element_declaration ';' */
       
   871 // SYM_LIST(structure_element_declaration_list_c)
       
   872 
       
   873 /*  structure_element_name ':' *_spec_init */
       
   874 // SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init)
       
   875 
       
   876 /* helper symbol for structure_initialization */
       
   877 /* structure_initialization: '(' structure_element_initialization_list ')' */
       
   878 /* structure_element_initialization_list ',' structure_element_initialization */
       
   879 // SYM_LIST(structure_element_initialization_list_c)
       
   880 
       
   881 /*  structure_element_name ASSIGN value */
       
   882 // SYM_REF2(structure_element_initialization_c, structure_element_name, value)
       
   883 
       
   884 /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
       
   885 // SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) 
       
   886 
       
   887 
   772 
   888 
   773 
   889 
   774 /*********************/
   890 /*********************/
   775 /* B 1.4 - Variables */
   891 /* B 1.4 - Variables */
   776 /*********************/
   892 /*********************/