]> git.saurik.com Git - bison.git/commitdiff
c++: use YYRHSLOC.
authorAkim Demaille <demaille@gostai.com>
Wed, 12 May 2010 05:27:13 +0000 (07:27 +0200)
committerAkim Demaille <demaille@gostai.com>
Wed, 12 May 2010 05:27:13 +0000 (07:27 +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.
(cherry picked from commit bb9191dd311e4c6d80f8dd12c6a7ce9254404fbc)

Conflicts:

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

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

index 966b00508f6d45c57e9fc930e5f1b2d149d17267..7d8b96bedaf05f303106690d3dac176f67996f97 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-05-07  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-10  Akim Demaille  <demaille@gostai.com>
 
        doc: fix lalr1.cc documentation.
diff --git a/NEWS b/NEWS
index 93312ff953a67d8f26464dc20a0f4e7a9ec15295..ee269105210522fafe1fd36c8af6b9d417958e01 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -180,6 +180,41 @@ Bison News
   determine which destructor to call for the lookahead upon a syntax
   error or upon parser return.  This bug has been fixed.
 
+** 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)
+
 * Changes in version 2.4.3 (????-??-??):
 
 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
index fb9a87b662b04bf3b82edaf8a18a279b23d8252c..a55df4f37aab50fc08efa88d6b76dc598f803c34 100644 (file)
@@ -53,7 +53,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]])])
index 4009b7c87fae84454831617d18e80d0ef1c0e2c2..b400b310306db385f840b6fe14f000d59304c375 100644 (file)
@@ -73,19 +73,20 @@ dnl FIXME: This is wrong, we want computed header guards.
    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])
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)               \
-do {                                                   \
-  if (N)                                               \
-    {                                                  \
-      (Current).begin = (Rhs)[1].begin;                        \
-      (Current).end   = (Rhs)[N].end;                  \
-    }                                                  \
-  else                                                 \
-    {                                                  \
-      (Current).begin = (Current).end = (Rhs)[0].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 b3955ca5cbacc62bdcc4025e2296c0c4b693d3a1..2371666300c0898342dc157ca4e68b93719f863a 100644 (file)
@@ -170,18 +170,18 @@ AT_SKEL_CC_IF(
     Point last;
   };
 
-# define YYLLOC_DEFAULT(Current, Rhs, N)                \
-do {                                                    \
-  if (N)                                                \
-    {                                                   \
-      (Current).first = (Rhs)[1].first;                        \
-      (Current).last  = (Rhs)[N].last;                  \
-    }                                                   \
-  else                                                  \
-    {                                                   \
-      (Current).first = (Current).last = (Rhs)[0].last;        \
-    }                                                   \
-} while (false)
+# 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)
 
 ]])[
   /* Exercise pre-prologue dependency to %union.  */
@@ -712,6 +712,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([%error-verbose %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_GLR_CC([%debug])