diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-04-27 14:33:26 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-04-27 18:11:41 +0200 |
commit | 91b8f3f171debc356902e6576607eba4eb9279de (patch) | |
tree | aafeaa0919050c744c441f7199faa7d37454673e /src | |
parent | 8f5d475079477db6ec2b95019e3a1fc67bdbf634 (diff) | |
download | bison-91b8f3f171debc356902e6576607eba4eb9279de.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/getargs.c | 2 | ||||
-rw-r--r-- | src/getargs.h | 1 | ||||
-rw-r--r-- | src/location.c | 65 |
3 files changed, 44 insertions, 24 deletions
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,42 +97,58 @@ 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; - 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)); - if (0 <= loc.start.line) + if (trace_flag & trace_locations) { - res += fprintf (out, ":%d", loc.start.line); - if (0 <= loc.start.column) - res += fprintf (out, ".%d", loc.start.column); + res += boundary_print (&loc.start, out); + res += fprintf (out, "-"); + res += boundary_print (&loc.end, out); } - if (loc.start.file != loc.end.file) + else { - res += fprintf (out, "-%s", - quotearg_n_style (3, escape_quoting_style, - loc.end.file)); - if (0 <= loc.end.line) + 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)); + if (0 <= loc.start.line) { - res += fprintf (out, ":%d", loc.end.line); - if (0 <= end_col) - res += fprintf (out, ".%d", end_col); + res += fprintf (out, ":%d", loc.start.line); + if (0 <= loc.start.column) + res += fprintf (out, ".%d", loc.start.column); } - } - else if (0 <= loc.end.line) - { - if (loc.start.line < loc.end.line) + if (loc.start.file != loc.end.file) { - res += fprintf (out, "-%d", loc.end.line); - if (0 <= end_col) - res += fprintf (out, ".%d", end_col); + res += fprintf (out, "-%s", + quotearg_n_style (3, escape_quoting_style, + 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; |