mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13: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[] =
|
static const char * const trace_args[] =
|
||||||
{
|
{
|
||||||
"none - no traces",
|
"none - no traces",
|
||||||
|
"locations - full display of the locations",
|
||||||
"scan - grammar scanner traces",
|
"scan - grammar scanner traces",
|
||||||
"parse - grammar parser traces",
|
"parse - grammar parser traces",
|
||||||
"automaton - construction of the automaton",
|
"automaton - construction of the automaton",
|
||||||
@@ -206,6 +207,7 @@ static const char * const trace_args[] =
|
|||||||
static const int trace_types[] =
|
static const int trace_types[] =
|
||||||
{
|
{
|
||||||
trace_none,
|
trace_none,
|
||||||
|
trace_locations,
|
||||||
trace_scan,
|
trace_scan,
|
||||||
trace_parse,
|
trace_parse,
|
||||||
trace_automaton,
|
trace_automaton,
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ enum trace
|
|||||||
trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
|
trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
|
||||||
trace_ielr = 1 << 12, /**< IELR conversion. */
|
trace_ielr = 1 << 12, /**< IELR conversion. */
|
||||||
trace_closure = 1 << 13, /**< Input/output of closure(). */
|
trace_closure = 1 << 13, /**< Input/output of closure(). */
|
||||||
|
trace_locations = 1 << 14, /**< Full display of locations. */
|
||||||
trace_all = ~0 /**< All of the above. */
|
trace_all = ~0 /**< All of the above. */
|
||||||
};
|
};
|
||||||
/** What debug items bison displays during its run. */
|
/** What debug items bison displays during its run. */
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include <sys/stat.h> /* fstat */
|
#include <sys/stat.h> /* fstat */
|
||||||
|
|
||||||
#include "complain.h"
|
#include "complain.h"
|
||||||
|
#include "getargs.h"
|
||||||
#include "location.h"
|
#include "location.h"
|
||||||
|
|
||||||
location const empty_location = EMPTY_LOCATION_INIT;
|
location const empty_location = EMPTY_LOCATION_INIT;
|
||||||
@@ -96,42 +97,58 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size)
|
|||||||
complain (loc, Wother, _("byte number overflow"));
|
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
|
unsigned
|
||||||
location_print (location loc, FILE *out)
|
location_print (location loc, FILE *out)
|
||||||
{
|
{
|
||||||
unsigned res = 0;
|
unsigned res = 0;
|
||||||
int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
|
if (trace_flag & trace_locations)
|
||||||
res += fprintf (out, "%s",
|
|
||||||
quotearg_n_style (3, escape_quoting_style, loc.start.file));
|
|
||||||
if (0 <= loc.start.line)
|
|
||||||
{
|
{
|
||||||
res += fprintf (out, ":%d", loc.start.line);
|
res += boundary_print (&loc.start, out);
|
||||||
if (0 <= loc.start.column)
|
res += fprintf (out, "-");
|
||||||
res += fprintf (out, ".%d", loc.start.column);
|
res += boundary_print (&loc.end, out);
|
||||||
}
|
}
|
||||||
if (loc.start.file != loc.end.file)
|
else
|
||||||
{
|
{
|
||||||
res += fprintf (out, "-%s",
|
int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
|
||||||
quotearg_n_style (3, escape_quoting_style,
|
res += fprintf (out, "%s",
|
||||||
loc.end.file));
|
quotearg_n_style (3, escape_quoting_style, loc.start.file));
|
||||||
if (0 <= loc.end.line)
|
if (0 <= loc.start.line)
|
||||||
{
|
{
|
||||||
res += fprintf (out, ":%d", loc.end.line);
|
res += fprintf (out, ":%d", loc.start.line);
|
||||||
if (0 <= end_col)
|
if (0 <= loc.start.column)
|
||||||
res += fprintf (out, ".%d", end_col);
|
res += fprintf (out, ".%d", loc.start.column);
|
||||||
}
|
}
|
||||||
}
|
if (loc.start.file != loc.end.file)
|
||||||
else if (0 <= loc.end.line)
|
|
||||||
{
|
|
||||||
if (loc.start.line < loc.end.line)
|
|
||||||
{
|
{
|
||||||
res += fprintf (out, "-%d", loc.end.line);
|
res += fprintf (out, "-%s",
|
||||||
if (0 <= end_col)
|
quotearg_n_style (3, escape_quoting_style,
|
||||||
res += fprintf (out, ".%d", end_col);
|
loc.end.file));
|
||||||
|
if (0 <= loc.end.line)
|
||||||
|
{
|
||||||
|
res += fprintf (out, ":%d", loc.end.line);
|
||||||
|
if (0 <= end_col)
|
||||||
|
res += fprintf (out, ".%d", end_col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (0 <= loc.end.line)
|
||||||
|
{
|
||||||
|
if (loc.start.line < loc.end.line)
|
||||||
|
{
|
||||||
|
res += fprintf (out, "-%d", loc.end.line);
|
||||||
|
if (0 <= end_col)
|
||||||
|
res += fprintf (out, ".%d", end_col);
|
||||||
|
}
|
||||||
|
else if (0 <= end_col && loc.start.column < end_col)
|
||||||
|
res += fprintf (out, "-%d", end_col);
|
||||||
}
|
}
|
||||||
else if (0 <= end_col && loc.start.column < end_col)
|
|
||||||
res += fprintf (out, "-%d", end_col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Reference in New Issue
Block a user