diagnostics: no longer pretty-print rules in error messages, carets suffice

* src/gram.c (grammar_rules_useless_report): Let -fcaret handle the
pretty-printing of the guilty rules.
(rule_print): Inline in its only use.
* tests/conflicts.at, tests/existing.at, tests/reduce.at,
* tests/regression.at: Adjust.
* NEWS: Document.
This commit is contained in:
Akim Demaille
2013-02-11 10:17:36 +01:00
parent 9a9130f26d
commit fec5f3c0cc
6 changed files with 50 additions and 80 deletions

23
NEWS
View File

@@ -58,6 +58,29 @@ GNU Bison NEWS
activated by default. The old format can still be used by invoking Bison
with -fno-caret (or -fnone).
Some error messages that reproduced excerpts of the grammar are now using
the caret information only. For instance on:
%%
exp: 'a' | 'a';
Bison 2.7 reports:
in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
in.y:2.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
Now bison reports:
in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
exp: 'a' | 'a';
^^^
and "bison -fno-caret" reports:
in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
*** Enhancements of the -Werror option
The -Werror=CATEGORY option is now recognized, and will treat specified

View File

@@ -125,13 +125,6 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level)
}
}
static void
rule_print (rule const *r, FILE *out)
{
fprintf (out, "%s:", r->lhs->tag);
rule_rhs_print (r, out);
}
void
ritem_print (FILE *out)
{
@@ -289,8 +282,8 @@ grammar_dump (FILE *out, const char *title)
rule_number r;
for (r = 0; r < nrules + nuseless_productions; r++)
{
fprintf (out, "%-5d ", r);
rule_print (&rules[r], out);
fprintf (out, "%-5d %s:", r, rules[r].lhs->tag);
rule_rhs_print (&rules[r], out);
fprintf (out, "\n");
}
}
@@ -300,24 +293,10 @@ grammar_dump (FILE *out, const char *title)
void
grammar_rules_useless_report (const char *message)
{
warnings w = Wother;
if (warnings_flag & w)
{
rule_number r;
for (r = 0; r < nrules ; ++r)
if (!rules[r].useful)
{
if (feature_flag & feature_caret)
complain (&rules[r].location, w, "%s", message);
else
{
complain (&rules[r].location, w | silent, "%s: ", message);
rule_print (&rules[r], stderr);
warnings_print_categories (w);
fprintf (stderr, "\n");
}
}
}
rule_number r;
for (r = 0; r < nrules ; ++r)
if (!rules[r].useful)
complain (&rules[r].location, Wother, "%s", message);
}
void

View File

