bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] c++: use YYRHSLOC


From: Akim Demaille
Subject: Re: [PATCH] c++: use YYRHSLOC
Date: Wed, 12 May 2010 09:55:08 +0200

Le 10 mai 2010 à 10:01, Akim Demaille a écrit :

> Installed in master only.

> From bb9191dd311e4c6d80f8dd12c6a7ce9254404fbc Mon Sep 17 00:00:00 2001
> From: Akim Demaille <address@hidden>
> Date: Sun, 9 May 2010 23:58:50 +0200
> Subject: [PATCH] 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.


Finally I installed it in branch-2.5 too.  The main difference is that the NEWS 
entry is in 2.5.  I will move the corresponding entry in master to the same 
place.

From e7bab2df968dd287d0a35a6c8a38569332af2ca2 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Wed, 12 May 2010 07:27:13 +0200
Subject: [PATCH] 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.
(cherry picked from commit bb9191dd311e4c6d80f8dd12c6a7ce9254404fbc)

Conflicts:

        ChangeLog
        NEWS
        data/lalr1.cc
        tests/calc.at
---
 ChangeLog     |   11 +++++++++++
 NEWS          |   35 +++++++++++++++++++++++++++++++++++
 data/glr.cc   |    3 ++-
 data/lalr1.cc |   25 +++++++++++++------------
 tests/calc.at |   25 +++++++++++++------------
 5 files changed, 74 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 966b005..7d8b96b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-05-07  Akim Demaille  <address@hidden>
+
+       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  <address@hidden>
 
        doc: fix lalr1.cc documentation.
diff --git a/NEWS b/NEWS
index 93312ff..ee26910 100644
--- 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
diff --git a/data/glr.cc b/data/glr.cc
index fb9a87b..a55df4f 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -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]])])
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 4009b7c..b400b31 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -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[
diff --git a/tests/calc.at b/tests/calc.at
index b3955ca..2371666 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -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])
-- 
1.7.0.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]