stage3/print_datatypes_error.cc
changeset 827 e3800aff352c
parent 778 44e02a88f1e7
child 829 6e39eea5f5d0
equal deleted inserted replaced
826:1e6bf9839ece 827:e3800aff352c
   132 	symbol_c *param_value, *param_name;
   132 	symbol_c *param_value, *param_name;
   133 	function_call_param_iterator_c fcp_iterator(fcall);
   133 	function_call_param_iterator_c fcp_iterator(fcall);
   134 	bool function_invocation_error = false;
   134 	bool function_invocation_error = false;
   135 	const char *POU_str = NULL;
   135 	const char *POU_str = NULL;
   136 
   136 
       
   137 debug_c::print("print_datatypes_error_c::handle_function_invocation() CALLED!\n");
       
   138 debug_c::print(fcall);
       
   139 
       
   140 
   137 	if (generic_function_call_t::POU_FB       == fcall_data.POU_type)  POU_str = "FB";
   141 	if (generic_function_call_t::POU_FB       == fcall_data.POU_type)  POU_str = "FB";
   138 	if (generic_function_call_t::POU_function == fcall_data.POU_type)  POU_str = "function";
   142 	if (generic_function_call_t::POU_function == fcall_data.POU_type)  POU_str = "function";
   139 	if (NULL == POU_str) ERROR;
   143 	if (NULL == POU_str) ERROR;
   140 
   144 
   141 	if ((NULL != fcall_data.formal_operand_list) && (NULL != fcall_data.nonformal_operand_list)) 
   145 	if ((NULL != fcall_data.formal_operand_list) && (NULL != fcall_data.nonformal_operand_list)) 
   202 				}
   206 				}
   203 			}
   207 			}
   204 		}
   208 		}
   205 	}
   209 	}
   206 	if (NULL != fcall_data.nonformal_operand_list) {
   210 	if (NULL != fcall_data.nonformal_operand_list) {
       
   211 debug_c::print("print_datatypes_error_c::handle_function_invocation() CALLING  ---> fcall_data.nonformal_operand_list->accept(*this)!\n");
       
   212 debug_c::print_ast(fcall_data.nonformal_operand_list);
       
   213 debug_c::print("print_datatypes_error_c::handle_function_invocation() LIST_END\n");
   207 		fcall_data.nonformal_operand_list->accept(*this);
   214 		fcall_data.nonformal_operand_list->accept(*this);
       
   215 debug_c::print("print_datatypes_error_c::handle_function_invocation() RETURNED <--- fcall_data.nonformal_operand_list->accept(*this)!\n");
   208 		if (f_decl)
   216 		if (f_decl)
   209 			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
   217 			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
   210 		  		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
   218 		  		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
   211 
   219 
   212 				/* This handle_function_invocation() will be called to handle IL function calls, where the first parameter comes from the previous IL instruction.
   220 				/* This handle_function_invocation() will be called to handle IL function calls, where the first parameter comes from the previous IL instruction.
   567 /* B 1.4.2 - Multi-element variables */
   575 /* B 1.4.2 - Multi-element variables */
   568 /*************************************/
   576 /*************************************/
   569 /*  subscripted_variable '[' subscript_list ']' */
   577 /*  subscripted_variable '[' subscript_list ']' */
   570 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   578 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   571 void *print_datatypes_error_c::visit(array_variable_c *symbol) {
   579 void *print_datatypes_error_c::visit(array_variable_c *symbol) {
       
   580 	/* the subscripted variable may be a structure or another array variable, that must also be visisted! */
       
   581 	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
       
   582 	symbol->subscripted_variable->accept(*this); 
       
   583 	
   572 	if (symbol->candidate_datatypes.size() == 0)
   584 	if (symbol->candidate_datatypes.size() == 0)
   573 		STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope.");
   585 		STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope.");
   574 	
   586 	
   575 	/* recursively call the subscript list to print any errors in the expressions used in the subscript...*/
   587 	/* recursively call the subscript list to print any errors in the expressions used in the subscript...*/
   576 	symbol->subscript_list->accept(*this);
   588 	symbol->subscript_list->accept(*this);
   596  *           may be accessed as fields of a structured variable!
   608  *           may be accessed as fields of a structured variable!
   597  *           Code handling a structured_variable_c must take
   609  *           Code handling a structured_variable_c must take
   598  *           this into account!
   610  *           this into account!
   599  */
   611  */
   600 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   612 // 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) {
   613 void *print_datatypes_error_c::visit(structured_variable_c *symbol) {
       
   614 	/* the record variable may be another structure or even an array variable, that must also be visisted! */
       
   615 	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
       
   616 	symbol->record_variable->accept(*this);
       
   617 	
   606 	if (symbol->candidate_datatypes.size() == 0)
   618 	if (symbol->candidate_datatypes.size() == 0)
   607 		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured/FB variable.");
   619 		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured (or FB) variable, or non-existant field (variable) in structure (FB).");
   608 	return NULL;
   620 	return NULL;
   609 }
   621 }
   610 
   622 
   611 
   623 
   612 
   624