summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-07-20 07:14:50 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-07-20 07:36:38 +0200
commitb8c5e5609ffdb1f27aacab2209b6517817dce79d (patch)
tree11ed59e705992fccdaa19c2e44edac7c1f802439 /src
parentb81229e1f93999c77887422c0795407154876823 (diff)
downloadbison-b8c5e5609ffdb1f27aacab2209b6517817dce79d.tar.gz
cex: label all the derivations by their initial action
From input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] Example: A b . First derivation a `-> A b . Second derivation a `-> A b `-> b . to input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] Example: A b . First reduce derivation a `-> A b . Second reduce derivation a `-> A b `-> b . * src/counterexample.c (print_counterexample): here. Compute the width of the labels to properly align the values. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust.
Diffstat (limited to 'src')
-rw-r--r--src/counterexample.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/counterexample.c b/src/counterexample.c
index 7df75d64..9e89a5c0 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -26,6 +26,7 @@
#include <gl_linked_list.h>
#include <gl_rbtreehash_list.h>
#include <hash.h>
+#include <mbswidth.h>
#include <stdlib.h>
#include <textstyle.h>
#include <time.h>
@@ -112,15 +113,37 @@ free_counterexample (counterexample *cex)
free (cex);
}
+static int max (int a, int b)
+{
+ return a < b ? b : a;
+}
+
static void
print_counterexample (const counterexample *cex, FILE *out, const char *prefix)
{
const bool flat = getenv ("YYFLAT");
- fprintf (out, flat ? " %s%-20s " : " %s%s: ",
- prefix, cex->unifying ? _("Example") : _("First example"));
+ const char *example1_label
+ = cex->unifying ? _("Example") : _("First example");
+ const char *example2_label
+ = cex->unifying ? _("Example") : _("Second example");
+ const char *deriv1_label
+ = cex->shift_reduce ? _("Shift derivation") : _("First reduce derivation");
+ const char *deriv2_label
+ = cex->shift_reduce ? _("Reduce derivation") : _("Second reduce derivation");
+ const int width =
+ max (max (mbswidth (example1_label, 0), mbswidth (example2_label, 0)),
+ max (mbswidth (deriv1_label, 0), mbswidth (deriv2_label, 0)));
+ if (flat)
+ fprintf (out, " %s%s%*s ", prefix,
+ example1_label, width - mbswidth (example1_label, 0), "");
+ else
+ fprintf (out, " %s%s: ", prefix, example1_label);
derivation_print_leaves (cex->d1, out);
- fprintf (out, flat ? " %s%-20s " : " %s%s",
- prefix, cex->shift_reduce ? _("Shift derivation") : _("First derivation"));
+ if (flat)
+ fprintf (out, " %s%s%*s ", prefix,
+ deriv1_label, width - mbswidth (deriv1_label, 0), "");
+ else
+ fprintf (out, " %s%s", prefix, deriv1_label);
derivation_print (cex->d1, out, prefix);
// If we output to the terminal (via stderr) and we have color
@@ -128,12 +151,18 @@ print_counterexample (const counterexample *cex, FILE *out, const char *prefix)
// to see the differences.
if (!cex->unifying || is_styled (stderr))
{
- fprintf (out, flat ? " %s%-20s " : " %s%s: ",
- prefix, cex->unifying ? _("Example") : _("Second example"));
+ if (flat)
+ fprintf (out, " %s%s%*s ", prefix,
+ example2_label, width - mbswidth (example2_label, 0), "");
+ else
+ fprintf (out, " %s%s: ", prefix, example2_label);
derivation_print_leaves (cex->d2, out);
}
- fprintf (out, flat ? " %s%-20s " : " %s%s",
- prefix, cex->shift_reduce ? _("Reduce derivation") : _("Second derivation"));
+ if (flat)
+ fprintf (out, " %s%s%*s ", prefix,
+ deriv2_label, width - mbswidth (deriv2_label, 0), "");
+ else
+ fprintf (out, " %s%s", prefix, deriv2_label);
derivation_print (cex->d2, out, prefix);
if (out != stderr)