mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
diagnostics: factor and enhance messages about duplicate rule directives
When reporting a duplicate directive on a rule, point to its first
occurrence:
one.y:11.10-15: error: only one %empty allowed per rule
%empty {} %empty
^^^^^^
one.y:11.3-8: previous declaration
%empty {} %empty
^^^^^^
And consistently discard the second one.
* src/complain.h, src/complain.c (duplicate_directive): New.
* src/reader.c: Use it where appropriate.
* src/symlist.h, src/symlist.c (symbol_list): Add a dprec_location member.
* tests/actions.at: Adjust expected output.
This commit is contained in:
@@ -365,3 +365,13 @@ deprecated_directive (location const *loc, char const *old, char const *upd)
|
||||
_("deprecated directive: %s, use %s"),
|
||||
quote (old), quote_n (1, upd));
|
||||
}
|
||||
|
||||
void
|
||||
duplicate_directive (char const *directive,
|
||||
location first, location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
complain (&second, complaint, _("only one %s allowed per rule"), directive);
|
||||
i += SUB_INDENT;
|
||||
complain_indent (&first, complaint, &i, _("previous declaration"));
|
||||
}
|
||||
|
||||
@@ -123,6 +123,10 @@ void complain_indent (location const *loc, warnings flags, unsigned *indent,
|
||||
void deprecated_directive (location const *loc,
|
||||
char const *obsolete, char const *updated);
|
||||
|
||||
/** Report a repeated directive for a rule. */
|
||||
void duplicate_directive (char const *directive,
|
||||
location first, location second);
|
||||
|
||||
/** Warnings treated as errors shouldn't stop the execution as regular errors
|
||||
should (because due to their nature, it is safe to go on). Thus, there are
|
||||
three possible execution statuses. */
|
||||
|
||||
28
src/reader.c
28
src/reader.c
@@ -442,8 +442,10 @@ grammar_current_rule_prec_set (symbol *precsym, location loc)
|
||||
token. */
|
||||
symbol_class_set (precsym, token_sym, loc, false);
|
||||
if (current_rule->ruleprec)
|
||||
complain (&loc, complaint, _("only one %s allowed per rule"), "%prec");
|
||||
current_rule->ruleprec = precsym;
|
||||
duplicate_directive ("%prec",
|
||||
current_rule->ruleprec->location, loc);
|
||||
else
|
||||
current_rule->ruleprec = precsym;
|
||||
}
|
||||
|
||||
/* Set %empty for the current rule. */
|
||||
@@ -456,7 +458,8 @@ grammar_current_rule_empty_set (location loc)
|
||||
if (warning_is_unset (Wempty_rule))
|
||||
warning_argmatch ("empty-rule", 0, 0);
|
||||
if (current_rule->percent_empty_loc.start.file)
|
||||
complain (&loc, complaint, _("only one %s allowed per rule"), "%empty");
|
||||
duplicate_directive ("%empty",
|
||||
current_rule->percent_empty_loc, loc);
|
||||
else
|
||||
current_rule->percent_empty_loc = loc;
|
||||
}
|
||||
@@ -473,8 +476,13 @@ grammar_current_rule_dprec_set (int dprec, location loc)
|
||||
complain (&loc, complaint, _("%s must be followed by positive number"),
|
||||
"%dprec");
|
||||
else if (current_rule->dprec != 0)
|
||||
complain (&loc, complaint, _("only one %s allowed per rule"), "%dprec");
|
||||
current_rule->dprec = dprec;
|
||||
duplicate_directive ("%dprec",
|
||||
current_rule->dprec_location, loc);
|
||||
else
|
||||
{
|
||||
current_rule->dprec = dprec;
|
||||
current_rule->dprec_location = loc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Attach a merge function NAME with argument type TYPE to current
|
||||
@@ -487,9 +495,13 @@ grammar_current_rule_merge_set (uniqstr name, location loc)
|
||||
complain (&loc, Wother, _("%s affects only GLR parsers"),
|
||||
"%merge");
|
||||
if (current_rule->merger != 0)
|
||||
complain (&loc, complaint, _("only one %s allowed per rule"), "%merge");
|
||||
current_rule->merger = get_merge_function (name);
|
||||
current_rule->merger_declaration_location = loc;
|
||||
duplicate_directive ("%merge",
|
||||
current_rule->merger_declaration_location, loc);
|
||||
else
|
||||
{
|
||||
current_rule->merger = get_merge_function (name);
|
||||
current_rule->merger_declaration_location = loc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Attach SYM to the current rule. If needed, move the previous
|
||||
|
||||
@@ -47,7 +47,9 @@ symbol_list_sym_new (symbol *sym, location loc)
|
||||
res->percent_empty_loc = empty_location;
|
||||
code_props_none_init (&res->action_props);
|
||||
res->dprec = 0;
|
||||
res->dprec_location = empty_location;
|
||||
res->merger = 0;
|
||||
res->merger_declaration_location = empty_location;
|
||||
|
||||
res->next = NULL;
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ typedef struct symbol_list
|
||||
location percent_empty_loc;
|
||||
|
||||
int dprec;
|
||||
location dprec_location;
|
||||
int merger;
|
||||
location merger_declaration_location;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user