From aedcb6c095347f71206ed9410ad27907b4be903e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 25 Jan 2013 14:14:01 +0100 Subject: [PATCH] c++: display locations as C does See commit 3804aa260b956dd012adde3894767254422a5fcf. * data/location.cc (operator<<): Display location exactly as is done in C skeletons. * tests/local.at (AT_LOC_PUSHDEF, AT_LOC_POPDEF): Also define AT_FIRST_LINE, AT_LAST_LINE, AT_FIRST_COLUMN, AT_LAST_COLUMN. * tests/actions.at (Location Print): Also check C++ skeletons. --- data/location.cc | 19 ++++++++++--------- tests/actions.at | 17 ++++++++++------- tests/local.at | 23 ++++++++++++++++------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/data/location.cc b/data/location.cc index 74c11458..987843b2 100644 --- a/data/location.cc +++ b/data/location.cc @@ -253,16 +253,17 @@ m4_define([b4_location_define], inline std::basic_ostream& operator<< (std::basic_ostream& ostr, const location& loc) { - position last = loc.end - 1; - ostr << loc.begin; - if (last.filename + unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; + ostr << loc.begin// << "(" << loc.end << ") " +; + if (loc.end.filename && (!loc.begin.filename - || *loc.begin.filename != *last.filename)) - ostr << '-' << last; - else if (loc.begin.line != last.line) - ostr << '-' << last.line << '.' << last.column; - else if (loc.begin.column != last.column) - ostr << '-' << last.column; + || *loc.begin.filename != *loc.end.filename)) + ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; + else if (loc.begin.line < loc.end.line) + ostr << '-' << loc.end.line << '.' << end_col; + else if (loc.begin.column < end_col) + ostr << '-' << end_col; return ostr; } ]]) diff --git a/tests/actions.at b/tests/actions.at index b352451d..75e5d16c 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -204,12 +204,15 @@ exp: /* empty */; int main (void) { + ]AT_YYLTYPE[ loc; +]AT_GLR_CC_IF([loc.initialize();])[ #define TEST(L1, C1, L2, C2) \ - ]AT_LOC_FIRST_LINE[ = L1; \ - ]AT_LOC_FIRST_COLUMN[ = C1; \ - ]AT_LOC_LAST_LINE[ = L2; \ - ]AT_LOC_LAST_COLUMN[ = C2; \ - ]YY_LOCATION_PRINT(stdout, AT_LOC)[;\ + loc.]AT_FIRST_LINE[ = L1; \ + loc.]AT_FIRST_COLUMN[ = C1; \ + loc.]AT_LAST_LINE[ = L2; \ + loc.]AT_LAST_COLUMN[ = C2; \ + ]AT_SKEL_CC_IF([std::cout << loc], + [YY_LOCATION_PRINT(stdout, loc)])[;\ putchar ('\n'); TEST(1, 1, 1, 1); @@ -239,8 +242,8 @@ AT_CLEANUP ## FIXME: test Java, and iterate over skeletons. AT_TEST([yacc.c]) AT_TEST([glr.c]) -#AT_TEST([lalr1.cc]) -#AT_TEST([glr.cc]) +AT_TEST([lalr1.cc]) +AT_TEST([glr.cc]) m4_popdef([AT_TEST]) diff --git a/tests/local.at b/tests/local.at index 52f7a09e..10179cb3 100644 --- a/tests/local.at +++ b/tests/local.at @@ -94,21 +94,30 @@ m4_define([AT_RESTORE_SPECIAL_FILES], [at_restore_special_files]) # AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN) # ---------------------------------------------------------------- -# Pushdef AT_LOC_(FIRST|LAST)_(LINE|COLUMN). +# Pushdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN). m4_define([AT_LOC_PUSHDEF], -[m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.$1]) -m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.$2]) -m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.$3]) -m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.$4])]) +[m4_pushdef([AT_FIRST_LINE], [$1]) +m4_pushdef([AT_FIRST_COLUMN], [$2]) +m4_pushdef([AT_LAST_LINE], [$3]) +m4_pushdef([AT_LAST_COLUMN], [$4]) +m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.AT_FIRST_LINE]) +m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.AT_FIRST_COLUMN]) +m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.AT_LAST_LINE]) +m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.AT_LAST_COLUMN])]) # AT_LOC_POPDEF # ------------- -# Popdef AT_LOC_(FIRST|LAST)_(LINE|COL). +# Popdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN). m4_define([AT_LOC_POPDEF], [m4_popdef([AT_LOC_FIRST_LINE]) m4_popdef([AT_LOC_FIRST_COLUMN]) m4_popdef([AT_LOC_LAST_LINE]) -m4_popdef([AT_LOC_LAST_COLUMN])]) +m4_popdef([AT_LOC_LAST_COLUMN]) +m4_popdef([AT_FIRST_LINE]) +m4_popdef([AT_FIRST_COLUMN]) +m4_popdef([AT_LAST_LINE]) +m4_popdef([AT_LAST_COLUMN]) +]) -- 2.45.2