mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
diagnostics: show locations in full when debugging
This is meant for developers, not end users, that's why I attached it to --trace. * src/getargs.h, src/getargs.c (trace_locations): New. * src/location.c (location_print): Use it.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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:%d.%d@%d",
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user