More detailed error messages for FB invocations in ST.
authorMario de Sousa <msousa@fe.up.pt>
Tue, 07 Feb 2012 11:55:29 +0000
changeset 431 5792016eedd8
parent 430 d7a6221f64d7
child 432 9c5ad4be30fd
More detailed error messages for FB invocations in ST.
stage3/fill_candidate_datatypes.cc
stage3/print_datatypes_error.cc
--- a/stage3/fill_candidate_datatypes.cc	Mon Feb 06 18:32:11 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Tue Feb 07 11:55:29 2012 +0000
@@ -1720,7 +1720,7 @@
 	 * spurious error messages.
 	 * Even if the parameters to the function call are invalid, doing this is still safe, as the 
 	 * expressions inside the function call will themselves have erros and will  guarantee that 
-	 * compilation is aborted in stage3.
+	 * compilation is aborted in stage3 (in print_datatypes_error_c).
 	 */
 	if (function_symtable.multiplicity(symbol->function_name) == 1) {
 		f_decl = function_symtable.get_value(lower);
@@ -1805,8 +1805,11 @@
 		compatible = match_nonformal_call(symbol, fb_decl);
 	}
 
-	if (compatible) 
-		symbol->called_fb_declaration = fb_decl;
+	/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that
+	 * we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe,
+	 * as the compiler will never reach the compilation stage!
+	 */
+	symbol->called_fb_declaration = fb_decl;
 
 	if (debug) std::cout << "FB [] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
 	return NULL;
--- a/stage3/print_datatypes_error.cc	Mon Feb 06 18:32:11 2012 +0000
+++ b/stage3/print_datatypes_error.cc	Tue Feb 07 11:55:29 2012 +0000
@@ -1034,7 +1034,7 @@
 		ERROR;
 
 	symbol_c *f_decl = symbol->called_function_declaration;
-	if (NULL == symbol->called_function_declaration) {
+	if (NULL == f_decl) {
 		STAGE3_ERROR(0, symbol, symbol, "Unable to resolve which overloaded function '%s' is being invoked.", ((identifier_c *)symbol->function_name)->value);
 		/* we now try to find any function declaration with the same name, just so we can provide some relevant error messages */
 		function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
@@ -1119,13 +1119,26 @@
 	if ((NULL != symbol->formal_param_list) && (NULL != symbol->nonformal_param_list)) 
 		ERROR;
 
+	symbol_c *f_decl = symbol->called_fb_declaration;
+	if (NULL == f_decl) {
+		/* Due to the way the syntax analysis is buit (i.e. stage 2), this should never occur.
+		 * I.e., a FB invocation using an undefined FB variable is not possible in the current implementation of stage 2.
+		 */
+		ERROR;
+// 		STAGE3_ERROR(0, symbol, symbol, "Undefined FB variable '%s'", ((identifier_c *)symbol->fb_name)->value);
+	}
+
 	if (NULL != symbol->formal_param_list) {
 		symbol->formal_param_list->accept(*this);
+		function_param_iterator_c fp_iterator(f_decl);
 		while ((param_name = fcp_iterator.next_f()) != NULL) {
 			param_value = fcp_iterator.get_current_value();
-			if (NULL == param_value->datatype) {
+			/* Find the corresponding parameter in function declaration */
+			if (NULL == fp_iterator.search(param_name)) {
+				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' when invoking FB '%s'", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->fb_name)->value);		  
+			} else if (NULL == param_value->datatype) {
 				function_invocation_error = true;
-				STAGE3_ERROR(0, symbol, symbol, "Invalid parameter '%s' in FB invocation: %s", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->fb_name)->value);
+				STAGE3_ERROR(0, symbol, symbol, "Data type incompatibility between parameter '%s' and value being passed, when invoking FB '%s'", ((identifier_c *)param_name)->value, ((identifier_c *)symbol->fb_name)->value);
 			}
 		}
 	}