Disable unset/unused mid-rule value warnings by default, and recognize

--warnings=midrule-values to enable them.  Discussed starting at
<http://lists.gnu.org/archive/html/help-bison/2006-10/msg00030.html>.
* NEWS (2.3a+): Mention.
* src/getargs.c, src/getargs.h (warnings_args, warnings_types, enum
warnings): Add entry for midrule-values subargument.
* src/reader.c (symbol_should_be_used): Don't return true just because
the value is a set/used mid-rule value unless
--warnings=midrule-values was specified.
* tests/input.at (Unused values, Unused values before symbol
declarations): Run tests with and without --warnings=midrule-values.

* src/reader.c (check_and_convert_grammar): Use symbol_list_free rather
than LIST_FREE directly.
This commit is contained in:
Joel E. Denny
2006-11-01 06:09:40 +00:00
parent 89eb3c7653
commit 17bd8a736a
6 changed files with 81 additions and 32 deletions

View File

@@ -203,16 +203,18 @@ static const char * const warnings_args[] =
{
/* In a series of synonyms, present the most meaningful first, so
that argmatch_valid be more readable. */
"none - no warnings",
"yacc - incompatibilities with POSIX YACC",
"all - all of the above",
"error - warnings are errors",
"none - no warnings",
"midrule-values - unset or unused midrule values",
"yacc - incompatibilities with POSIX YACC",
"all - all of the above",
"error - warnings are errors",
0
};
static const int warnings_types[] =
{
warnings_none,
warnings_midrule_values,
warnings_yacc,
warnings_all,
warnings_error

View File

@@ -111,7 +111,8 @@ enum warnings
{
warnings_none = 0, /**< Issue no warnings. */
warnings_error = 1 << 0, /**< Warnings are treated as errors. */
warnings_yacc = 1 << 1, /**< POSIXME. */
warnings_midrule_values = 1 << 1, /**< Unset or unused midrule values. */
warnings_yacc = 1 << 2, /**< POSIXME. */
warnings_all = ~warnings_error /**< All above warnings. */
};
/** What warnings are issued. */

View File

@@ -243,19 +243,24 @@ grammar_current_rule_begin (symbol *lhs, location loc)
/*----------------------------------------------------------------------.
| A symbol should be used if it has a destructor, or if it is a |
| mid-rule symbol (i.e., the generated LHS replacing a mid-rule |
| action) that was assigned to, as in "exp: { $$ = 1; } { $$ = $1; }". |
| A symbol should be used if either: |
| 1. It has a destructor. |
| 2. --warnings=midrule-values and the symbol is a mid-rule symbol |
| (i.e., the generated LHS replacing a mid-rule action) that was |
| assigned to or used, as in "exp: { $$ = 1; } { $$ = $1; }". |
`----------------------------------------------------------------------*/
static bool
symbol_should_be_used (symbol_list const *s)
{
return (symbol_destructor_get (s->content.sym)
|| (s->midrule && s->midrule->used)
|| (s->midrule_parent_rule
&& symbol_list_n_get (s->midrule_parent_rule,
s->midrule_parent_rhs_index)->used));
if (symbol_destructor_get (s->content.sym))
return true;
if (warnings_flag & warnings_midrule_values)
return ((s->midrule && s->midrule->used)
|| (s->midrule_parent_rule
&& symbol_list_n_get (s->midrule_parent_rule,
s->midrule_parent_rhs_index)->used));
return false;
}
/*----------------------------------------------------------------.
@@ -666,5 +671,5 @@ check_and_convert_grammar (void)
packgram ();
/* The grammar as a symbol_list is no longer needed. */
LIST_FREE (symbol_list, grammar);
symbol_list_free (grammar);
}