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.
This commit is contained in:
Alex Rozenman
2009-09-05 13:16:45 +03:00
parent f4c75eaf2a
commit 61bc57e533
3 changed files with 118 additions and 20 deletions

View File

@@ -1,3 +1,12 @@
2009-09-05 Alex Rozenman <rozenman@gmail.com>
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-04 Akim Demaille <demaille@gostai.com>
Adjust synclines in src/parse-gram.[ch].

View File

@@ -376,14 +376,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;
@@ -409,8 +409,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;
@@ -431,7 +431,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;
@@ -492,7 +492,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;
@@ -521,7 +521,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
continue;
cp_end = p;
exact_mode = true;
explicit_bracketing = true;
}
else
{
@@ -537,7 +537,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. */
@@ -552,13 +552,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);
}
}
@@ -574,7 +574,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. */
@@ -592,13 +592,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;
@@ -608,7 +620,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);
}
{
@@ -621,7 +633,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;
}

View File

@@ -255,14 +255,14 @@ exp:
]])
AT_BISON_CHECK([-o test.c test.y], 1, [],
[[test.y:50.51-60: invalid reference: `$<ival>lo9', symbol not found
[[test.y:50.51-60: unresolved reference: `$<ival>lo9'
test.y:51.51-60: warning: misleading reference: `$<ival>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($<aa>sym.field); }
|
sym_a sym_b
{ func($[sym.field]); }
|
sym_a sym_b
{ func($<aa>[sym.field]); }
|
sym_a sym_b
{ func($sym); }
|
sym_a sym_b
{ func($<aa>sym); }
|
sym_a sym_b
{ func($[sym]); }
sym_a sym_b
{ func($<aa>[sym]); }
;
stat1:
sym_a sym_b
{ func($sym-field); }
|
sym_a sym_b
{ func($<aa>sym-field); }
|
sym_a sym_b
{ func($[sym-field]); }
|
sym_a sym_b
{ func($<aa>[sym-field]); }
|
sym_a sym_b
{ func($sym); }
|
sym_a sym_b
{ func($<aa>sym); }
|
sym_a sym_b
{ func($[sym]); }
sym_a sym_b
{ func($<aa>[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: `$<aa>sym'
test.y:19.8-19: unresolved reference: `$[sym.field]'
test.y:22.8-23: unresolved reference: `$<aa>[sym.field]'
test.y:25.8-11: unresolved reference: `$sym'
test.y:28.8-15: unresolved reference: `$<aa>sym'
test.y:31.8-13: unresolved reference: `$[sym]'
test.y:33.8-17: unresolved reference: `$<aa>[sym]'
test.y:37.8-11: unresolved reference: `$sym'
test.y:40.8-15: unresolved reference: `$<aa>sym'
test.y:43.8-19: unresolved reference: `$[sym-field]'
test.y:46.8-23: unresolved reference: `$<aa>[sym-field]'
test.y:49.8-11: unresolved reference: `$sym'
test.y:52.8-15: unresolved reference: `$<aa>sym'
test.y:55.8-13: unresolved reference: `$[sym]'
test.y:57.8-17: unresolved reference: `$<aa>[sym]'
]])
AT_CLEANUP