mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 21:03:04 +00:00
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:
committed by
Akim Demaille
parent
df1ca1b0de
commit
cc2235ace2
@@ -50,6 +50,7 @@ warnings_print_categories (warnings warn_flags)
|
||||
"conflicts-sr",
|
||||
"conflicts-rr",
|
||||
"deprecated",
|
||||
"precedence",
|
||||
"other"
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ typedef enum
|
||||
Wconflicts_sr = 1 << 2, /**< S/R conflicts. */
|
||||
Wconflicts_rr = 1 << 3, /**< R/R conflicts. */
|
||||
Wdeprecated = 1 << 4, /**< Obsolete constructs. */
|
||||
Wother = 1 << 5, /**< All other warnings. */
|
||||
Wprecedence = 1 << 5, /**< Useless precedence and associativity. */
|
||||
|
||||
Wother = 1 << 6, /**< All other warnings. */
|
||||
|
||||
Werror = 1 << 10, /** This bit is no longer used. */
|
||||
|
||||
|
||||
@@ -252,6 +252,7 @@ static const char * const warnings_args[] =
|
||||
"conflicts-sr - S/R conflicts",
|
||||
"conflicts-rr - R/R conflicts",
|
||||
"deprecated - obsolete constructs",
|
||||
"precedence - useless precedence and associativity",
|
||||
"other - all other warnings",
|
||||
"all - all of the above",
|
||||
"error - warnings are errors",
|
||||
@@ -266,6 +267,7 @@ static const int warnings_types[] =
|
||||
Wconflicts_sr,
|
||||
Wconflicts_rr,
|
||||
Wdeprecated,
|
||||
Wprecedence,
|
||||
Wother,
|
||||
Wall,
|
||||
Werror
|
||||
@@ -381,6 +383,7 @@ Warning categories include:\n\
|
||||
`conflicts-sr' S/R conflicts (enabled by default)\n\
|
||||
`conflicts-rr' R/R conflicts (enabled by default)\n\
|
||||
`deprecated' obsolete constructs\n\
|
||||
`precedence' useless precedence and associativity\n\
|
||||
`other' all other warnings (enabled by default)\n\
|
||||
`all' all the warnings\n\
|
||||
`no-CATEGORY' turn off warnings in CATEGORY\n\
|
||||
|
||||
@@ -146,8 +146,6 @@ main (int argc, char *argv[])
|
||||
|
||||
print_precedence_warnings ();
|
||||
|
||||
print_assoc_warnings ();
|
||||
|
||||
/* Output file names. */
|
||||
compute_output_file_names ();
|
||||
|
||||
|
||||
53
src/symtab.c
53
src/symtab.c
@@ -1057,29 +1057,6 @@ register_precedence (graphid first, graphid snd)
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------.
|
||||
| Print a warning for unused precedence relations. |
|
||||
`--------------------------------------------------*/
|
||||
|
||||
void
|
||||
print_precedence_warnings (void)
|
||||
{
|
||||
int i;
|
||||
if (!prec_nodes)
|
||||
init_prec_nodes ();
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
{
|
||||
symbol *s = symbols[i];
|
||||
if (s
|
||||
&& s->prec != 0
|
||||
&& !prec_nodes[i]->pred
|
||||
&& !prec_nodes[i]->succ
|
||||
&& s->assoc == precedence_assoc)
|
||||
complain (&s->location, Wother,
|
||||
_("useless precedence for %s"), s->tag);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------.
|
||||
| Initialize association tracking table. |
|
||||
`---------------------------------------*/
|
||||
@@ -1119,21 +1096,35 @@ register_assoc (graphid i, graphid j)
|
||||
used_assoc[j] = true;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------.
|
||||
| Print a warning for each unused symbol associativity. |
|
||||
`------------------------------------------------------*/
|
||||
/*--------------------------------------------------.
|
||||
| Print a warning for unused precedence relations. |
|
||||
`--------------------------------------------------*/
|
||||
|
||||
void
|
||||
print_assoc_warnings (void)
|
||||
print_precedence_warnings (void)
|
||||
{
|
||||
graphid i;
|
||||
int i;
|
||||
if (!prec_nodes)
|
||||
init_prec_nodes ();
|
||||
if (!used_assoc)
|
||||
init_assoc ();
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
{
|
||||
symbol *s = symbols[i];
|
||||
if (is_assoc_useless (s))
|
||||
complain (&s->location, Wother,
|
||||
_("useless associativity for %s"), s->tag);
|
||||
if (s
|
||||
&& s->prec != 0
|
||||
&& !prec_nodes[i]->pred
|
||||
&& !prec_nodes[i]->succ)
|
||||
{
|
||||
if (is_assoc_useless (s))
|
||||
complain (&s->location, Wprecedence,
|
||||
_("useless precedence and associativity for %s"), s->tag);
|
||||
else if (s->assoc == precedence_assoc)
|
||||
complain (&s->location, Wprecedence,
|
||||
_("useless precedence for %s"), s->tag);
|
||||
}
|
||||
else if (is_assoc_useless (s))
|
||||
complain (&s->location, Wprecedence,
|
||||
_("useless associativity for %s, use %%precedence"), s->tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,8 @@ struct symgraph
|
||||
|
||||
void register_precedence (graphid first, graphid snd);
|
||||
|
||||
/** Print a warning for each symbol whose precedence is useless. */
|
||||
/** Print a warning for each symbol whose precedence and/or associativity
|
||||
* is useless. */
|
||||
|
||||
void print_precedence_warnings (void);
|
||||
|
||||
@@ -274,9 +275,7 @@ void print_precedence_warnings (void);
|
||||
| Symbol associativity |
|
||||
`----------------------*/
|
||||
|
||||
void register_assoc (int i, int j);
|
||||
|
||||
void print_assoc_warnings (void);
|
||||
void register_assoc (graphid i, graphid j);
|
||||
|
||||
/*-----------------.
|
||||
| Semantic types. |
|
||||
|
||||
Reference in New Issue
Block a user