# HG changeset patch # User Mario de Sousa # Date 1328615729 0 # Node ID 5792016eedd88c8c0544ab2415e11b998ce977b6 # Parent d7a6221f64d760ffdfa061ad1c24dc4905de694e More detailed error messages for FB invocations in ST. diff -r d7a6221f64d7 -r 5792016eedd8 stage3/fill_candidate_datatypes.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; diff -r d7a6221f64d7 -r 5792016eedd8 stage3/print_datatypes_error.cc --- 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); } } }