]> git.saurik.com Git - bison.git/commitdiff
c++: use YYRHSLOC.
authorAkim Demaille <demaille@gostai.com>
Sun, 9 May 2010 21:58:50 +0000 (23:58 +0200)
committerAkim Demaille <demaille@gostai.com>
Mon, 10 May 2010 07:59:11 +0000 (09:59 +0200)
* data/lalr1.cc (YYRHSLOC): New.
(YYLLOC_DEFAULT): Use it.
* data/glr.cc: If location_type was user defined, do not include
location.hh, and do not produce location.hh and position.hh.
* tests/calc.at (YYLLOC_DEFAULT): Use YYRHSLOC.
Check that glr.cc supports user defined location_type.
* NEWS: Document this.

ChangeLog
NEWS
data/glr.cc
data/lalr1.cc
tests/calc.at

index 724a1213d6c9958c174e89014a8114ee4e2cd13b..cea5f0267678c1e275c2c536f5a43f642a42d7ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-05-10  Akim Demaille  <demaille@gostai.com>
+
+       c++: use YYRHSLOC.
+       * data/lalr1.cc (YYRHSLOC): New.
+       (YYLLOC_DEFAULT): Use it.
+       * data/glr.cc: If location_type was user defined, do not include
+       location.hh, and do not produce location.hh and position.hh.
+       * tests/calc.at (YYLLOC_DEFAULT): Use YYRHSLOC.
+       Check that glr.cc supports user defined location_type.
+       * NEWS: Document this.
+
 2010-05-07  Akim Demaille  <demaille@gostai.com>
 
        doc: fix typo.
diff --git a/NEWS b/NEWS
index 7097f3bd80aaba305a64ca052b62b92193c0b573..cacdb7702cc0d9803504a5f33b82b317e2fb0a31 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,10 +3,46 @@ Bison News
 
 * Changes in version ?.? (????-??-??):
 
+** C++ parsers use YYRHSLOC
+
+  Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
+  macro and use it in the default YYLLOC_DEFAULT.  You are encouraged
+  to use it.  If, for instance, your location structure has "first"
+  and "last" members, instead of
+
+      # define YYLLOC_DEFAULT(Current, Rhs, N)                             \
+        do                                                                 \
+          if (N)                                                           \
+            {                                                              \
+              (Current).first = (Rhs)[1].location.first;                   \
+              (Current).last  = (Rhs)[N].location.last;                    \
+            }                                                              \
+          else                                                             \
+            {                                                              \
+              (Current).first = (Current).last = (Rhs)[0].location.last;   \
+            }                                                              \
+        while (false)
+
+  use:
+
+      # define YYLLOC_DEFAULT(Current, Rhs, N)                             \
+        do                                                                 \
+          if (N)                                                           \
+            {                                                              \
+              (Current).first = YYRHSLOC (Rhs, 1).first;                   \
+              (Current).last  = YYRHSLOC (Rhs, N).last;                    \
+            }                                                              \
+          else                                                             \
+            {                                                              \
+              (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last;   \
+            }                                                              \
+        while (false)
+
+
 ** Additional yylex/yyparse arguments
 
   The new directive %param declare additional argument to both yylex
-  and yyparse.  The %lex-param, %parse-param, and %param directive
+  and yyparse.  The %lex-param, %parse-param, and %param directives
   support one or more arguments.  Instead of
 
       %lex-param   {arg1_type *arg1}
index feed669a277e547c0fb95a06f120aadfbf89c389..24b3fbbea3384d10c4c5475ece43087633b8deab 100644 (file)
@@ -51,7 +51,8 @@ b4_defines_if([],
               [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
 
 m4_include(b4_pkgdatadir/[c++.m4])
-m4_include(b4_pkgdatadir/[location.cc])
+b4_percent_define_ifdef([[location_type]], [],
+                        [m4_include(b4_pkgdatadir/[location.cc])])
 
 m4_define([b4_parser_class_name],
           [b4_percent_define_get([[parser_class_name]])])
@@ -226,7 +227,8 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
 #include <stdexcept>
 #include <string>
 #include <iostream>
-#include "location.hh"
+]b4_percent_define_ifdef([[location_type]], [],
+                         [[#include "location.hh"]])[
 
 /* Using locations.  */
 #define YYLSP_NEEDED ]b4_locations_if([1], [0])[
index 7cb7db628ac64336994836b110981f93f575f746..8094cccffd08a4decc34aa29e2919ce0511f6ea4 100644 (file)
@@ -180,19 +180,20 @@ b4_namespace_close])[
    If N is 0, then set CURRENT to the empty location which ends
    the previous symbol: RHS[0] (always defined).  */
 
+#define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)                        \
-do {                                                            \
-  if (N)                                                        \
-    {                                                           \
-      (Current).begin = (Rhs)[1].location.begin;                \
-      (Current).end   = (Rhs)[N].location.end;                 \
-    }                                                           \
-  else                                                          \
-    {                                                           \
-      (Current).begin = (Current).end = (Rhs)[0].location.end; \
-    }                                                           \
-} while (false)
+# define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+ do                                                                    \
+   if (N)                                                              \
+     {                                                                 \
+       (Current).begin = YYRHSLOC (Rhs, 1).begin;                      \
+       (Current).end   = YYRHSLOC (Rhs, N).end;                        \
+     }                                                                 \
+   else                                                                \
+     {                                                                 \
+       (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;        \
+     }                                                                 \
+ while (false)
 #endif]])[
 
 ]b4_namespace_open[
index 08ccbe41cd7dbf959b97aaa0a8aefc7be63dbb6c..5046d23734105147ece124d68f1fa7d51e9b534b 100644 (file)
@@ -171,17 +171,17 @@ AT_SKEL_CC_IF(
   };
 
 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
-do {                                                                    \
-  if (N)                                                                \
-    {                                                                   \
-      (Current).first = (Rhs)[1].location.first;                       \
-      (Current).last  = (Rhs)[N].location.last;                         \
-    }                                                                   \
-  else                                                                  \
-    {                                                                   \
-      (Current).first = (Current).last = (Rhs)[0].location.last;       \
-    }                                                                   \
-} while (false)
+  do                                                                    \
+    if (N)                                                              \
+      {                                                                 \
+        (Current).first = YYRHSLOC (Rhs, 1).first;                      \
+        (Current).last  = YYRHSLOC (Rhs, N).last;                       \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last;      \
+      }                                                                 \
+  while (false)
 
 ]])[
   /* Exercise pre-prologue dependency to %union.  */
@@ -716,6 +716,7 @@ m4_define([AT_CHECK_CALC_GLR_CC],
 [AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)])
 
 AT_CHECK_CALC_GLR_CC([])
+AT_CHECK_CALC_GLR_CC([%define location_type Span])
 AT_CHECK_CALC_GLR_CC([%define parse.error verbose %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_GLR_CC([%debug])