From a514c51e555c7c5ee962a84eb571c2fdfa49a1ec Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 27 Apr 2019 14:39:22 +0200 Subject: [PATCH] diagnostics: fix locations coming from M4 Locations issued from M4 need the byte-based column for the diagnostics to work properly. Currently they were unassigned, which typically resulted in partially non-colored diagnostics. * src/location.c (boundary_set_from_string): Fix the parsed location. * src/muscle-tab.c (muscle_percent_define_default): Set the byte values. * tests/diagnostics.at (Locations from M4): New. --- src/location.c | 2 +- src/muscle-tab.c | 8 +++++--- tests/diagnostics.at | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/location.c b/src/location.c index 2c56e0cf..e2299c2e 100644 --- a/src/location.c +++ b/src/location.c @@ -296,7 +296,7 @@ boundary_set_from_string (boundary *bound, char *loc_str) char *delim = strrchr (loc_str, '.'); aver (delim); *delim = '\0'; - bound->column = atoi (delim+1); + bound->byte = bound->column = atoi (delim+1); delim = strrchr (loc_str, ':'); aver (delim); *delim = '\0'; diff --git a/src/muscle-tab.c b/src/muscle-tab.c index a8cec20e..cd4beeb2 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -710,9 +710,11 @@ muscle_percent_define_default (char const *variable, char const *value) { uniqstr loc_name = muscle_name (variable, "loc"); location loc; - loc.start.file = loc.end.file = ""; - loc.start.line = loc.end.line = -1; - loc.start.column = loc.end.column = -1; + loc.start.file = ""; + loc.start.line = -1; + loc.start.column = -1; + loc.start.byte = -1; + loc.end = loc.start; muscle_insert (loc_name, ""); muscle_location_grow (loc_name, loc); } diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 773982ff..282d9b35 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -18,8 +18,8 @@ AT_BANNER([[Diagnostics.]]) -# AT_TEST([TITLE], [GRAMMAR], [OUTPUT-WITH-STYLE]) -# ------------------------------------------------ +# AT_TEST($1: TITLE, $2: GRAMMAR, $3: EXIT-STATUS, $4: OUTPUT-WITH-STYLE) +# ----------------------------------------------------------------------- m4_pushdef([AT_TEST], [ AT_SETUP([$1]) @@ -33,15 +33,15 @@ AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([[input.y]], [$2]) -AT_DATA([experr], [$3]) +AT_DATA([experr], [$4]) # Cannot use AT_BISON_CHECK easily as we need to change the # environment. # FIXME: Enhance AT_BISON_CHECK. -AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --style=debug -Wall input.y], [], [], [experr]) +AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret --style=debug -Wall input.y], [$3], [], [experr]) # When no style, same messages, but without style. AT_CHECK([perl -pi -e 's{}{}g' experr]) -AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [], [], [experr]) +AT_CHECK([LC_ALL=en_US.UTF-8 bison -fcaret -Wall input.y], [$3], [], [experr]) AT_BISON_OPTION_POPDEFS @@ -59,6 +59,7 @@ AT_TEST([[Warnings]], %% exp: %empty; ]], +[0], [[input.y:9.12-14: warning: symbol FOO redeclared [-Wother] 9 | %token FOO FOO FOO | ^~~ @@ -97,6 +98,7 @@ d : e: ]], +[0], [[input.y:11.4-5: warning: empty rule without %empty [-Wempty-rule] 11 | a: {} | ^~ @@ -135,6 +137,7 @@ f: { 42 } g: { "฿¥$€₦" } h: { 🐃 } ]], +[0], [[input.y:11.4-17: warning: empty rule without %empty [-Wempty-rule] 11 | a: { } | ^~~~~~~~~~~~~~ @@ -163,9 +166,9 @@ input.y: warning: fix-its can be applied. Rerun with option ]]) -## -------------- ## -## Special files. ## -## -------------- ## +## --------------- ## +## Special files. ## +## --------------- ## # Don't try to quote special files. # http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html @@ -178,6 +181,7 @@ a: {} #line 1 "/dev/stdout" b: {} ]], +[0], [[input.y:11.4-5: warning: empty rule without %empty [-Wempty-rule] 11 | a: {} | ^~ @@ -186,5 +190,26 @@ b: {} ]]) +## ------------------- ## +## Locations from M4. ## +## ------------------- ## + +# Locations coming from m4 need the byte-column for diagnostics. + +AT_TEST([[Locations from M4]], +[[%define api.prefix {foo} +%define api.prefix {bar} +%% +exp:; +]], +[1], +[[input.y:10.1-24: error: %define variable 'api.prefix' redefined + 10 | %define api.prefix {bar} + | ^~~~~~~~~~~~~~~~~~~~~~~~ +input.y:9.1-24: previous definition + 9 | %define api.prefix {foo} + | ^~~~~~~~~~~~~~~~~~~~~~~~ +input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] +]]) m4_popdef([AT_TEST])