mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 05:13:04 +00:00
fix warnings for useless %printer/%destructor
The previous commit, which turns into a warning what used to be an
error:
%printer {} foo;
%%
exp: '0';
has two shortcomings: the warning is way too long (foo is reported
to be useless later), and besides, it also turns into a warning much
more serious errors:
%printer {} foo;
%%
exp: foo;
Reduce the amount to warnings in the first case, restore the error in
the second.
* src/symtab.h (status): Add a new inital state: undeclared.
* src/symtab.c (symbol_new): Initialize to undeclared.
(symbol_class_set): Simplify the logic of the code that neutralize
the "redeclared" warning after the "redefined" one.
(symbol_check_defined): "undeclared" is also an error.
* src/reader.c (grammar_current_rule_symbol_append): Symbols appearing
in a rule are "needed".
* src/symlist.c (symbol_list_destructor_set, symbol_list_printer_set):
An unknown symbol appearing in a %printer/%destructor is "used".
* src/reduce.c (nonterminals_reduce): Do not report as "useless" symbols
that are not used (e.g., those that for instance appeared only in a
%printer).
* tests/input.at (Undeclared symbols used for a printer or destructor):
Improve the cover the cases described above.
This commit is contained in:
39
src/symtab.c
39
src/symtab.c
@@ -85,7 +85,7 @@ symbol_new (uniqstr tag, location loc)
|
||||
|
||||
res->alias = NULL;
|
||||
res->class = unknown_sym;
|
||||
res->status = needed;
|
||||
res->status = undeclared;
|
||||
|
||||
if (nsyms == SYMBOL_NUMBER_MAXIMUM)
|
||||
fatal (_("too many symbols in input grammar (limit is %d)"),
|
||||
@@ -358,10 +358,12 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc)
|
||||
void
|
||||
symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
{
|
||||
bool warned = false;
|
||||
if (sym->class != unknown_sym && sym->class != class)
|
||||
{
|
||||
complain_at (loc, _("symbol %s redefined"), sym->tag);
|
||||
sym->status = needed;
|
||||
// Don't report both "redefined" and "redeclared".
|
||||
warned = true;
|
||||
}
|
||||
|
||||
if (class == nterm_sym && sym->class != nterm_sym)
|
||||
@@ -373,7 +375,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
|
||||
if (declaring)
|
||||
{
|
||||
if (sym->status == declared)
|
||||
if (sym->status == declared && !warned)
|
||||
warn_at (loc, _("symbol %s redeclared"), sym->tag);
|
||||
sym->status = declared;
|
||||
}
|
||||
@@ -421,18 +423,25 @@ symbol_check_defined (symbol *sym)
|
||||
{
|
||||
if (sym->class == unknown_sym)
|
||||
{
|
||||
if (sym->status == needed)
|
||||
complain_at
|
||||
(sym->location,
|
||||
_("symbol %s is used, but is not defined as a token and has no"
|
||||
" rules"),
|
||||
sym->tag);
|
||||
else
|
||||
warn_at
|
||||
(sym->location,
|
||||
_("symbol %s is used, but is not defined as a token and has no"
|
||||
" rules"),
|
||||
sym->tag);
|
||||
switch (sym->status)
|
||||
{
|
||||
case used:
|
||||
warn_at (sym->location,
|
||||
_("symbol %s is used, but is not defined as a token"
|
||||
" and has no rules"),
|
||||
sym->tag);
|
||||
break;
|
||||
case undeclared:
|
||||
case needed:
|
||||
complain_at (sym->location,
|
||||
_("symbol %s is used, but is not defined as a token"
|
||||
" and has no rules"),
|
||||
sym->tag);
|
||||
break;
|
||||
case declared:
|
||||
/* If declared, then sym->class != unknown_sym. */
|
||||
assert (0);
|
||||
}
|
||||
|
||||
sym->class = nterm_sym;
|
||||
sym->number = nvars++;
|
||||
|
||||
Reference in New Issue
Block a user