-Wempty-rule: diagnose empty rules without %empty

* src/complain.h, src/complain.c (warning_empty_rule, Wempty_rule):
New warning category.
(warnings_args, warnings_types): Adjust.
* src/reader.c (grammar_rule_check): Check the empty rules are
flagged by %empty.
* tests/actions.at (Implicitly empty rule): New.
* tests/existing.at: Add expected warnings.
This commit is contained in:
Akim Demaille
2013-02-09 18:26:38 +01:00
parent 684083f065
commit f68a49ed49
6 changed files with 107 additions and 5 deletions

View File

@@ -63,6 +63,7 @@ static const char * const warnings_args[] =
"conflicts-sr",
"conflicts-rr",
"deprecated",
"empty-rule",
"precedence",
"other",
"all",
@@ -78,6 +79,7 @@ static const int warnings_types[] =
Wconflicts_sr,
Wconflicts_rr,
Wdeprecated,
Wempty_rule,
Wprecedence,
Wother,
Wall,

View File

@@ -35,6 +35,7 @@ typedef enum
warning_yacc, /**< POSIXME. */
warning_conflicts_sr, /**< S/R conflicts. */
warning_conflicts_rr, /**< R/R conflicts. */
warning_empty_rule, /**< Implicitly empty rules. */
warning_deprecated, /**< Obsolete constructs. */
warning_precedence, /**< Useless precedence and associativity. */
warning_other, /**< All other warnings. */
@@ -85,6 +86,7 @@ typedef enum
Wconflicts_sr = 1 << warning_conflicts_sr,
Wconflicts_rr = 1 << warning_conflicts_rr,
Wdeprecated = 1 << warning_deprecated,
Wempty_rule = 1 << warning_empty_rule,
Wprecedence = 1 << warning_precedence,
Wother = 1 << warning_other,

View File

@@ -327,6 +327,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\
`empty-rule' empty rules without %empty\n\
`precedence' useless precedence and associativity\n\
`other' all other warnings (enabled by default)\n\
`all' all the warnings\n\

View File

@@ -339,6 +339,12 @@ grammar_rule_check (const symbol_list *r)
complain (&r->percent_empty_loc, complaint,
_("%%empty on non-empty rule"));
/* Check that empty rule => %empty. */
if (!(r->next && r->next->content.sym)
&& !r->midrule_parent_rule
&& !r->percent_empty_loc.start.file)
complain (&r->location, Wempty_rule, _("empty rule without %%empty"));
/* See comments in grammar_current_rule_prec_set for how POSIX
mandates this complaint. It's only for identifiers, so skip
it for char literals and strings, which are always tokens. */