warnings: introduce -Wprecedence

The new warning category "precedence" flags useless precedence and
associativity.  -Wprecedence can now be used, it is disabled by default.
The warnings about precedence and associativity are grouped into one, and
the testsuite was corrected accordingly.

* src/complain.h (warnings): Introduce "precedence".
* src/complain.c (warnings_print_categories): Adjust.
* src/getargs.c (warnings_args, warning_types): Likewise.
* src/symtab.h, src/symtab.c (print_associativity_warnings): Remove.
* src/symtab.h (register_assoc): Correct arguments.
* src/symtab.c (print_precedence_warnings): Print both warnings together.
* doc/bison.texi (Bison options): Document the warnings and provide an
example.
* tests/conflicts.at, tests/existing.at, tests/local.at,
* tests/regression.at: Adapt the testsuite for the new category
(-Wprecedence instead of -Wother where appropriate).
This commit is contained in:
Valentin Tolmer
2013-01-30 11:30:15 +01:00
committed by Akim Demaille
parent df1ca1b0de
commit cc2235ace2
12 changed files with 331 additions and 232 deletions

View File

@@ -9716,6 +9716,67 @@ no effect on the conflict report.
Deprecated constructs whose support will be removed in future versions of
Bison.
@item precedence
Useless precedence and associativity directives. Disabled by default.
Consider for instance the following grammar:
@example
@group
%nonassoc "="
%left "+"
%left "*"
%precedence "("
@end group
%%
@group
stmt:
exp
| "var" "=" exp
;
@end group
@group
exp:
exp "+" exp
| exp "*" "num"
| "(" exp ")"
| "num"
;
@end group
@end example
Bison reports:
@c cannot leave the location and the [-Wprecedence] for lack of
@c width in PDF.
@example
@group
warning: useless precedence and associativity for "="
%nonassoc "="
^^^
@end group
@group
warning: useless associativity for "*", use %precedence
%left "*"
^^^
@end group
@group
warning: useless precedence for "("
%precedence "("
^^^
@end group
@end example
One would get the exact same parser with the following directives instead:
@example
@group
%left "+"
%precedence "*"
@end group
@end example
@item other
All warnings not categorized above. These warnings are enabled by default.