diff options
author | Victor Santet <victor.santet@epita.fr> | 2012-06-19 16:14:55 +0200 |
---|---|---|
committer | Akim Demaille <akim@lrde.epita.fr> | 2012-06-20 10:30:26 +0200 |
commit | b921d92fcbdb2c19fe2c6158e9a5181d451b976a (patch) | |
tree | 472f764fe75cb2a1f0dc10cdecba2f8081e45e0c /src/symtab.c | |
parent | dda2c1adbab70a9e7ecaf3f83b3419fbd20fb321 (diff) | |
download | bison-b921d92fcbdb2c19fe2c6158e9a5181d451b976a.tar.gz |
warnings: used but undeclared symbols are warnings
We used to raise an error if a symbol appears only in a %printer or
%destructor. Make it a warning.
* src/symtab.h (status): New enum.
(symbol): Replace the binary "declared" with the three-state "status".
Adjust dependencies.
* src/symtab.c (symbol_check_defined): Needed symbols are an error,
whereas "used" are simply warnings.
* src/symlist.c (symbol_list_destructor_set, symbol_list_printer): Set
symbol status to 'used' when associated to destructors or printers.
* input.at (Undeclared symbols used for a printer or destructor): New.
Diffstat (limited to 'src/symtab.c')
-rw-r--r-- | src/symtab.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/symtab.c b/src/symtab.c index d25b9368..719cb9fd 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -85,7 +85,7 @@ symbol_new (uniqstr tag, location loc) res->alias = NULL; res->class = unknown_sym; - res->declared = false; + res->status = needed; if (nsyms == SYMBOL_NUMBER_MAXIMUM) fatal (_("too many symbols in input grammar (limit is %d)"), @@ -361,7 +361,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) if (sym->class != unknown_sym && sym->class != class) { complain_at (loc, _("symbol %s redefined"), sym->tag); - sym->declared = false; + sym->status = needed; } if (class == nterm_sym && sym->class != nterm_sym) @@ -373,9 +373,9 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) if (declaring) { - if (sym->declared) + if (sym->status == declared) warn_at (loc, _("symbol %s redeclared"), sym->tag); - sym->declared = true; + sym->status = declared; } } @@ -421,10 +421,19 @@ symbol_check_defined (symbol *sym) { if (sym->class == unknown_sym) { - complain_at - (sym->location, - _("symbol %s is used, but is not defined as a token and has no rules"), - sym->tag); + 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); + sym->class = nterm_sym; sym->number = nvars++; } |