stage3/print_datatypes_error.cc
changeset 834 783ef40344dd
parent 829 6e39eea5f5d0
child 841 aed36f08545d
equal deleted inserted replaced
833:27f246b35ac2 834:783ef40344dd
   276 void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) {
   276 void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) {
   277 	if (NULL == il_operand) {
   277 	if (NULL == il_operand) {
   278 		STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name);
   278 		STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name);
   279 		return NULL;
   279 		return NULL;
   280 	}
   280 	}
   281 	il_operand->accept(*this);
   281 	// il_operand->accept(*this);  // NOT required. The il_simple_operation_c already visits it!!
   282 	
   282 	
   283 	if (NULL == called_fb_declaration) {
   283 	if (NULL == called_fb_declaration) {
   284 		STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance.");
   284 		STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance.");
   285 		return NULL;
   285 		return NULL;
   286 	}
   286 	}
   758 
   758 
   759 
   759 
   760 
   760 
   761 void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) {
   761 void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) {
   762 	il_operand = symbol->il_operand;
   762 	il_operand = symbol->il_operand;
   763 	if (NULL != symbol->il_operand) {
   763 	if (NULL != il_operand)     symbol->il_operand->accept(*this); /* recursive call to see whether data types are compatible */
   764 		symbol->il_operand->accept(*this);
   764 
   765 	}
       
   766 	/* recursive call to see whether data types are compatible */
       
   767 	symbol->il_simple_operator->accept(*this);
   765 	symbol->il_simple_operator->accept(*this);
   768 	il_operand = NULL;
   766 	il_operand = NULL;
   769 	return NULL;
   767 	return NULL;
   770 }
   768 }
   771 
   769 
   930 
   928 
   931 /*******************/
   929 /*******************/
   932 /* B 2.2 Operators */
   930 /* B 2.2 Operators */
   933 /*******************/
   931 /*******************/
   934 void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
   932 void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
   935 	if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
   933 	if (NULL == il_operand) {
   936 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);
   934 		STAGE3_ERROR(0, symbol, symbol, "Missing operand for %s operator.", il_operator);		// message (a)
   937 	} else if (NULL == symbol->datatype) {
   935 	} else if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
   938 		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);
   936 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);		// message (b)
       
   937 	} else if (NULL == symbol->datatype) {
       
   938 		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);		// message (c)
   939 	} else if (deprecated_operation)
   939 	} else if (deprecated_operation)
   940 		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);
   940 		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);		// message (d)
   941 	return NULL;
   941 	return NULL;
   942 }
   942 }
   943 
   943 
   944 
   944 
   945 void *print_datatypes_error_c::visit(LD_operator_c *symbol) {
   945 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)!!
   946 	return NULL;
   946 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)
   947 }
   947 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)
   948 
   948 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)
   949 void *print_datatypes_error_c::visit(LDN_operator_c *symbol) {
       
   950 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   951 		(il_operand->candidate_datatypes.size() > 0))
       
   952 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'LDN' operator.");
       
   953 	return NULL;
       
   954 }
       
   955 
       
   956 void *print_datatypes_error_c::visit(ST_operator_c *symbol) {
       
   957 	/* MANU:
       
   958 	 * if prev_instruction is NULL we can print a message error or warning error like:
       
   959 	 * we can't use a ST like first instruction.
       
   960 	 * What do you think?
       
   961 	 */
       
   962 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   963 		(il_operand->candidate_datatypes.size() > 0))
       
   964 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ST' operator.");
       
   965 	return NULL;
       
   966 }
       
   967 
       
   968 void *print_datatypes_error_c::visit(STN_operator_c *symbol) {
       
   969 	/* MANU:
       
   970 	 * if prev_instruction is NULL we can print a message error or warning error like:
       
   971 	 * we can't use a ST like first instruction.
       
   972 	 * What do you think?
       
   973 	 */
       
   974 	if ((symbol->candidate_datatypes.size() == 0) 		&&
       
   975 		(il_operand->candidate_datatypes.size() > 0))
       
   976 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'STN' operator.");
       
   977 	return NULL;
       
   978 }
       
   979 
   949 
   980 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
   950 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
   981 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
   951 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
   982 	 *              NOT [<il_operand>]
   952 	 *              NOT [<il_operand>]
   983 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
   953 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
   984 	 *       We therefore consider it an error if an il_operand is specified!
   954 	 *       We therefore consider it an error if an il_operand is specified!
   985 	 */
   955 	 */
   986 	if (il_operand != NULL)
   956 	if (il_operand != NULL) {
   987 		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
   957 		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
   988 	if (symbol->candidate_datatypes.size() == 0)
   958 	} else if (symbol->candidate_datatypes.size() == 0)
   989 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
   959 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
   990 	return NULL;
   960 	return NULL;
   991 }
   961 }
   992 
   962 
   993 void *print_datatypes_error_c::visit(S_operator_c *symbol) {
   963 void *print_datatypes_error_c::visit(S_operator_c *symbol) {
   994   /* TODO: what if this is a FB call ?? */
   964 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("S", symbol, symbol->called_fb_declaration);
   995 	if ((symbol->candidate_datatypes.size() == 0) 		&&
   965 	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("S", symbol);
   996 		(il_operand->candidate_datatypes.size() > 0))
       
   997 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'S' operator.");
       
   998 	return NULL;
       
   999 }
   966 }
  1000 
   967 
  1001 void *print_datatypes_error_c::visit(R_operator_c *symbol) {
   968 void *print_datatypes_error_c::visit(R_operator_c *symbol) {
  1002   /* TODO: what if this is a FB call ?? */
   969 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("R", symbol, symbol->called_fb_declaration);
  1003 	if ((symbol->candidate_datatypes.size() == 0) 		&&
   970 	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("R", symbol);
  1004 		(il_operand->candidate_datatypes.size() > 0))
       
  1005 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' operator.");
       
  1006 	return NULL;
       
  1007 }
   971 }
  1008 
   972 
  1009 void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);}
   973 void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);}
  1010 void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);}
   974 void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);}
  1011 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);}
   975 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);}