stage3/narrow_candidate_datatypes.cc
changeset 1041 56ebe2a31b5b
parent 1040 e8563dcaefca
child 1047 34b733cb6641
equal deleted inserted replaced
1040:e8563dcaefca 1041:56ebe2a31b5b
   607 /* helper symbol for enumerated_specification->enumerated_spec_init */
   607 /* helper symbol for enumerated_specification->enumerated_spec_init */
   608 /* enumerated_value_list ',' enumerated_value */
   608 /* enumerated_value_list ',' enumerated_value */
   609 // SYM_LIST(enumerated_value_list_c)
   609 // SYM_LIST(enumerated_value_list_c)
   610 void *narrow_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) {
   610 void *narrow_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) {
   611 //if (NULL == symbol->datatype) ERROR;  // Comented out-> Reserve this check for the print_datatypes_error_c ???  
   611 //if (NULL == symbol->datatype) ERROR;  // Comented out-> Reserve this check for the print_datatypes_error_c ???  
   612   for(int i = 0; i < symbol->n; i++) set_datatype(symbol->datatype, symbol->elements[i]);
   612   for(int i = 0; i < symbol->n; i++) set_datatype(symbol->datatype, symbol->get_element(i));
   613 //for(int i = 0; i < symbol->n; i++) if (NULL == symbol->elements[i]->datatype) ERROR; // Comented out-> Reserve this check for the print_datatypes_error_c ???  
   613 //for(int i = 0; i < symbol->n; i++) if (NULL == symbol->get_element(i)->datatype) ERROR; // Comented out-> Reserve this check for the print_datatypes_error_c ???  
   614   return NULL;  
   614   return NULL;  
   615 }
   615 }
   616 
   616 
   617 
   617 
   618 /* enumerated_type_name '#' identifier */
   618 /* enumerated_type_name '#' identifier */
   680 		 * candidate_datatype whether it is feasible, as they may all be feasible but not for the same ...
   680 		 * candidate_datatype whether it is feasible, as they may all be feasible but not for the same ...
   681 		 */
   681 		 */
   682 		// assume symbol->datatype is a FB type
   682 		// assume symbol->datatype is a FB type
   683 		search_varfb_instance_type_c search_varfb_instance_type(symbol->datatype);
   683 		search_varfb_instance_type_c search_varfb_instance_type(symbol->datatype);
   684 		for (int k = 0; k < symbol->n; k++) {
   684 		for (int k = 0; k < symbol->n; k++) {
   685 			structure_element_initialization_c *struct_elem = (structure_element_initialization_c *)symbol->elements[k];
   685 			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);
   686 			symbol_c *type = search_varfb_instance_type.get_basetype_decl(struct_elem->structure_element_name);
   687 			set_datatype(type, struct_elem);
   687 			set_datatype(type, struct_elem);
   688 			struct_elem->accept(*this);
   688 			struct_elem->accept(*this);
   689 			if (struct_elem->datatype == NULL) ERROR; // should never occur. Already checked in fill_candidate_datatypes_c
   689 			if (struct_elem->datatype == NULL) ERROR; // should never occur. Already checked in fill_candidate_datatypes_c
   690 		}
   690 		}
   770 
   770 
   771 /* subscript_list ',' subscript */
   771 /* subscript_list ',' subscript */
   772 // SYM_LIST(subscript_list_c)
   772 // SYM_LIST(subscript_list_c)
   773 void *narrow_candidate_datatypes_c::visit(subscript_list_c *symbol) {
   773 void *narrow_candidate_datatypes_c::visit(subscript_list_c *symbol) {
   774 	for (int i = 0; i < symbol->n; i++) {
   774 	for (int i = 0; i < symbol->n; i++) {
   775 		for (unsigned int k = 0; k < symbol->elements[i]->candidate_datatypes.size(); k++) {
   775 		for (unsigned int k = 0; k < symbol->get_element(i)->candidate_datatypes.size(); k++) {
   776 			if (get_datatype_info_c::is_ANY_INT(symbol->elements[i]->candidate_datatypes[k]))
   776 			if (get_datatype_info_c::is_ANY_INT(symbol->get_element(i)->candidate_datatypes[k]))
   777 				symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[k];
   777 				symbol->get_element(i)->datatype = symbol->get_element(i)->candidate_datatypes[k];
   778 		}
   778 		}
   779 		symbol->elements[i]->accept(*this);
   779 		symbol->get_element(i)->accept(*this);
   780 	}
   780 	}
   781 	return NULL;  
   781 	return NULL;  
   782 }
   782 }
   783 
   783 
   784 
   784 
   844 
   844 
   845 
   845 
   846 void *narrow_candidate_datatypes_c::visit(var1_list_c *symbol) {
   846 void *narrow_candidate_datatypes_c::visit(var1_list_c *symbol) {
   847 #if 0   /* We don't really need to set the datatype of each variable. We just check the declaration itself! */
   847 #if 0   /* We don't really need to set the datatype of each variable. We just check the declaration itself! */
   848   for(int i = 0; i < symbol->n; i++) {
   848   for(int i = 0; i < symbol->n; i++) {
   849     if (symbol->elements[i]->candidate_datatypes.size() == 1)
   849     if (symbol->get_element(i)->candidate_datatypes.size() == 1)
   850       symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[0];
   850       symbol->get_element(i)->datatype = symbol->get_element(i)->candidate_datatypes[0];
   851   }
   851   }
   852 #endif
   852 #endif
   853   return NULL;
   853   return NULL;
   854 }  
   854 }  
   855 
   855 
  1024 	 * in, so it will be able to produce tha correct datatypes for the IL instruction referenced
  1024 	 * in, so it will be able to produce tha correct datatypes for the IL instruction referenced
  1025 	 * by the label, as in the 2nd pass we already know the datatypes of the JMP instruction!
  1025 	 * by the label, as in the 2nd pass we already know the datatypes of the JMP instruction!
  1026 	 */
  1026 	 */
  1027 	for(int j = 0; j < 2; j++) {
  1027 	for(int j = 0; j < 2; j++) {
  1028 		for(int i = symbol->n-1; i >= 0; i--) {
  1028 		for(int i = symbol->n-1; i >= 0; i--) {
  1029 			symbol->elements[i]->accept(*this);
  1029 			symbol->get_element(i)->accept(*this);
  1030 		}
  1030 		}
  1031 	}
  1031 	}
  1032 	return NULL;
  1032 	return NULL;
  1033 }
  1033 }
  1034 
  1034 
  1139    * 'LD <il_operand>' IL instruction.
  1139    * 'LD <il_operand>' IL instruction.
  1140    * Just to be consistent, we will copy the datatype info back into the il_operand, even though this should not be necessary!
  1140    * Just to be consistent, we will copy the datatype info back into the il_operand, even though this should not be necessary!
  1141    */
  1141    */
  1142   if ((NULL != symbol->il_operand) && ((NULL == symbol->simple_instr_list) || (0 == ((list_c *)symbol->simple_instr_list)->n))) ERROR; // stage2 is not behaving as we expect it to!
  1142   if ((NULL != symbol->il_operand) && ((NULL == symbol->simple_instr_list) || (0 == ((list_c *)symbol->simple_instr_list)->n))) ERROR; // stage2 is not behaving as we expect it to!
  1143   if  (NULL != symbol->il_operand)
  1143   if  (NULL != symbol->il_operand)
  1144     symbol->il_operand->datatype = ((list_c *)symbol->simple_instr_list)->elements[0]->datatype;
  1144     symbol->il_operand->datatype = ((list_c *)symbol->simple_instr_list)->get_element(0)->datatype;
  1145   
  1145   
  1146   return NULL;
  1146   return NULL;
  1147 }
  1147 }
  1148 
  1148 
  1149 
  1149 
  1211 
  1211 
  1212 /* | simple_instr_list il_simple_instruction */
  1212 /* | simple_instr_list il_simple_instruction */
  1213 /* This object is referenced by il_expression_c objects */
  1213 /* This object is referenced by il_expression_c objects */
  1214 void *narrow_candidate_datatypes_c::visit(simple_instr_list_c *symbol) {
  1214 void *narrow_candidate_datatypes_c::visit(simple_instr_list_c *symbol) {
  1215 	if (symbol->n > 0)
  1215 	if (symbol->n > 0)
  1216 		symbol->elements[symbol->n - 1]->datatype = symbol->datatype;
  1216 		symbol->get_element(symbol->n - 1)->datatype = symbol->datatype;
  1217 
  1217 
  1218 	for(int i = symbol->n-1; i >= 0; i--) {
  1218 	for(int i = symbol->n-1; i >= 0; i--) {
  1219 		symbol->elements[i]->accept(*this);
  1219 		symbol->get_element(i)->accept(*this);
  1220 	}
  1220 	}
  1221 	return NULL;
  1221 	return NULL;
  1222 }
  1222 }
  1223 
  1223 
  1224 
  1224 
  1746 
  1746 
  1747 /* helper symbol for case_statement */
  1747 /* helper symbol for case_statement */
  1748 // SYM_LIST(case_element_list_c)
  1748 // SYM_LIST(case_element_list_c)
  1749 void *narrow_candidate_datatypes_c::visit(case_element_list_c *symbol) {
  1749 void *narrow_candidate_datatypes_c::visit(case_element_list_c *symbol) {
  1750 	for (int i = 0; i < symbol->n; i++) {
  1750 	for (int i = 0; i < symbol->n; i++) {
  1751 		symbol->elements[i]->datatype = symbol->datatype;
  1751 		symbol->get_element(i)->datatype = symbol->datatype;
  1752 		symbol->elements[i]->accept(*this);
  1752 		symbol->get_element(i)->accept(*this);
  1753 	}
  1753 	}
  1754 	return NULL;
  1754 	return NULL;
  1755 }
  1755 }
  1756 
  1756 
  1757 /*  case_list ':' statement_list */
  1757 /*  case_list ':' statement_list */
  1764 }
  1764 }
  1765 
  1765 
  1766 // SYM_LIST(case_list_c)
  1766 // SYM_LIST(case_list_c)
  1767 void *narrow_candidate_datatypes_c::visit(case_list_c *symbol) {
  1767 void *narrow_candidate_datatypes_c::visit(case_list_c *symbol) {
  1768 	for (int i = 0; i < symbol->n; i++) {
  1768 	for (int i = 0; i < symbol->n; i++) {
  1769 		for (unsigned int k = 0; k < symbol->elements[i]->candidate_datatypes.size(); k++) {
  1769 		for (unsigned int k = 0; k < symbol->get_element(i)->candidate_datatypes.size(); k++) {
  1770 			if (get_datatype_info_c::is_type_equal(symbol->datatype, symbol->elements[i]->candidate_datatypes[k]))
  1770 			if (get_datatype_info_c::is_type_equal(symbol->datatype, symbol->get_element(i)->candidate_datatypes[k]))
  1771 				symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[k];
  1771 				symbol->get_element(i)->datatype = symbol->get_element(i)->candidate_datatypes[k];
  1772 		}
  1772 		}
  1773 		/* NOTE: this may be an integer, a subrange_c, or a enumerated value! */
  1773 		/* NOTE: this may be an integer, a subrange_c, or a enumerated value! */
  1774 		symbol->elements[i]->accept(*this);
  1774 		symbol->get_element(i)->accept(*this);
  1775 	}
  1775 	}
  1776 	return NULL;
  1776 	return NULL;
  1777 }
  1777 }
  1778 
  1778 
  1779 
  1779