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:
Akim Demaille
2012-06-20 12:33:34 +02:00
parent 0d4b994cc2
commit 3b0b682fd6
6 changed files with 61 additions and 34 deletions

View File

@@ -51,11 +51,27 @@ typedef int symbol_number;
typedef struct symbol symbol;
/* Declaration status of a symbol.
First, it is "undeclared". Then, if "undeclared" and used in a
%printer/%destructor, it is "used". If not "declared" by used in a
rule, it is "needed". Finally, if declared (via a rule for
nonterminals, or %oken), it is "declared".
When status are checked at the end, "declared" symbols are fine,
"used" symbols trigger warnings, otherwise it's an error.
*/
typedef enum
{
needed, /**< found but not "defined". */
used, /**< used by %printer but not declared. */
declared, /**< defined with %type or %token. */
/** Used in the input file for an unknown reason (error). */
undeclared,
/** Used by %destructor/%printer but not defined (warning). */
used,
/** Used in the gramar (rules) but not defined (error). */
needed,
/** Defined with %type or %token (good). */
declared,
} status;
/* When extending this structure, be sure to complete