From 14e568d74425e5111429e05fb1036f043b59bed4 Mon Sep 17 00:00:00 2001 From: Alex Rozenman Date: Sat, 5 Sep 2009 13:16:45 +0300 Subject: [PATCH] Use "Unresolved reference" error message when no symbols were found in a symbolic reference resolution. Remove .expr and -expr from the shown reference when the reference is unresolved. * src/scan-code.l: Change the error message, adjust location columns, rename variable "exact_mode" to "explicit_bracketing". * tests/named-ref.at: Adjust existing tests and add a new one. --- ChangeLog | 9 +++++ src/scan-code.l | 44 ++++++++++++++--------- tests/named-refs.at | 85 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 118 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70cebee3..f7b0ded9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-09-05 Alex Rozenman + + Use "Unresolved reference" error message when no symbols were found + in a symbolic reference resolution. Remove .expr and -expr from + the shown reference when the reference is unresolved. + * src/scan-code.l: Change the error message, adjust location columns, + rename variable "exact_mode" to "explicit_bracketing". + * tests/named-ref.at: Adjust existing tests and add a new one. + 2009-09-03 Akim Demaille * NEWS (2.4.2): Add "Internationalization" item. diff --git a/src/scan-code.l b/src/scan-code.l index fc35513a..196fa807 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -375,14 +375,14 @@ find_prefix_end (const char *prefix, char *begin, char *end) static variant * variant_add (uniqstr id, location id_loc, unsigned symbol_index, - char *cp, char *cp_end, bool exact_mode) + char *cp, char *cp_end, bool explicit_bracketing) { char *prefix_end; prefix_end = find_prefix_end (id, cp, cp_end); if (prefix_end && (prefix_end == cp_end || - (!exact_mode && is_dot_or_dash (*prefix_end)))) + (!explicit_bracketing && is_dot_or_dash (*prefix_end)))) { variant *r = variant_table_grow (); r->symbol_index = symbol_index; @@ -408,8 +408,8 @@ get_at_spec(unsigned symbol_index) } static void -show_sub_messages (const char* cp, bool exact_mode, int midrule_rhs_index, - char dollar_or_at, bool is_warning) +show_sub_messages (const char* cp, bool explicit_bracketing, + int midrule_rhs_index, char dollar_or_at, bool is_warning) { unsigned i; @@ -430,7 +430,7 @@ show_sub_messages (const char* cp, bool exact_mode, int midrule_rhs_index, else { static struct obstack msg_buf; - const char *tail = exact_mode ? "" : + const char *tail = explicit_bracketing ? "" : cp + strlen (var->id); const char *id = var->hidden_by ? var->hidden_by->id : var->id; @@ -491,7 +491,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, { symbol_list *l; char *cp_end; - bool exact_mode; + bool explicit_bracketing; unsigned i; unsigned valid_variants = 0; unsigned valid_variant_index = 0; @@ -520,7 +520,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, continue; cp_end = p; - exact_mode = true; + explicit_bracketing = true; } else { @@ -536,7 +536,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, continue; cp_end = p; - exact_mode = false; + explicit_bracketing = false; } /* Add all relevant variants. */ @@ -551,13 +551,13 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, continue; var = variant_add (l->content.sym->tag, l->sym_loc, - symbol_index, cp, cp_end, exact_mode); + symbol_index, cp, cp_end, explicit_bracketing); if (var && l->named_ref) var->hidden_by = l->named_ref; if (l->named_ref) variant_add (l->named_ref->id, l->named_ref->loc, - symbol_index, cp, cp_end, exact_mode); + symbol_index, cp, cp_end, explicit_bracketing); } } @@ -573,7 +573,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE; /* Check correct bracketing. */ - if (!exact_mode && contains_dot_or_dash (var->id)) + if (!explicit_bracketing && contains_dot_or_dash (var->id)) var->err |= VARIANT_BAD_BRACKETING; /* Check using of hidden symbols. */ @@ -591,13 +591,25 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, { case 0: if (variant_count == 0) - complain_at (text_loc, _("invalid reference: %s, symbol not found"), - quote (text)); + { + if (explicit_bracketing || !ref_tail_fields) + complain_at (text_loc, _("unresolved reference: %s"), + quote(text)); + else + { + unsigned len = ref_tail_fields - text; + char *str = strndup (text, len); + text_loc.end.column = text_loc.start.column + len; + complain_at (text_loc, _("unresolved reference: %s"), + quote (str)); + free (str); + } + } else { complain_at (text_loc, _("invalid reference: %s"), quote (text)); - show_sub_messages (cp, exact_mode, midrule_rhs_index, + show_sub_messages (cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, false); } return INVALID_REF; @@ -607,7 +619,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, { warn_at (text_loc, _("misleading reference: %s"), quote (text)); - show_sub_messages (cp, exact_mode, midrule_rhs_index, + show_sub_messages (cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, true); } { @@ -620,7 +632,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, default: complain_at (text_loc, _("ambiguous reference: %s"), quote (text)); - show_sub_messages (cp, exact_mode, midrule_rhs_index, + show_sub_messages (cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, false); return INVALID_REF; } diff --git a/tests/named-refs.at b/tests/named-refs.at index b542dc4b..174a4f2f 100644 --- a/tests/named-refs.at +++ b/tests/named-refs.at @@ -255,14 +255,14 @@ exp: ]]) AT_BISON_CHECK([-o test.c test.y], 1, [], -[[test.y:50.51-60: invalid reference: `$lo9', symbol not found +[[test.y:50.51-60: unresolved reference: `$lo9' test.y:51.51-60: warning: misleading reference: `$exp' test.y:42.1-3: warning: refers to: $exp at $$ test.y:51.7: warning: possibly meant: $x, hiding $exp at $1 test.y:51.41: warning: possibly meant: $r, hiding $exp at $4 test.y:52.51-52: $l of `exp' has no declared type -test.y:55.46-49: invalid reference: `$r12', symbol not found -test.y:56.29-33: invalid reference: `$expo', symbol not found +test.y:55.46-49: unresolved reference: `$r12' +test.y:56.29-33: unresolved reference: `$expo' ]]) AT_CLEANUP @@ -353,7 +353,7 @@ factor: '(' expr ')' { $$ = $2; } ; ]]) AT_BISON_CHECK([-o test.c test.y], 1, [], -[[test.y:24.36-41: invalid reference: `$cond1', symbol not found +[[test.y:24.36-41: unresolved reference: `$cond1' test.y:26.43-53: invalid reference: `$stmt.field' test.y:25.35-38: possibly meant: $then.field, hiding $stmt.field at $4 test.y:28.43-52: invalid reference: `$stmt.list' @@ -454,3 +454,80 @@ AT_BISON_CHECK([-o test.c test.y], 1, [], [[test.y:11.9: unexpected identifier in bracketed name: `s' ]]) AT_CLEANUP + +####################################################################### + +AT_SETUP([Unresolved references]) +AT_DATA_GRAMMAR([test.y], +[[ +%% +stat: +sym_a sym_b +{ func($sym.field); } +| +sym_a sym_b +{ func($sym.field); } +| +sym_a sym_b +{ func($[sym.field]); } +| +sym_a sym_b +{ func($[sym.field]); } +| +sym_a sym_b +{ func($sym); } +| +sym_a sym_b +{ func($sym); } +| +sym_a sym_b +{ func($[sym]); } +sym_a sym_b +{ func($[sym]); } +; +stat1: +sym_a sym_b +{ func($sym-field); } +| +sym_a sym_b +{ func($sym-field); } +| +sym_a sym_b +{ func($[sym-field]); } +| +sym_a sym_b +{ func($[sym-field]); } +| +sym_a sym_b +{ func($sym); } +| +sym_a sym_b +{ func($sym); } +| +sym_a sym_b +{ func($[sym]); } +sym_a sym_b +{ func($[sym]); } +; +sym_a : 'a'; +sym_b : 'b'; +]]) +AT_BISON_CHECK([-o test.c test.y], 1, [], +[[test.y:13.8-11: unresolved reference: `$sym' +test.y:16.8-15: unresolved reference: `$sym' +test.y:19.8-19: unresolved reference: `$[sym.field]' +test.y:22.8-23: unresolved reference: `$[sym.field]' +test.y:25.8-11: unresolved reference: `$sym' +test.y:28.8-15: unresolved reference: `$sym' +test.y:31.8-13: unresolved reference: `$[sym]' +test.y:33.8-17: unresolved reference: `$[sym]' +test.y:37.8-11: unresolved reference: `$sym' +test.y:40.8-15: unresolved reference: `$sym' +test.y:43.8-19: unresolved reference: `$[sym-field]' +test.y:46.8-23: unresolved reference: `$[sym-field]' +test.y:49.8-11: unresolved reference: `$sym' +test.y:52.8-15: unresolved reference: `$sym' +test.y:55.8-13: unresolved reference: `$[sym]' +test.y:57.8-17: unresolved reference: `$[sym]' +]]) +AT_CLEANUP -- 2.45.2