cex: use usual routines for diagnostics about R/R conflicts

This is more consistent, and brings benefits: users know that these
diagnostics are attached to -Wcounterexamples, and they can also click
on the hyperlink if permitted by their terminal.

We go from

    warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    Reduce/reduce conflict on token $end:
      Example              A b .
      First derivation     a -> [ A b . ]
      Second derivation    a -> [ A b -> [ b . ] ]

to

    warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples]
      Example              A b .
      First derivation     a -> [ A b . ]
      Second derivation    a -> [ A b -> [ b . ] ]

with an hyperlink on -Wcounterexamples.

* src/counterexample.c (counterexample_report_reduce_reduce):
Use complain.
* tests/counterexample.at, tests/diagnostics.at, tests/report.at:
Adjust.
This commit is contained in:
Akim Demaille
2020-07-19 18:00:51 +02:00
parent 1438b79e80
commit 9922f1f877
5 changed files with 51 additions and 35 deletions

View File

@@ -1265,27 +1265,43 @@ counterexample_report_reduce_reduce (state_item_number itm1, state_item_number i
FILE *out, const char *prefix)
{
{
fputs (prefix, out);
fputs (ngettext ("Reduce/reduce conflict on token",
"Reduce/reduce conflict on tokens",
bitset_count (conflict_syms)), out);
struct obstack obstack;
obstack_init (&obstack);
bitset_iterator biter;
state_item_number sym;
const char *sep = " ";
const char *sep = "";
BITSET_FOR_EACH (biter, conflict_syms, sym, 0)
{
fprintf (out, "%s%s", sep, symbols[sym]->tag);
obstack_printf (&obstack, "%s%s", sep, symbols[sym]->tag);
sep = ", ";
}
fputs (_(":\n"), out);
char *tokens = obstack_finish0 (&obstack);
if (out == stderr)
complain (NULL, Wcounterexamples,
ngettext ("reduce/reduce conflict on token %s",
"reduce/reduce conflict on tokens %s",
bitset_count (conflict_syms)),
tokens);
else
{
fputs (prefix, out);
fprintf (out,
ngettext ("reduce/reduce conflict on token %s",
"reduce/reduce conflict on tokens %s",
bitset_count (conflict_syms)),
tokens);
fprintf (out, "%s\n", _(":"));
}
obstack_free (&obstack, NULL);
}
// In the report, print the items.
if (*prefix || trace_flag & trace_cex)
if (out != stderr || trace_flag & trace_cex)
{
print_state_item (&state_items[itm1], out, prefix);
print_state_item (&state_items[itm2], out, prefix);
}
counterexample_report (itm1, itm2, bitset_first (conflict_syms), false, out, prefix);
counterexample_report (itm1, itm2, bitset_first (conflict_syms),
false, out, prefix);
}
static state_item_number