From ea138cd1f191ee1aff65c0a706a9646316538916 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 19 Jul 2020 19:34:34 +0200 Subject: [PATCH] cex: use usual routines for diagnostics about S/R conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See previous commit. We go from input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] Shift/reduce conflict on token "⊕": Example exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp ↳ exp • "⊕" exp to input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] Example exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp ↳ exp • "⊕" exp with an hyperlink on -Wcounterexamples. * src/counterexample.c (counterexample_report_shift_reduce): Use complain. * tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust. --- src/counterexample.c | 11 +++++-- tests/conflicts.at | 6 ++-- tests/counterexample.at | 68 ++++++++++++++++++++--------------------- tests/diagnostics.at | 8 ++--- tests/report.at | 20 ++++++------ 5 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/counterexample.c b/src/counterexample.c index 90a1739e..426d131e 100644 --- a/src/counterexample.c +++ b/src/counterexample.c @@ -1248,8 +1248,15 @@ counterexample_report_shift_reduce (state_item_number itm1, state_item_number it symbol_number next_sym, FILE *out, const char *prefix) { - fputs (prefix, out); - fprintf (out, _("Shift/reduce conflict on token %s:\n"), symbols[next_sym]->tag); + if (out == stderr) + complain (NULL, Wcounterexamples, + _("shift/reduce conflict on token %s"), symbols[next_sym]->tag); + else + { + fputs (prefix, out); + fprintf (out, _("shift/reduce conflict on token %s"), symbols[next_sym]->tag); + fprintf (out, "%s\n", _(":")); + } // In the report, print the items. if (*prefix || trace_flag & trace_cex) { diff --git a/tests/conflicts.at b/tests/conflicts.at index 529f7406..187085c3 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -861,7 +861,7 @@ State 5 OP [reduce using rule 1 (exp)] $default reduce using rule 1 (exp) - Shift/reduce conflict on token OP: + shift/reduce conflict on token OP: 1 exp: exp OP exp . 1 exp: exp . OP exp Example exp OP exp . OP exp @@ -1764,7 +1764,7 @@ State 4 reported_conflicts go to state 6 - Shift/reduce conflict on token 'a': + shift/reduce conflict on token 'a': 10 reported_conflicts: . %empty 8 reported_conflicts: . 'a' First example resolved_conflict . 'a' 'a' @@ -1778,7 +1778,7 @@ State 4 `-> resolved_conflict reported_conflicts 'a' `-> . - Shift/reduce conflict on token 'a': + shift/reduce conflict on token 'a': 10 reported_conflicts: . %empty 9 reported_conflicts: . 'a' First example resolved_conflict . 'a' 'a' diff --git a/tests/counterexample.at b/tests/counterexample.at index 270e511e..c6c07320 100644 --- a/tests/counterexample.at +++ b/tests/counterexample.at @@ -54,7 +54,7 @@ y: A | A B; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B C Shift derivation s @@ -68,7 +68,7 @@ Shift/reduce conflict on token B: input.y:4.4: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B C Shift derivation s -> [ y -> [ A . B ] c -> [ C ] ] Reduce derivation s -> [ a -> [ A . ] x -> [ B C ] ] @@ -96,7 +96,7 @@ bc: B bc C | B C; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B C Shift derivation s @@ -109,7 +109,7 @@ Shift/reduce conflict on token B: `-> a bc `-> A . `-> B C -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A A . B B C C Shift derivation s @@ -128,12 +128,12 @@ Shift/reduce conflict on token B: input.y:6.4: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B C Shift derivation s -> [ ac -> [ A ac -> [ b -> [ . B ] ] C ] ] Reduce derivation s -> [ a -> [ A . ] bc -> [ B C ] ] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A A . B B C C Shift derivation s -> [ ac -> [ A ac -> [ A ac -> [ b -> [ . b -> [ B B ] ] ] C ] C ] ] Reduce derivation s -> [ a -> [ A a -> [ A . ] ] bc -> [ B bc -> [ B C ] C ] ] @@ -162,7 +162,7 @@ xby: B | X xby Y; AT_BISON_CHECK_CEX( [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B Shift derivation s @@ -174,7 +174,7 @@ Shift/reduce conflict on token B: `-> A x `-> B y `-> . `-> %empty -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] First example A X . B Y $end Shift derivation $accept @@ -194,12 +194,12 @@ Shift/reduce conflict on token B: input.y:5.4-9: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example A . B Shift derivation s -> [ A xby -> [ . B ] ] Reduce derivation s -> [ ax -> [ A x -> [ . ] ] by -> [ B y -> [ ] ] ] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] First example A X . B Y $end Shift derivation $accept -> [ s -> [ A xby -> [ X xby -> [ . B ] Y ] ] $end ] Second example A X . B y $end @@ -229,7 +229,7 @@ bc: B C; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token C: +input.y: warning: shift/reduce conflict on token C [-Wcounterexamples] First example B . C $end Shift derivation $accept @@ -248,7 +248,7 @@ Shift/reduce conflict on token C: input.y:6.4: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token C: +input.y: warning: shift/reduce conflict on token C [-Wcounterexamples] First example B . C $end Shift derivation $accept -> [ g -> [ x -> [ bc -> [ B . C ] ] ] $end ] Second example B . C D $end @@ -276,7 +276,7 @@ y: A A B; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] First example A . A B $end Shift derivation $accept @@ -295,7 +295,7 @@ Shift/reduce conflict on token A: ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] First example A . A B $end Shift derivation $accept -> [ s -> [ t -> [ y -> [ A . A B ] ] ] $end ] Second example A . A $end @@ -327,7 +327,7 @@ y: Y; AT_BISON_CHECK_CEX( [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] Example b . A X X Y Shift derivation a @@ -340,7 +340,7 @@ Shift/reduce conflict on token A: `-> b . `-> A x xy `-> X `-> X Y -Shift/reduce conflict on token X: +input.y: warning: shift/reduce conflict on token X [-Wcounterexamples] First example A X . X Shift derivation a @@ -357,12 +357,12 @@ input.y:4.4: warning: rule useless in parser due to conflicts [-Wother] input.y:8.4: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] Example b . A X X Y Shift derivation a -> [ s -> [ b . xx -> [ A X X ] y -> [ Y ] ] ] Reduce derivation a -> [ r -> [ b . ] t -> [ A x -> [ X ] xy -> [ X Y ] ] ] -Shift/reduce conflict on token X: +input.y: warning: shift/reduce conflict on token X [-Wcounterexamples] First example A X . X Shift derivation a -> [ t -> [ A xx -> [ X . X ] ] ] Second example X . X xy @@ -472,7 +472,7 @@ i: X | i J K; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token J: +input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] time limit exceeded: XXX First example H i . J K $end Shift derivation @@ -490,7 +490,7 @@ time limit exceeded: XXX input.y:4.4-6: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token J: +input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] time limit exceeded: XXX First example H i . J K $end Shift derivation $accept -> [ a -> [ H i -> [ i . J K ] ] $end ] @@ -522,7 +522,7 @@ b: A B C | A B D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example N A . B C Shift derivation s @@ -535,7 +535,7 @@ Shift/reduce conflict on token B: `-> N a B `-> A . -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example N N A . B D C Shift derivation s @@ -553,12 +553,12 @@ Shift/reduce conflict on token B: input.y:5.4: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example N A . B C Shift derivation s -> [ n -> [ N b -> [ A . B C ] ] ] Reduce derivation s -> [ n -> [ N a -> [ A . ] B ] C ] -Shift/reduce conflict on token B: +input.y: warning: shift/reduce conflict on token B [-Wcounterexamples] Example N N A . B D C Shift derivation s -> [ n -> [ N n -> [ N b -> [ A . B D ] ] C ] ] Reduce derivation s -> [ n -> [ N n -> [ N a -> [ A . ] B ] D ] C ] @@ -703,7 +703,7 @@ time limit exceeded: XXX `-> c A `-> . -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] time limit exceeded: XXX First example b c . A Shift derivation @@ -742,7 +742,7 @@ input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] `-> c A `-> . -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] First example b c . A Shift derivation a @@ -803,7 +803,7 @@ time limit exceeded: XXX Second example c . A $end Second derivation $accept -> [ a -> [ c d -> [ c -> [ . ] A ] ] $end ] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] time limit exceeded: XXX First example b c . A Shift derivation a -> [ b d -> [ c . A ] ] @@ -816,7 +816,7 @@ input.y: warning: reduce/reduce conflict on token A [-Wcounterexamples] Second example b c . A $end Second derivation $accept -> [ a -> [ b d -> [ a -> [ c d -> [ c -> [ . ] A ] ] ] ] $end ] -Shift/reduce conflict on token A: +input.y: warning: shift/reduce conflict on token A [-Wcounterexamples] First example b c . A Shift derivation a -> [ b d -> [ c . A ] ] Second example b c . A $end @@ -857,7 +857,7 @@ i: %empty | i J; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token J: +input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] Example H i J . J J Shift derivation s @@ -872,7 +872,7 @@ Shift/reduce conflict on token J: input.y:5.13-15: warning: rule useless in parser due to conflicts [-Wother] ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token J: +input.y: warning: shift/reduce conflict on token J [-Wcounterexamples] Example H i J . J J Shift derivation s -> [ a -> [ H i J . J ] J ] Reduce derivation s -> [ a -> [ H i -> [ i J . ] J J ] ] @@ -903,7 +903,7 @@ d: D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token D: +input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] Example A a . D Shift derivation s @@ -918,7 +918,7 @@ Shift/reduce conflict on token D: ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token D: +input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] Example A a . D Shift derivation s -> [ A a d -> [ . D ] ] Reduce derivation s -> [ A a a -> [ b -> [ c -> [ . ] ] ] d -> [ D ] ] @@ -947,7 +947,7 @@ d: D; AT_BISON_CHECK_CEX( [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token D: +input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] First example A a . D $end Shift derivation $accept @@ -965,7 +965,7 @@ Shift/reduce conflict on token D: ]], [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr] -Shift/reduce conflict on token D: +input.y: warning: shift/reduce conflict on token D [-Wcounterexamples] First example A a . D $end Shift derivation $accept -> [ s -> [ A a d -> [ . D ] ] $end ] Second example A a . D E $end diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 47581049..0ef480e7 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -535,7 +535,7 @@ exp ]], [1], [[input.y: error: shift/reduce conflicts: 4 found, 0 expected -Shift/reduce conflict on token "+": +input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] Example exp "+" exp "+" exp Shift derivation exp @@ -547,7 +547,7 @@ Shift/reduce conflict on token "+": exp "+" exp exp "+" exp -Shift/reduce conflict on token "else": +input.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples] Example "if" exp "then" "if" exp "then" exp "else" exp Shift derivation exp @@ -559,7 +559,7 @@ Shift/reduce conflict on token "else": "if" exp "then" exp "else" exp "if" exp "then" exp -Shift/reduce conflict on token "+": +input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] Example "if" exp "then" exp "+" exp Shift derivation exp @@ -571,7 +571,7 @@ Shift/reduce conflict on token "+": exp "+" exp "if" exp "then" exp -Shift/reduce conflict on token "+": +input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] Example "if" exp "then" exp "else" exp "+" exp Shift derivation exp diff --git a/tests/report.at b/tests/report.at index ea00d0ad..b12d742c 100644 --- a/tests/report.at +++ b/tests/report.at @@ -1537,7 +1537,7 @@ exp AT_CHECK([LC_ALL="$locale" bison -fno-caret -o input.cc -rall -Wcex --graph=input.gv --xml input.y], [], [], [[input.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr] input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] -Shift/reduce conflict on token "⊕": +input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] Example exp "+" exp • "⊕" exp Shift derivation exp @@ -1557,7 +1557,7 @@ input.y: warning: reduce/reduce conflict on tokens $end, "+", "⊕" [-Wcounterex exp ↳ exp "+" exp • -Shift/reduce conflict on token "⊕": +input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] Example exp "+" exp • "⊕" exp Shift derivation exp @@ -1568,7 +1568,7 @@ Shift/reduce conflict on token "⊕": ↳ exp "⊕" exp ↳ exp "+" exp • -Shift/reduce conflict on token "⊕": +input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] Example exp "⊕" exp • "⊕" exp Shift derivation exp @@ -1579,7 +1579,7 @@ Shift/reduce conflict on token "⊕": ↳ exp "⊕" exp ↳ exp "⊕" exp • -Shift/reduce conflict on token "+": +input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] Example exp "⊕" exp • "+" exp Shift derivation exp @@ -1590,7 +1590,7 @@ Shift/reduce conflict on token "+": ↳ exp "+" exp ↳ exp "⊕" exp • -Shift/reduce conflict on token "+": +input.y: warning: shift/reduce conflict on token "+" [-Wcounterexamples] Example exp "⊕" exp • "+" exp Shift derivation exp @@ -1745,7 +1745,7 @@ State 7 Conflict between rule 2 and token "+" resolved as reduce (%left "+"). - Shift/reduce conflict on token "⊕": + shift/reduce conflict on token "⊕": 2 exp: exp "+" exp • 1 exp: exp • "⊕" exp Example exp "+" exp • "⊕" exp @@ -1769,7 +1769,7 @@ State 7 exp ↳ exp "+" exp • - Shift/reduce conflict on token "⊕": + shift/reduce conflict on token "⊕": 3 exp: exp "+" exp • 1 exp: exp • "⊕" exp Example exp "+" exp • "⊕" exp @@ -1798,7 +1798,7 @@ State 8 "⊕" [reduce using rule 1 (exp)] $default reduce using rule 1 (exp) - Shift/reduce conflict on token "⊕": + shift/reduce conflict on token "⊕": 1 exp: exp "⊕" exp • 1 exp: exp • "⊕" exp Example exp "⊕" exp • "⊕" exp @@ -1811,7 +1811,7 @@ State 8 ↳ exp "⊕" exp ↳ exp "⊕" exp • - Shift/reduce conflict on token "+": + shift/reduce conflict on token "+": 1 exp: exp "⊕" exp • 2 exp: exp • "+" exp Example exp "⊕" exp • "+" exp @@ -1824,7 +1824,7 @@ State 8 ↳ exp "+" exp ↳ exp "⊕" exp • - Shift/reduce conflict on token "+": + shift/reduce conflict on token "+": 1 exp: exp "⊕" exp • 3 exp: exp • "+" exp Example exp "⊕" exp • "+" exp