stage3/print_datatypes_error.cc
changeset 676 ca4f17211251
parent 558 9273dfc5fa7c
child 689 45c35d829db9
equal deleted inserted replaced
675:59fc28d4b06c 676:ca4f17211251
   107 static bool are_all_datatypes_of_prev_il_instructions_datatypes_equal(il_instruction_c *symbol) {
   107 static bool are_all_datatypes_of_prev_il_instructions_datatypes_equal(il_instruction_c *symbol) {
   108 	if (NULL == symbol) ERROR;
   108 	if (NULL == symbol) ERROR;
   109 	bool res;
   109 	bool res;
   110 	
   110 	
   111 	if (symbol->prev_il_instruction.size() > 0)
   111 	if (symbol->prev_il_instruction.size() > 0)
   112 		res = is_type_valid(symbol->prev_il_instruction[0]->datatype);
   112 		res = get_datatype_info_c::is_type_valid(symbol->prev_il_instruction[0]->datatype);
   113 
   113 
   114 	for (unsigned int i = 1; i < symbol->prev_il_instruction.size(); i++)
   114 	for (unsigned int i = 1; i < symbol->prev_il_instruction.size(); i++)
   115 		res &= is_type_equal(symbol->prev_il_instruction[i-1]->datatype, symbol->prev_il_instruction[i]->datatype);
   115 		res &= get_datatype_info_c::is_type_equal(symbol->prev_il_instruction[i-1]->datatype, symbol->prev_il_instruction[i]->datatype);
   116 	
   116 	
   117 	return res;
   117 	return res;
   118 }
   118 }
   119 
   119 
   120 
   120 
   248 					 * narrow algorithm. We leave this untill somebody aks for it...
   248 					 * narrow algorithm. We leave this untill somebody aks for it...
   249 					 * So, for now, we simply comment out this code.
   249 					 * So, for now, we simply comment out this code.
   250 					 */
   250 					 */
   251 					for (unsigned int p = 0; p < il_instruction_symbol->prev_il_instruction.size(); p++) {
   251 					for (unsigned int p = 0; p < il_instruction_symbol->prev_il_instruction.size(); p++) {
   252 						symbol_c *value = il_instruction_symbol->prev_il_instruction[p];  
   252 						symbol_c *value = il_instruction_symbol->prev_il_instruction[p];  
   253 						if (!is_type_valid(value->datatype)) {
   253 						if (!get_datatype_info_c::is_type_valid(value->datatype)) {
   254 							function_invocation_error = true;
   254 							function_invocation_error = true;
   255 							STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility for value passed to first parameter when invoking function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   255 							STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility for value passed to first parameter when invoking function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   256 							STAGE3_ERROR(0, value, value, "This is the IL instruction producing the incompatible data type to first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   256 							STAGE3_ERROR(0, value, value, "This is the IL instruction producing the incompatible data type to first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   257 						}
   257 						}
   258 					}
   258 					}
   259 #else
   259 #else
   260 					if (!is_type_valid(il_instruction_symbol->datatype)) {
   260 					if (!get_datatype_info_c::is_type_valid(il_instruction_symbol->datatype)) {
   261 						function_invocation_error = true;
   261 						function_invocation_error = true;
   262 						STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility between value in IL 'accumulator' and first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   262 						STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility between value in IL 'accumulator' and first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
   263 					}
   263 					}
   264 #endif
   264 #endif
   265 					if (function_invocation_error)
   265 					if (function_invocation_error)
   266 						/* when handling a IL function call, and an error is found in the first parameter, then we bug out and do not print out any more error messages. */
   266 						/* when handling a IL function call, and an error is found in the first parameter, then we bug out and do not print out any more error messages. */
   267 						return;
   267 						return;
   268 				}
   268 				}
   269 				else if (!is_type_valid(param_value->datatype)) {
   269 				else if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
   270 					function_invocation_error = true;
   270 					function_invocation_error = true;
   271 					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility for value passed in position %d when invoking %s '%s'", i, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   271 					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility for value passed in position %d when invoking %s '%s'", i, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   272 				}
   272 				}
   273 			}
   273 			}
   274 	}
   274 	}
   535 /**********************/
   535 /**********************/
   536 /********************************/
   536 /********************************/
   537 /* B 1.3.3 - Derived data types */
   537 /* B 1.3.3 - Derived data types */
   538 /********************************/
   538 /********************************/
   539 void *print_datatypes_error_c::visit(simple_spec_init_c *symbol) {
   539 void *print_datatypes_error_c::visit(simple_spec_init_c *symbol) {
   540 	if (!is_type_valid(symbol->simple_specification->datatype)) {
   540 	if (!get_datatype_info_c::is_type_valid(symbol->simple_specification->datatype)) {
   541 		STAGE3_ERROR(0, symbol->simple_specification, symbol->simple_specification, "Invalid data type.");
   541 		STAGE3_ERROR(0, symbol->simple_specification, symbol->simple_specification, "Invalid data type.");
   542 	} else if (NULL != symbol->constant) {
   542 	} else if (NULL != symbol->constant) {
   543 		if (!is_type_valid(symbol->constant->datatype))
   543 		if (!get_datatype_info_c::is_type_valid(symbol->constant->datatype))
   544 			STAGE3_ERROR(0, symbol->constant, symbol->constant, "Initial value has incompatible data type.");
   544 			STAGE3_ERROR(0, symbol->constant, symbol->constant, "Initial value has incompatible data type.");
   545 	} else if (!is_type_valid(symbol->datatype)) {
   545 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   546 		ERROR; /* If we have an error here, then we must also have an error in one of
   546 		ERROR; /* If we have an error here, then we must also have an error in one of
   547 		        * the two previous tests. If we reach this point, some strange error is ocurring!
   547 		        * the two previous tests. If we reach this point, some strange error is ocurring!
   548 			*/
   548 			*/
   549 	}
   549 	}
   550 	return NULL;
   550 	return NULL;
   575 /********************************************/
   575 /********************************************/
   576 /* B 1.4.1 - Directly Represented Variables */
   576 /* B 1.4.1 - Directly Represented Variables */
   577 /********************************************/
   577 /********************************************/
   578 void *print_datatypes_error_c::visit(direct_variable_c *symbol) {
   578 void *print_datatypes_error_c::visit(direct_variable_c *symbol) {
   579 	if (symbol->candidate_datatypes.size() == 0) ERROR;
   579 	if (symbol->candidate_datatypes.size() == 0) ERROR;
   580 	if (!is_type_valid(symbol->datatype))
   580 	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
   581 		STAGE3_ERROR(4, symbol, symbol, "Direct variable has incompatible data type with expression.");
   581 		STAGE3_ERROR(4, symbol, symbol, "Direct variable has incompatible data type with expression.");
   582 	return NULL;
   582 	return NULL;
   583 }
   583 }
   584 
   584 
   585 /*************************************/
   585 /*************************************/
   646 // SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init)
   646 // SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init)
   647 void *print_datatypes_error_c::visit(located_var_decl_c *symbol) {
   647 void *print_datatypes_error_c::visit(located_var_decl_c *symbol) {
   648   symbol->located_var_spec_init->accept(*this);
   648   symbol->located_var_spec_init->accept(*this);
   649   /* It does not make sense to call symbol->location->accept(*this). The check is done right here if the following if() */
   649   /* It does not make sense to call symbol->location->accept(*this). The check is done right here if the following if() */
   650   // symbol->location->accept(*this); 
   650   // symbol->location->accept(*this); 
   651   if ((is_type_valid(symbol->located_var_spec_init->datatype)) && (!is_type_valid(symbol->location->datatype)))
   651   if ((get_datatype_info_c::is_type_valid(symbol->located_var_spec_init->datatype)) && (!get_datatype_info_c::is_type_valid(symbol->location->datatype)))
   652     STAGE3_ERROR(0, symbol, symbol, "Bit size of data type is incompatible with bit size of location.");
   652     STAGE3_ERROR(0, symbol, symbol, "Bit size of data type is incompatible with bit size of location.");
   653   return NULL;
   653   return NULL;
   654 }  
   654 }  
   655 
   655 
   656 
   656 
  1262 	return NULL;
  1262 	return NULL;
  1263 }
  1263 }
  1264 
  1264 
  1265 void *print_datatypes_error_c::visit(while_statement_c *symbol) {
  1265 void *print_datatypes_error_c::visit(while_statement_c *symbol) {
  1266 	symbol->expression->accept(*this);
  1266 	symbol->expression->accept(*this);
  1267 	if (!is_type_valid(symbol->expression->datatype)) {
  1267 	if (!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) {
  1268 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'WHILE' condition.");
  1268 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'WHILE' condition.");
  1269 		return NULL;
  1269 		return NULL;
  1270 	}
  1270 	}
  1271 	if (NULL != symbol->statement_list)
  1271 	if (NULL != symbol->statement_list)
  1272 		symbol->statement_list->accept(*this);
  1272 		symbol->statement_list->accept(*this);
  1273 	return NULL;
  1273 	return NULL;
  1274 }
  1274 }
  1275 
  1275 
  1276 void *print_datatypes_error_c::visit(repeat_statement_c *symbol) {
  1276 void *print_datatypes_error_c::visit(repeat_statement_c *symbol) {
  1277 	if (!is_type_valid(symbol->expression->datatype)) {
  1277 	if (!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) {
  1278 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'REPEAT' condition.");
  1278 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'REPEAT' condition.");
  1279 		return NULL;
  1279 		return NULL;
  1280 	}
  1280 	}
  1281 	if (NULL != symbol->statement_list)
  1281 	if (NULL != symbol->statement_list)
  1282 		symbol->statement_list->accept(*this);
  1282 		symbol->statement_list->accept(*this);