[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] diagnostics: provide a means to see byte-columns
From: |
Akim Demaille |
Subject: |
[PATCH 2/4] diagnostics: provide a means to see byte-columns |
Date: |
Sat, 27 Apr 2019 18:15:54 +0200 |
This is meant for developers, not end users, that's why I attached it
to --trace.
* src/getargs.h, src/getargs.c (trace_byte): New.
* src/location.c (location_print): Use it.
---
src/getargs.c | 2 ++
src/getargs.h | 1 +
src/location.c | 17 +++++++++++++++++
3 files changed, 20 insertions(+)
diff --git a/src/getargs.c b/src/getargs.c
index f672c75e..080ef352 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -185,6 +185,7 @@ ARGMATCH_VERIFY (report_args, report_types);
static const char * const trace_args[] =
{
"none - no traces",
+ "locations - full display of the locations",
"scan - grammar scanner traces",
"parse - grammar parser traces",
"automaton - construction of the automaton",
@@ -206,6 +207,7 @@ static const char * const trace_args[] =
static const int trace_types[] =
{
trace_none,
+ trace_locations,
trace_scan,
trace_parse,
trace_automaton,
diff --git a/src/getargs.h b/src/getargs.h
index 58f082f8..27fb0fad 100644
--- a/src/getargs.h
+++ b/src/getargs.h
@@ -104,6 +104,7 @@ enum trace
trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
trace_ielr = 1 << 12, /**< IELR conversion. */
trace_closure = 1 << 13, /**< Input/output of closure(). */
+ trace_locations = 1 << 14, /**< Full display of locations. */
trace_all = ~0 /**< All of the above. */
};
/** What debug items bison displays during its run. */
diff --git a/src/location.c b/src/location.c
index 6d361c19..2c56e0cf 100644
--- a/src/location.c
+++ b/src/location.c
@@ -27,6 +27,7 @@
#include <sys/stat.h> /* fstat */
#include "complain.h"
+#include "getargs.h"
#include "location.h"
location const empty_location = EMPTY_LOCATION_INIT;
@@ -96,11 +97,26 @@ location_compute (location *loc, boundary *cur, char const
*token, size_t size)
complain (loc, Wother, _("byte number overflow"));
}
+static unsigned
+boundary_print (boundary const *b, FILE *out)
+{
+ return fprintf (out, "%s:address@hidden",
+ quotearg_n_style (3, escape_quoting_style, b->file),
+ b->line, b->column, b->byte);
+}
unsigned
location_print (location loc, FILE *out)
{
unsigned res = 0;
+ if (trace_flag & trace_locations)
+ {
+ res += boundary_print (&loc.start, out);
+ res += fprintf (out, "-");
+ res += boundary_print (&loc.end, out);
+ }
+ else
+ {
int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
res += fprintf (out, "%s",
quotearg_n_style (3, escape_quoting_style,
loc.start.file));
@@ -133,6 +149,7 @@ location_print (location loc, FILE *out)
else if (0 <= end_col && loc.start.column < end_col)
res += fprintf (out, "-%d", end_col);
}
+ }
return res;
}
--
2.21.0