]> git.saurik.com Git - bison.git/commitdiff
c++: display locations as C does
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 25 Jan 2013 13:14:01 +0000 (14:14 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Fri, 25 Jan 2013 15:35:52 +0000 (16:35 +0100)
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
tests/actions.at
tests/local.at

index 74c114582b7a1d306e8000e3c510d6a524f0561c..987843b26cd55e9a7a51850dbedc6d1a185d8597 100644 (file)
@@ -253,16 +253,17 @@ m4_define([b4_location_define],
   inline std::basic_ostream<YYChar>&
   operator<< (std::basic_ostream<YYChar>& 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;
   }
 ]])
index b352451d29f3981f61d7115ce588fe63ce4cd1d9..75e5d16c319259541966c31bb96693b8b4cdf043 100644 (file)
@@ -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])
 
index 52f7a09e941ed0d87ac76b49ab00816a5750b75f..10179cb3a98f4674e03a5e703476a304688a0da7 100644 (file)
@@ -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])
+])