cex: suggest -Wcounterexamples when there are unexpected conflicts

Suggesting -Wcounterexamples when there are conflicts is probably not
what the user wants.  If she knows her conflicts and has set
%expect/%expect-rr appropriately, we shouldn't warn.

The commit also swaps the counterexamples and the report of conflicts,
into, IMHO, a more natural order: from

    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

to

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

* src/conflicts.c (rule_conflicts_print): Rename as...
(report_rule_expectation_mismatches): this.
Move the handling of report_counterexamples to...
(conflicts_print): Here.
Display this warning when applicable.
This commit is contained in:
Akim Demaille
2020-06-10 08:11:56 +02:00
parent d2acc4b401
commit b0bb4cde2e
8 changed files with 112 additions and 56 deletions

View File

@@ -726,6 +726,7 @@ AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
[[0]], [[]],
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[input]], [[1]], [[]],
@@ -736,6 +737,7 @@ AT_PARSER_CHECK([[input]], [[1]], [[]],
AT_BISON_CHECK([[-Dlr.type=canonical-lr -Dparse.lac=full \
-o input.c input.y]], [[0]], [[]],
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[input]], [[1]], [[]],
@@ -746,6 +748,7 @@ AT_PARSER_CHECK([[input]], [[1]], [[]],
AT_BISON_CHECK([[-Dlr.type=ielr -Dparse.lac=full -o input.c input.y]],
[[0]], [[]],
[[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[input]], [[1]], [[]],
@@ -770,6 +773,7 @@ exp: exp OP exp | NUM;
AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
# Check the contents of the report.
@@ -1014,6 +1018,7 @@ cond:
AT_BISON_CHECK([-o input.c input.y], 0, [],
[[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
input.y:12.3-18: warning: rule useless in parser due to conflicts [-Wother]
]])
@@ -1118,6 +1123,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: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
input.y:4.6-8: warning: rule useless in parser due to conflicts [-Wother]
]])
@@ -1238,6 +1244,7 @@ exp: exp OP exp | NUM;
AT_BISON_CHECK([-o input.c input.y], 1, [],
[[input.y: error: shift/reduce conflicts: 1 found, 0 expected
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_CLEANUP
@@ -1274,6 +1281,7 @@ exp: exp OP exp | NUM;
AT_BISON_CHECK([-o input.c input.y], 1, [],
[[input.y: error: shift/reduce conflicts: 1 found, 2 expected
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_CLEANUP
@@ -1293,6 +1301,7 @@ a: 'a';
AT_BISON_CHECK([-o input.c input.y], 1, [],
[[input.y: error: reduce/reduce conflicts: 1 found, 0 expected
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_CLEANUP
@@ -1493,6 +1502,7 @@ e: e '+' e
AT_BISON_CHECK([-Wall -o input.c input.y], 0, [],
[[input.y: warning: 4 shift/reduce conflicts [-Wconflicts-sr]
input.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
input.y:1.1-5: warning: useless precedence and associativity for '+' [-Wprecedence]
input.y:2.1-5: warning: useless precedence and associativity for '*' [-Wprecedence]
]])
@@ -1598,6 +1608,7 @@ 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: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-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]
@@ -1756,6 +1767,7 @@ 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: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-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]
@@ -1939,6 +1951,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: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
2.y:3.12-14: warning: rule useless in parser due to conflicts [-Wother]
]])
@@ -1975,12 +1988,15 @@ B: ;
AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
[[sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
sr-rr.y: warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother]
]])
[
@@ -2049,6 +2065,7 @@ for gram in sr-rr sr rr; do
fi
} | sed -e "s/^/$file: /" > experr
]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
echo "$file: error: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Werror=other]" >> experr
]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[
fi
done