@@ -192,7 +192,7 @@ e: 'e' | /* Nothing. */;
]])
AT_BISON_CHECK([-o input.c input.y], 0, [],
[[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */ [-Wother]
[[input.y:4.9: warning: rule useless in parser due to conflicts [-Wother]
]])
AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [],
@@ -920,7 +920,7 @@ cond:
AT_BISON_CHECK([-o input.c input.y], 0, [],
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
input.y:12.3-18: warning: rule useless in parser due to conflicts: cond: cond "then" cond [-Wother]
input.y:12.3-18: warning: rule useless in parser due to conflicts [-Wother]
]])
AT_CLEANUP
@@ -964,7 +964,7 @@ id : '0';
AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0' [-Wother]
input.y:4.6-8: warning: rule useless in parser due to conflicts [-Wother]
]])
# Check the contents of the report.
@@ -1284,13 +1284,13 @@ reported_conflicts:
AT_BISON_CHECK([[--report=all input.y]], 0, [],
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1 [-Wother]
input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2 [-Wother]
input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
input.y:12.5-20: warning: rule useless in parser due to conflicts [-Wother]
input.y:20.5-20: warning: rule useless in parser due to conflicts [-Wother]
input.y:21.4: warning: rule useless in parser due to conflicts [-Wother]
input.y:25.13: warning: rule useless in parser due to conflicts [-Wother]
input.y:25.16: warning: rule useless in parser due to conflicts [-Wother]
input.y:31.5-7: warning: rule useless in parser due to conflicts [-Wother]
input.y:32.4: warning: rule useless in parser due to conflicts [-Wother]
]])
AT_CHECK([[cat input.output]], 0,
@@ -1437,10 +1437,10 @@ AT_CHECK([[cat input.y >> input-keep.y]])
AT_BISON_CHECK([[input-keep.y]], 0, [],
[[input-keep.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
input-keep.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
input-keep.y:22.4: warning: rule useless in parser due to conflicts [-Wother]
input-keep.y:26.16: warning: rule useless in parser due to conflicts [-Wother]
input-keep.y:32.5-7: warning: rule useless in parser due to conflicts [-Wother]
input-keep.y:33.4: warning: rule useless in parser due to conflicts [-Wother]
]])
AT_CLEANUP
@@ -1620,7 +1620,7 @@ exp: 'a' | 'a';
AT_BISON_CHECK([[2.y]], [[0]], [],
[[2.y: warning: %expect-rr applies only to GLR parsers [-Wother]
2.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2.y:3.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
2.y:3.12-14: warning: rule useless in parser due to conflicts [-Wother]
]])
AT_CLEANUP

View File

@@ -2001,7 +2001,7 @@ dnl without being followed by "of".)
[[VARIABLE, '=', LABEL, LEFT, DOT_X]],
dnl BISON-STDERR
[[input.y:471.11-48: warning: rule useless in parser due to conflicts: path: ORDINAL LAST object_type relative_path [-Wother]
[[input.y:471.11-48: warning: rule useless in parser due to conflicts [-Wother]
input.y:19.8-12: warning: useless associativity for LABEL, use %precedence [-Wprecedence]
input.y:20.8-15: warning: useless associativity for VARIABLE, use %precedence [-Wprecedence]
input.y:21.8-13: warning: useless associativity for NUMBER, use %precedence [-Wprecedence]

View File

@@ -201,28 +201,6 @@ input.y:14.11-13: warning: rule useless in grammar [-Wother]
^^^
]])
AT_BISON_CHECK([[input.y]], 0, [],
[[input.y: warning: 9 nonterminals useless in grammar [-Wother]
input.y: warning: 9 rules useless in grammar [-Wother]
input.y:6.1-8: warning: nonterminal useless in grammar: useless1 [-Wother]
input.y:7.1-8: warning: nonterminal useless in grammar: useless2 [-Wother]
input.y:8.1-8: warning: nonterminal useless in grammar: useless3 [-Wother]
input.y:9.1-8: warning: nonterminal useless in grammar: useless4 [-Wother]
input.y:10.1-8: warning: nonterminal useless in grammar: useless5 [-Wother]
input.y:11.1-8: warning: nonterminal useless in grammar: useless6 [-Wother]
input.y:12.1-8: warning: nonterminal useless in grammar: useless7 [-Wother]
input.y:13.1-8: warning: nonterminal useless in grammar: useless8 [-Wother]
input.y:14.1-8: warning: nonterminal useless in grammar: useless9 [-Wother]
input.y:6.11-13: warning: rule useless in grammar: useless1: '1' [-Wother]
input.y:7.11-13: warning: rule useless in grammar: useless2: '2' [-Wother]
input.y:8.11-13: warning: rule useless in grammar: useless3: '3' [-Wother]
input.y:9.11-13: warning: rule useless in grammar: useless4: '4' [-Wother]
input.y:10.11-13: warning: rule useless in grammar: useless5: '5' [-Wother]
input.y:11.11-13: warning: rule useless in grammar: useless6: '6' [-Wother]
input.y:12.11-13: warning: rule useless in grammar: useless7: '7' [-Wother]
input.y:13.11-13: warning: rule useless in grammar: useless8: '8' [-Wother]
input.y:14.11-13: warning: rule useless in grammar: useless9: '9' [-Wother]
]])
AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
[[Nonterminals useless in grammar
@@ -317,16 +295,6 @@ not-reduced.y:17.17-18.63: warning: rule useless in grammar [-Wother]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]])
AT_BISON_CHECK([[not-reduced.y]], 0, [],
[[not-reduced.y: warning: 2 nonterminals useless in grammar [-Wother]
not-reduced.y: warning: 3 rules useless in grammar [-Wother]
not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable [-Wother]
not-reduced.y:11.6-19: warning: nonterminal useless in grammar: non_productive [-Wother]
not-reduced.y:11.6-57: warning: rule useless in grammar: exp: non_productive [-Wother]
not-reduced.y:14.16-56: warning: rule useless in grammar: not_reachable: useful [-Wother]
not-reduced.y:17.17-18.63: warning: rule useless in grammar: non_productive: non_productive useless_token [-Wother]
]])
AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
[[Nonterminals useless in grammar
not_reachable
@@ -397,9 +365,9 @@ AT_BISON_CHECK([[input.y]], 0, [],
input.y: warning: 3 rules useless in grammar [-Wother]
input.y:5.15-25: warning: nonterminal useless in grammar: underivable [-Wother]
input.y:6.14-24: warning: nonterminal useless in grammar: indirection [-Wother]
input.y:5.15-25: warning: rule useless in grammar: exp: underivable [-Wother]
input.y:6.14-24: warning: rule useless in grammar: underivable: indirection [-Wother]
input.y:7.14-24: warning: rule useless in grammar: indirection: underivable [-Wother]
input.y:5.15-25: warning: rule useless in grammar [-Wother]
input.y:6.14-24: warning: rule useless in grammar [-Wother]
input.y:7.14-24: warning: rule useless in grammar [-Wother]
]])
AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,

View File

@@ -1148,8 +1148,8 @@ sr_conflict:
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-Wall -o input.c input.y]], [[0]],,
[[input.y:24.5-19: warning: rule useless in parser due to conflicts: start: start [-Wother]
input.y:28.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias" [-Wother]
[[input.y:24.5-19: warning: rule useless in parser due to conflicts [-Wother]
input.y:28.5-19: warning: rule useless in parser due to conflicts [-Wother]
input.y:18.7-9: warning: useless precedence and associativity for TK1 [-Wprecedence]
]])
AT_COMPILE([[input]])