stage3/print_datatypes_error.cc
changeset 849 1f8885ae539a
parent 848 db78824cec23
child 873 dea39ef02847
equal deleted inserted replaced
823:c95f42f28b69 849:1f8885ae539a
   158 		fcall_data.formal_operand_list->accept(*this);
   158 		fcall_data.formal_operand_list->accept(*this);
   159 		if (NULL != f_decl) {
   159 		if (NULL != f_decl) {
   160 			function_param_iterator_c fp_iterator(f_decl);
   160 			function_param_iterator_c fp_iterator(f_decl);
   161 			while ((param_name = fcp_iterator.next_f()) != NULL) {
   161 			while ((param_name = fcp_iterator.next_f()) != NULL) {
   162 				param_value = fcp_iterator.get_current_value();
   162 				param_value = fcp_iterator.get_current_value();
   163 
   163 				
   164 				/* Check if there are duplicate parameter values */
   164 				/* Check if there are duplicate parameter values */
   165 				if(fcp_iterator.search_f(param_name) != param_value) {
   165 				if(fcp_iterator.search_f(param_name) != param_value) {
   166 					function_invocation_error = true;
   166 					function_invocation_error = true;
   167 					STAGE3_ERROR(0, param_name, param_name, "Duplicate parameter '%s' when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   167 					STAGE3_ERROR(0, param_name, param_name, "Duplicate parameter '%s' when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   168 					continue; /* jump to next parameter */
   168 					continue; /* jump to next parameter */
   193 						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax '=>' used for parameter '%s', when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   193 						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax '=>' used for parameter '%s', when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   194 						continue; /* jump to next parameter */
   194 						continue; /* jump to next parameter */
   195 					}
   195 					}
   196 				} else ERROR;
   196 				} else ERROR;
   197 
   197 
   198 				if (NULL == param_value->datatype) {
   198 				if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
   199 					function_invocation_error = true;
   199 					function_invocation_error = true;
   200 					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility between parameter '%s' and value being passed, when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   200 					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility between parameter '%s' and value being passed, when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
   201 					continue; /* jump to next parameter */
   201 					continue; /* jump to next parameter */
   202 				}
   202 				}
   203 			}
   203 			}
   204 		}
   204 		}
   205 	}
   205 	}
   206 	if (NULL != fcall_data.nonformal_operand_list) {
   206 	if (NULL != fcall_data.nonformal_operand_list) {
   207 		fcall_data.nonformal_operand_list->accept(*this);
       
   208 		if (f_decl)
   207 		if (f_decl)
   209 			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
   208 			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
   210 		  		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
   209 		  		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
   211 
   210 
   212 				/* This handle_function_invocation() will be called to handle IL function calls, where the first parameter comes from the previous IL instruction.
   211 				/* This handle_function_invocation() will be called to handle IL function calls, where the first parameter comes from the previous IL instruction.
   249 					}
   248 					}
   250 #endif
   249 #endif
   251 					if (function_invocation_error)
   250 					if (function_invocation_error)
   252 						/* 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. */
   251 						/* 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. */
   253 						return;
   252 						return;
   254 				}
   253 				} else {
   255 				else if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
   254 					if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
   256 					function_invocation_error = true;
   255 						function_invocation_error = true;
   257 					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);
   256 						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);
       
   257 					}
       
   258 					param_value->accept(*this);
   258 				}
   259 				}
   259 			}
   260 			}
   260 	}
   261 	}
   261 
   262 
   262 	if (NULL == fcall_data.called_function_declaration) {
   263 	if (NULL == fcall_data.called_function_declaration) {
   277 void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) {
   278 void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) {
   278 	if (NULL == il_operand) {
   279 	if (NULL == il_operand) {
   279 		STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name);
   280 		STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name);
   280 		return NULL;
   281 		return NULL;
   281 	}
   282 	}
   282 	il_operand->accept(*this);
   283 	// il_operand->accept(*this);  // NOT required. The il_simple_operation_c already visits it!!
   283 	
   284 	
   284 	if (NULL == called_fb_declaration) {
   285 	if (NULL == called_fb_declaration) {
   285 		STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance.");
   286 		STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance.");
   286 		return NULL;
   287 		return NULL;
   287 	}
   288 	}
   313 	/* NOTE: The error_level currently being used for errors in variables/constants etc... is rather high.
   314 	/* NOTE: The error_level currently being used for errors in variables/constants etc... is rather high.
   314 	 *       However, in the case of an implicit FB call, if the datatype of the operand == NULL, this may be
   315 	 *       However, in the case of an implicit FB call, if the datatype of the operand == NULL, this may be
   315 	 *       the __only__ indication of an error! So we test it here again, to make sure thtis error will really
   316 	 *       the __only__ indication of an error! So we test it here again, to make sure thtis error will really
   316 	 *       be printed out!
   317 	 *       be printed out!
   317 	 */
   318 	 */
   318 	if (NULL == il_operand->datatype) {
   319 	if (!get_datatype_info_c::is_type_valid(il_operand->datatype)) {
   319 		/* Note: the case of (NULL == fb_declaration) was already caught above! */
   320 		/* Note: the case of (NULL == fb_declaration) was already caught above! */
   320 // 		if (NULL != fb_declaration) {
   321 // 		if (NULL != fb_declaration) {
   321 			STAGE3_ERROR(0, il_operator, il_operator, "Invalid FB call: Datatype incompatibility between the FB's '%s' parameter and value being passed, or paramater '%s' is not a 'VAR_INPUT' parameter.", param_name, param_name);
   322 			STAGE3_ERROR(0, il_operator, il_operator, "Invalid FB call: Datatype incompatibility between the FB's '%s' parameter and value being passed, or paramater '%s' is not a 'VAR_INPUT' parameter.", param_name, param_name);
   322 			return NULL;
   323 			return NULL;
   323 // 		}
   324 // 		}
   334 /* B 1.2.1 - Numeric Literals */
   335 /* B 1.2.1 - Numeric Literals */
   335 /******************************/
   336 /******************************/
   336 void *print_datatypes_error_c::visit(real_c *symbol) {
   337 void *print_datatypes_error_c::visit(real_c *symbol) {
   337 	if (symbol->candidate_datatypes.size() == 0) {
   338 	if (symbol->candidate_datatypes.size() == 0) {
   338 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
   339 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
   339 	} else if (NULL == symbol->datatype) {
   340 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   340 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   341 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   341 	}
   342 	}
   342 	return NULL;
   343 	return NULL;
   343 }
   344 }
   344 
   345 
   345 void *print_datatypes_error_c::visit(integer_c *symbol) {
   346 void *print_datatypes_error_c::visit(integer_c *symbol) {
   346 	if (symbol->candidate_datatypes.size() == 0) {
   347 	if (symbol->candidate_datatypes.size() == 0) {
   347 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   348 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   348 	} else if (NULL == symbol->datatype) {
   349 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   349 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   350 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   350 	}
   351 	}
   351 	return NULL;
   352 	return NULL;
   352 }
   353 }
   353 
   354 
   354 void *print_datatypes_error_c::visit(neg_real_c *symbol) {
   355 void *print_datatypes_error_c::visit(neg_real_c *symbol) {
   355 	if (symbol->candidate_datatypes.size() == 0) {
   356 	if (symbol->candidate_datatypes.size() == 0) {
   356 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
   357 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
   357 	} else if (NULL == symbol->datatype) {
   358 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   358 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   359 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   359 	}
   360 	}
   360 	return NULL;
   361 	return NULL;
   361 }
   362 }
   362 
   363 
   363 void *print_datatypes_error_c::visit(neg_integer_c *symbol) {
   364 void *print_datatypes_error_c::visit(neg_integer_c *symbol) {
   364 	if (symbol->candidate_datatypes.size() == 0) {
   365 	if (symbol->candidate_datatypes.size() == 0) {
   365 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   366 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   366 	} else if (NULL == symbol->datatype) {
   367 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   367 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   368 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   368 	}
   369 	}
   369 	return NULL;
   370 	return NULL;
   370 }
   371 }
   371 
   372 
   372 void *print_datatypes_error_c::visit(binary_integer_c *symbol) {
   373 void *print_datatypes_error_c::visit(binary_integer_c *symbol) {
   373 	if (symbol->candidate_datatypes.size() == 0) {
   374 	if (symbol->candidate_datatypes.size() == 0) {
   374 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   375 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   375 	} else if (NULL == symbol->datatype) {
   376 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   376 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   377 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   377 	}
   378 	}
   378 	return NULL;
   379 	return NULL;
   379 }
   380 }
   380 
   381 
   381 void *print_datatypes_error_c::visit(octal_integer_c *symbol) {
   382 void *print_datatypes_error_c::visit(octal_integer_c *symbol) {
   382 	if (symbol->candidate_datatypes.size() == 0) {
   383 	if (symbol->candidate_datatypes.size() == 0) {
   383 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   384 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   384 	} else if (NULL == symbol->datatype) {
   385 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   385 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   386 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   386 	}
   387 	}
   387 	return NULL;
   388 	return NULL;
   388 }
   389 }
   389 
   390 
   390 void *print_datatypes_error_c::visit(hex_integer_c *symbol) {
   391 void *print_datatypes_error_c::visit(hex_integer_c *symbol) {
   391 	if (symbol->candidate_datatypes.size() == 0) {
   392 	if (symbol->candidate_datatypes.size() == 0) {
   392 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   393 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
   393 	} else if (NULL == symbol->datatype) {
   394 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   394 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   395 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   395 	}
   396 	}
   396 	return NULL;
   397 	return NULL;
   397 }
   398 }
   398 
   399 
   399 void *print_datatypes_error_c::visit(integer_literal_c *symbol) {
   400 void *print_datatypes_error_c::visit(integer_literal_c *symbol) {
   400 	if (symbol->candidate_datatypes.size() == 0) {
   401 	if (symbol->candidate_datatypes.size() == 0) {
   401 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   402 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   402 	} else if (NULL == symbol->datatype) {
   403 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   403 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   404 		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
   404 	}
   405 	}
   405 	return NULL;
   406 	return NULL;
   406 }
   407 }
   407 
   408 
   408 void *print_datatypes_error_c::visit(real_literal_c *symbol) {
   409 void *print_datatypes_error_c::visit(real_literal_c *symbol) {
   409 	if (symbol->candidate_datatypes.size() == 0) {
   410 	if (symbol->candidate_datatypes.size() == 0) {
   410 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   411 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   411 	} else if (NULL == symbol->datatype) {
   412 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   412 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   413 		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
   413 	}
   414 	}
   414 	return NULL;
   415 	return NULL;
   415 }
   416 }
   416 
   417 
   417 void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) {
   418 void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) {
   418 	if (symbol->candidate_datatypes.size() == 0) {
   419 	if (symbol->candidate_datatypes.size() == 0) {
   419 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   420 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   420 	} else if (NULL == symbol->datatype) {
   421 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   421 		STAGE3_ERROR(4, symbol, symbol, "ANY_BIT data type not valid in this location.");
   422 		STAGE3_ERROR(4, symbol, symbol, "ANY_BIT data type not valid in this location.");
   422 	}
   423 	}
   423 	return NULL;
   424 	return NULL;
   424 }
   425 }
   425 
   426 
   426 void *print_datatypes_error_c::visit(boolean_literal_c *symbol) {
   427 void *print_datatypes_error_c::visit(boolean_literal_c *symbol) {
   427 	if (symbol->candidate_datatypes.size() == 0) {
   428 	if (symbol->candidate_datatypes.size() == 0) {
   428 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   429 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
   429 	} else if (NULL == symbol->datatype) {
   430 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   430 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   431 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   431 	}
   432 	}
   432 	return NULL;
   433 	return NULL;
   433 }
   434 }
   434 
   435 
   435 void *print_datatypes_error_c::visit(boolean_true_c *symbol) {
   436 void *print_datatypes_error_c::visit(boolean_true_c *symbol) {
   436 	if (symbol->candidate_datatypes.size() == 0) {
   437 	if (symbol->candidate_datatypes.size() == 0) {
   437 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
   438 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
   438 	} else if (NULL == symbol->datatype) {
   439 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   439 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   440 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   440 	}
   441 	}
   441 	return NULL;
   442 	return NULL;
   442 }
   443 }
   443 
   444 
   444 void *print_datatypes_error_c::visit(boolean_false_c *symbol) {
   445 void *print_datatypes_error_c::visit(boolean_false_c *symbol) {
   445 	if (symbol->candidate_datatypes.size() == 0) {
   446 	if (symbol->candidate_datatypes.size() == 0) {
   446 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
   447 		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
   447 	} else if (NULL == symbol->datatype) {
   448 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   448 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   449 		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
   449 	}
   450 	}
   450 	return NULL;
   451 	return NULL;
   451 }
   452 }
   452 
   453 
   454 /* B.1.2.2   Character Strings */
   455 /* B.1.2.2   Character Strings */
   455 /*******************************/
   456 /*******************************/
   456 void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) {
   457 void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) {
   457 	if (symbol->candidate_datatypes.size() == 0) {
   458 	if (symbol->candidate_datatypes.size() == 0) {
   458 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for WSTRING data type.");
   459 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for WSTRING data type.");
   459 	} else if (NULL == symbol->datatype) {
   460 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   460 		STAGE3_ERROR(4, symbol, symbol, "WSTRING data type not valid in this location.");
   461 		STAGE3_ERROR(4, symbol, symbol, "WSTRING data type not valid in this location.");
   461 	}
   462 	}
   462 	return NULL;
   463 	return NULL;
   463 }
   464 }
   464 
   465 
   465 void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) {
   466 void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) {
   466 	if (symbol->candidate_datatypes.size() == 0) {
   467 	if (symbol->candidate_datatypes.size() == 0) {
   467 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for STRING data type.");
   468 		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for STRING data type.");
   468 	} else if (NULL == symbol->datatype) {
   469 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   469 		STAGE3_ERROR(4, symbol, symbol, "STRING data type not valid in this location.");
   470 		STAGE3_ERROR(4, symbol, symbol, "STRING data type not valid in this location.");
   470 	}
   471 	}
   471 	return NULL;
   472 	return NULL;
   472 }
   473 }
   473 
   474 
   478 /* B 1.2.3.1 - Duration */
   479 /* B 1.2.3.1 - Duration */
   479 /************************/
   480 /************************/
   480 void *print_datatypes_error_c::visit(duration_c *symbol) {
   481 void *print_datatypes_error_c::visit(duration_c *symbol) {
   481 	if (symbol->candidate_datatypes.size() == 0) {
   482 	if (symbol->candidate_datatypes.size() == 0) {
   482 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TIME data type.");
   483 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TIME data type.");
   483 	} else if (NULL == symbol->datatype) {
   484 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   484 		STAGE3_ERROR(4, symbol, symbol, "TIME data type not valid in this location.");
   485 		STAGE3_ERROR(4, symbol, symbol, "TIME data type not valid in this location.");
   485 	}
   486 	}
   486 	return NULL;
   487 	return NULL;
   487 }
   488 }
   488 
   489 
   490 /* B 1.2.3.2 - Time of day and Date */
   491 /* B 1.2.3.2 - Time of day and Date */
   491 /************************************/
   492 /************************************/
   492 void *print_datatypes_error_c::visit(time_of_day_c *symbol) {
   493 void *print_datatypes_error_c::visit(time_of_day_c *symbol) {
   493 	if (symbol->candidate_datatypes.size() == 0) {
   494 	if (symbol->candidate_datatypes.size() == 0) {
   494 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TOD data type.");
   495 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TOD data type.");
   495 	} else if (NULL == symbol->datatype) {
   496 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   496 		STAGE3_ERROR(4, symbol, symbol, "TOD data type not valid in this location.");
   497 		STAGE3_ERROR(4, symbol, symbol, "TOD data type not valid in this location.");
   497 	}
   498 	}
   498 	return NULL;
   499 	return NULL;
   499 }
   500 }
   500 
   501 
   501 void *print_datatypes_error_c::visit(date_c *symbol) {
   502 void *print_datatypes_error_c::visit(date_c *symbol) {
   502 	if (symbol->candidate_datatypes.size() == 0) {
   503 	if (symbol->candidate_datatypes.size() == 0) {
   503 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DATE data type.");
   504 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DATE data type.");
   504 	} else if (NULL == symbol->datatype) {
   505 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   505 		STAGE3_ERROR(4, symbol, symbol, "DATE data type not valid in this location.");
   506 		STAGE3_ERROR(4, symbol, symbol, "DATE data type not valid in this location.");
   506 	}
   507 	}
   507 	return NULL;
   508 	return NULL;
   508 }
   509 }
   509 
   510 
   510 void *print_datatypes_error_c::visit(date_and_time_c *symbol) {
   511 void *print_datatypes_error_c::visit(date_and_time_c *symbol) {
   511 	if (symbol->candidate_datatypes.size() == 0) {
   512 	if (symbol->candidate_datatypes.size() == 0) {
   512 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DT data type.");
   513 		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DT data type.");
   513 	} else if (NULL == symbol->datatype) {
   514 	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
   514 		STAGE3_ERROR(4, symbol, symbol, "DT data type not valid in this location.");
   515 		STAGE3_ERROR(4, symbol, symbol, "DT data type not valid in this location.");
   515 	}
   516 	}
   516 	return NULL;
   517 	return NULL;
   517 }
   518 }
   518 
   519 
   567 /* B 1.4.2 - Multi-element variables */
   568 /* B 1.4.2 - Multi-element variables */
   568 /*************************************/
   569 /*************************************/
   569 /*  subscripted_variable '[' subscript_list ']' */
   570 /*  subscripted_variable '[' subscript_list ']' */
   570 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   571 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   571 void *print_datatypes_error_c::visit(array_variable_c *symbol) {
   572 void *print_datatypes_error_c::visit(array_variable_c *symbol) {
       
   573 	/* the subscripted variable may be a structure or another array variable, that must also be visisted! */
       
   574 	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
       
   575 	symbol->subscripted_variable->accept(*this); 
       
   576 	
   572 	if (symbol->candidate_datatypes.size() == 0)
   577 	if (symbol->candidate_datatypes.size() == 0)
   573 		STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope.");
   578 		STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope.");
   574 	
   579 	
   575 	/* recursively call the subscript list to print any errors in the expressions used in the subscript...*/
   580 	/* recursively call the subscript list to print any errors in the expressions used in the subscript...*/
   576 	symbol->subscript_list->accept(*this);
   581 	symbol->subscript_list->accept(*this);
   582 void *print_datatypes_error_c::visit(subscript_list_c *symbol) {
   587 void *print_datatypes_error_c::visit(subscript_list_c *symbol) {
   583 	for (int i = 0; i < symbol->n; i++) {
   588 	for (int i = 0; i < symbol->n; i++) {
   584 		int start_error_count = error_count;
   589 		int start_error_count = error_count;
   585 		symbol->elements[i]->accept(*this);
   590 		symbol->elements[i]->accept(*this);
   586 		/* The following error message will only get printed if the current_display_error_level is set higher than 0! */
   591 		/* The following error message will only get printed if the current_display_error_level is set higher than 0! */
   587 		if ((start_error_count == error_count) && (NULL == symbol->elements[i]->datatype))
   592 		if ((start_error_count == error_count) && (!get_datatype_info_c::is_type_valid(symbol->elements[i]->datatype)))
   588 			STAGE3_ERROR(0, symbol, symbol, "Invalid data type for array subscript field.");
   593 			STAGE3_ERROR(0, symbol, symbol, "Invalid data type for array subscript field.");
   589 	}
   594 	}
   590 	return NULL;
   595 	return NULL;
   591 }
   596 }
   592 
   597 
   596  *           may be accessed as fields of a structured variable!
   601  *           may be accessed as fields of a structured variable!
   597  *           Code handling a structured_variable_c must take
   602  *           Code handling a structured_variable_c must take
   598  *           this into account!
   603  *           this into account!
   599  */
   604  */
   600 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   605 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   601 /* NOTE: We do not recursively determine the data types of each field_selector in fill_candidate_datatypes_c,
       
   602  * so it does not make sense to recursively visit all the field_selectors to print out error messages. 
       
   603  * Maybe in the future, if we find the need to print out more detailed error messages, we might do it that way. For now, we don't!
       
   604  */
       
   605 void *print_datatypes_error_c::visit(structured_variable_c *symbol) {
   606 void *print_datatypes_error_c::visit(structured_variable_c *symbol) {
       
   607 	/* the record variable may be another structure or even an array variable, that must also be visisted! */
       
   608 	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
       
   609 	symbol->record_variable->accept(*this);
       
   610 	
   606 	if (symbol->candidate_datatypes.size() == 0)
   611 	if (symbol->candidate_datatypes.size() == 0)
   607 		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured/FB variable.");
   612 		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured (or FB) variable, or non-existant field (variable) in structure (FB).");
   608 	return NULL;
   613 	return NULL;
   609 }
   614 }
   610 
   615 
   611 
   616 
   612 
   617 
   755 
   760 
   756 
   761 
   757 
   762 
   758 void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) {
   763 void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) {
   759 	il_operand = symbol->il_operand;
   764 	il_operand = symbol->il_operand;
   760 	if (NULL != symbol->il_operand) {
   765 	if (NULL != il_operand)     symbol->il_operand->accept(*this); /* recursive call to see whether data types are compatible */
   761 		symbol->il_operand->accept(*this);
   766 
   762 	}
       
   763 	/* recursive call to see whether data types are compatible */
       
   764 	symbol->il_simple_operator->accept(*this);
   767 	symbol->il_simple_operator->accept(*this);
   765 	il_operand = NULL;
   768 	il_operand = NULL;
   766 	return NULL;
   769 	return NULL;
   767 }
   770 }
   768 
   771 
   927 
   930 
   928 /*******************/
   931 /*******************/
   929 /* B 2.2 Operators */
   932 /* B 2.2 Operators */
   930 /*******************/
   933 /*******************/
   931 void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
   934 void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
   932 	if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
   935 	if (NULL == il_operand) {
   933 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);
   936 		STAGE3_ERROR(0, symbol, symbol, "Missing operand for %s operator.", il_operator);		// message (a)
   934 	} else if (NULL == symbol->datatype) {
   937 	} else if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
   935 		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);
   938 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);		// message (b)
       
   939 	} else if (NULL == symbol->datatype) {  // do NOT use !get_datatype_info_c::is_type_valid() here!
       
   940 		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);		// message (c)
   936 	} else if (deprecated_operation)
   941 	} else if (deprecated_operation)
   937 		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);
   942 		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);		// message (d)
   938 	return NULL;
   943 	return NULL;
   939 }
   944 }
   940 
   945 
   941 
   946 
   942 void *print_datatypes_error_c::visit(LD_operator_c *symbol) {
   947 void *print_datatypes_error_c::visit(  LD_operator_c *symbol) {return print_binary_operator_errors("LD"  , symbol);}  // I believe it will never emit messages (b) and (c)!!
   943 	return NULL;
   948 void *print_datatypes_error_c::visit( LDN_operator_c *symbol) {return print_binary_operator_errors("LDN" , symbol);}  // I believe it will never emit message (c)
   944 }
   949 void *print_datatypes_error_c::visit(  ST_operator_c *symbol) {return print_binary_operator_errors("ST"  , symbol);}  // I believe it will never emit message (c)
   945 
   950 void *print_datatypes_error_c::visit( STN_operator_c *symbol) {return print_binary_operator_errors("STN" , symbol);}  // I believe it will never emit message (c)
   946 void *print_datatypes_error_c::visit(LDN_operator_c *symbol) {
       
   947 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   948 		(il_operand->candidate_datatypes.size() > 0))
       
   949 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'LDN' operator.");
       
   950 	return NULL;
       
   951 }
       
   952 
       
   953 void *print_datatypes_error_c::visit(ST_operator_c *symbol) {
       
   954 	/* MANU:
       
   955 	 * if prev_instruction is NULL we can print a message error or warning error like:
       
   956 	 * we can't use a ST like first instruction.
       
   957 	 * What do you think?
       
   958 	 */
       
   959 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   960 		(il_operand->candidate_datatypes.size() > 0))
       
   961 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ST' operator.");
       
   962 	return NULL;
       
   963 }
       
   964 
       
   965 void *print_datatypes_error_c::visit(STN_operator_c *symbol) {
       
   966 	/* MANU:
       
   967 	 * if prev_instruction is NULL we can print a message error or warning error like:
       
   968 	 * we can't use a ST like first instruction.
       
   969 	 * What do you think?
       
   970 	 */
       
   971 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   972 		(il_operand->candidate_datatypes.size() > 0))
       
   973 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'STN' operator.");
       
   974 	return NULL;
       
   975 }
       
   976 
   951 
   977 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
   952 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
   978 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
   953 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
   979 	 *              NOT [<il_operand>]
   954 	 *              NOT [<il_operand>]
   980 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
   955 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
   981 	 *       We therefore consider it an error if an il_operand is specified!
   956 	 *       We therefore consider it an error if an il_operand is specified!
   982 	 */
   957 	 */
   983 	if (il_operand != NULL)
   958 	if (il_operand != NULL) {
   984 		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
   959 		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
   985 	if (symbol->candidate_datatypes.size() == 0)
   960 	} else if (symbol->candidate_datatypes.size() == 0)
   986 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
   961 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
   987 	return NULL;
   962 	return NULL;
   988 }
   963 }
   989 
   964 
   990 void *print_datatypes_error_c::visit(S_operator_c *symbol) {
   965 void *print_datatypes_error_c::visit(S_operator_c *symbol) {
   991   /* TODO: what if this is a FB call ?? */
   966 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("S", symbol, symbol->called_fb_declaration);
   992 	if ((symbol->candidate_datatypes.size() == 0) 		&&
   967 	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("S", symbol);
   993 		(il_operand->candidate_datatypes.size() > 0))
       
   994 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'S' operator.");
       
   995 	return NULL;
       
   996 }
   968 }
   997 
   969 
   998 void *print_datatypes_error_c::visit(R_operator_c *symbol) {
   970 void *print_datatypes_error_c::visit(R_operator_c *symbol) {
   999   /* TODO: what if this is a FB call ?? */
   971 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("R", symbol, symbol->called_fb_declaration);
  1000 	if ((symbol->candidate_datatypes.size() == 0) 		&&
   972 	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("R", symbol);
  1001 		(il_operand->candidate_datatypes.size() > 0))
       
  1002 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' operator.");
       
  1003 	return NULL;
       
  1004 }
   973 }
  1005 
   974 
  1006 void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);}
   975 void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);}
  1007 void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);}
   976 void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);}
  1008 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);}
   977 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);}
  1033 
  1002 
  1034   
  1003   
  1035 
  1004 
  1036 
  1005 
  1037 void *print_datatypes_error_c::handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper) {
  1006 void *print_datatypes_error_c::handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper) {
  1038 	if (NULL == symbol->datatype)
  1007 	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
  1039 		STAGE3_ERROR(0, symbol, symbol, "%s operator must be preceded by an IL instruction producing a BOOL value.", oper);
  1008 		STAGE3_ERROR(0, symbol, symbol, "%s operator must be preceded by an IL instruction producing a BOOL value.", oper);
  1040 	return NULL;
  1009 	return NULL;
  1041 }
  1010 }
  1042 
  1011 
  1043 void *print_datatypes_error_c::visit(  CAL_operator_c *symbol) {return NULL;}
  1012 void *print_datatypes_error_c::visit(  CAL_operator_c *symbol) {return NULL;}
  1140 /* B 3.2.1 Assignment Statements */
  1109 /* B 3.2.1 Assignment Statements */
  1141 /*********************************/
  1110 /*********************************/
  1142 void *print_datatypes_error_c::visit(assignment_statement_c *symbol) {
  1111 void *print_datatypes_error_c::visit(assignment_statement_c *symbol) {
  1143 	symbol->l_exp->accept(*this);
  1112 	symbol->l_exp->accept(*this);
  1144 	symbol->r_exp->accept(*this);
  1113 	symbol->r_exp->accept(*this);
  1145 	if ((NULL == symbol->l_exp->datatype) &&
  1114 	if ((!get_datatype_info_c::is_type_valid(symbol->l_exp->datatype)) &&
  1146 	    (NULL == symbol->r_exp->datatype) &&
  1115 	    (!get_datatype_info_c::is_type_valid(symbol->r_exp->datatype)) &&
  1147 		(symbol->l_exp->candidate_datatypes.size() > 0)	&&
  1116 	    (symbol->l_exp->candidate_datatypes.size() > 0)	&&
  1148 		(symbol->r_exp->candidate_datatypes.size() > 0))
  1117 	    (symbol->r_exp->candidate_datatypes.size() > 0))
  1149 		STAGE3_ERROR(0, symbol, symbol, "Incompatible data types for ':=' operation.");
  1118 		STAGE3_ERROR(0, symbol, symbol, "Incompatible data types for ':=' operation.");
  1150 	return NULL;
  1119 	return NULL;
  1151 }
  1120 }
  1152 
  1121 
  1153 
  1122 
  1181 /* B 3.2.3 Selection Statements */
  1150 /* B 3.2.3 Selection Statements */
  1182 /********************************/
  1151 /********************************/
  1183 
  1152 
  1184 void *print_datatypes_error_c::visit(if_statement_c *symbol) {
  1153 void *print_datatypes_error_c::visit(if_statement_c *symbol) {
  1185 	symbol->expression->accept(*this);
  1154 	symbol->expression->accept(*this);
  1186 	if ((NULL == symbol->expression->datatype) &&
  1155 	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
  1187 		(symbol->expression->candidate_datatypes.size() > 0)) {
  1156 	    (symbol->expression->candidate_datatypes.size() > 0)) {
  1188 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'IF' condition.");
  1157 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'IF' condition.");
  1189 	}
  1158 	}
  1190 	if (NULL != symbol->statement_list)
  1159 	if (NULL != symbol->statement_list)
  1191 		symbol->statement_list->accept(*this);
  1160 		symbol->statement_list->accept(*this);
  1192 	if (NULL != symbol->elseif_statement_list)
  1161 	if (NULL != symbol->elseif_statement_list)
  1196 	return NULL;
  1165 	return NULL;
  1197 }
  1166 }
  1198 
  1167 
  1199 void *print_datatypes_error_c::visit(elseif_statement_c *symbol) {
  1168 void *print_datatypes_error_c::visit(elseif_statement_c *symbol) {
  1200 	symbol->expression->accept(*this);
  1169 	symbol->expression->accept(*this);
  1201 	if ((NULL == symbol->expression->datatype) &&
  1170 	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
  1202 		(symbol->expression->candidate_datatypes.size() > 0)) {
  1171 	    (symbol->expression->candidate_datatypes.size() > 0)) {
  1203 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'ELSIF' condition.");
  1172 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'ELSIF' condition.");
  1204 	}
  1173 	}
  1205 	if (NULL != symbol->statement_list)
  1174 	if (NULL != symbol->statement_list)
  1206 		symbol->statement_list->accept(*this);
  1175 		symbol->statement_list->accept(*this);
  1207 	return NULL;
  1176 	return NULL;
  1208 }
  1177 }
  1209 
  1178 
  1210 
  1179 
  1211 void *print_datatypes_error_c::visit(case_statement_c *symbol) {
  1180 void *print_datatypes_error_c::visit(case_statement_c *symbol) {
  1212 	symbol->expression->accept(*this);
  1181 	symbol->expression->accept(*this);
  1213 	if ((NULL == symbol->expression->datatype) &&
  1182 	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
  1214 		(symbol->expression->candidate_datatypes.size() > 0)) {
  1183 	    (symbol->expression->candidate_datatypes.size() > 0)) {
  1215 		STAGE3_ERROR(0, symbol, symbol, "'CASE' quantity not an integer or enumerated.");
  1184 		STAGE3_ERROR(0, symbol, symbol, "'CASE' quantity not an integer or enumerated.");
  1216 	}
  1185 	}
  1217 	symbol->case_element_list->accept(*this);
  1186 	symbol->case_element_list->accept(*this);
  1218 	if (NULL != symbol->statement_list)
  1187 	if (NULL != symbol->statement_list)
  1219 		symbol->statement_list->accept(*this);
  1188 		symbol->statement_list->accept(*this);
  1227 void *print_datatypes_error_c::visit(for_statement_c *symbol) {
  1196 void *print_datatypes_error_c::visit(for_statement_c *symbol) {
  1228 	symbol->control_variable->accept(*this);
  1197 	symbol->control_variable->accept(*this);
  1229 	symbol->beg_expression->accept(*this);
  1198 	symbol->beg_expression->accept(*this);
  1230 	symbol->end_expression->accept(*this);
  1199 	symbol->end_expression->accept(*this);
  1231 	/* Control variable */
  1200 	/* Control variable */
  1232 	if ((NULL == symbol->control_variable->datatype) &&
  1201 	if ((!get_datatype_info_c::is_type_valid(symbol->control_variable->datatype)) &&
  1233 		(symbol->control_variable->candidate_datatypes.size() > 0)) {
  1202 	    (symbol->control_variable->candidate_datatypes.size() > 0)) {
  1234 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' control variable.");
  1203 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' control variable.");
  1235 	}
  1204 	}
  1236 	/* BEG expression */
  1205 	/* BEG expression */
  1237 	if ((NULL == symbol->beg_expression->datatype) &&
  1206 	if ((!get_datatype_info_c::is_type_valid(symbol->beg_expression->datatype)) &&
  1238 		(symbol->beg_expression->candidate_datatypes.size() > 0)) {
  1207 	    (symbol->beg_expression->candidate_datatypes.size() > 0)) {
  1239 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' begin expression.");
  1208 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' begin expression.");
  1240 	}
  1209 	}
  1241 	/* END expression */
  1210 	/* END expression */
  1242 	if ((NULL == symbol->end_expression->datatype) &&
  1211 	if ((!get_datatype_info_c::is_type_valid(symbol->end_expression->datatype)) &&
  1243 		(symbol->end_expression->candidate_datatypes.size() > 0)) {
  1212 	    (symbol->end_expression->candidate_datatypes.size() > 0)) {
  1244 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' end expression.");
  1213 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' end expression.");
  1245 	}
  1214 	}
  1246 	/* BY expression */
  1215 	/* BY expression */
  1247 	if ((NULL != symbol->by_expression) &&
  1216 	if ((NULL != symbol->by_expression) &&
  1248 		(NULL == symbol->by_expression->datatype) &&
  1217 	    (!get_datatype_info_c::is_type_valid(symbol->by_expression->datatype)) &&
  1249 		(symbol->end_expression->candidate_datatypes.size() > 0)) {
  1218 	    (symbol->end_expression->candidate_datatypes.size() > 0)) {
  1250 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' by expression.");
  1219 		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' by expression.");
  1251 	}
  1220 	}
  1252 	/* DO statement */
  1221 	/* DO statement */
  1253 	if (NULL != symbol->statement_list)
  1222 	if (NULL != symbol->statement_list)
  1254 		symbol->statement_list->accept(*this);
  1223 		symbol->statement_list->accept(*this);