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;
}
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;
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;
{
symbol_list *l;
char *cp_end;
- bool exact_mode;
+ bool explicit_bracketing;
unsigned i;
unsigned valid_variants = 0;
unsigned valid_variant_index = 0;
continue;
cp_end = p;
- exact_mode = true;
+ explicit_bracketing = true;
}
else
{
continue;
cp_end = p;
- exact_mode = false;
+ explicit_bracketing = false;
}
/* Add all relevant variants. */
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);
}
}
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. */
{
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;
{
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);
}
{
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;
}
]])
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
;
]])
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'
[[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