bison-patches
[Top][All Lists]
Advanced

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

Re: Using "%define location_type" c++ skeleton should exclude default lo


From: Akim Demaille
Subject: Re: Using "%define location_type" c++ skeleton should exclude default location
Date: Sun, 9 May 2010 14:34:55 +0200

Le 4 mai 2010 à 15:30, Akim Demaille a écrit :

> 
> Le 14 avr. 2010 à 13:19, Akim Demaille a écrit :
> 
>> I have installed a first batch of changes in 2.5 and 2.6 to this end.  I 
>> think I failed to keep you in CC, please have a look at the archive (it 
>> should appear in 
>> http://lists.gnu.org/archive/html/bison-patches/2010-04/threads.html I 
>> guess).
> 
> Installed in master, will be cherry-picked/back-ported into 2.5.
> 
> From 7789b6e3e7199a00437f03591a4605e6c042bdea Mon Sep 17 00:00:00 2001
> From: Akim Demaille <address@hidden>
> Date: Wed, 14 Apr 2010 17:56:38 +0200
> Subject: [PATCH 17/18] lalr1.cc: don't generate location.hh when 
> location_type is defined
> 
>       * data/bison.m4 (b4_percent_define_get): Accept a default value.
>       * data/c++.m4: Do not provide a default value for the %define
>       variable location_type, rather, use b4_percent_define_get with a
>       default argument where its value is needed.
>       * data/lalr1.cc: Do not load location.cc (which outputs both
>       location.hh and position.hh) if the user defined location_type.
>       Do not include location.hh either.

Installed in branch-2.5.  Many conflicts, there are many changes in that area 
of the code bw 2.5 and master.  We should probably "define" 2.5, and focus on 
releasing it.

From 95a2de5695670ae0df98cb3c42141cad549f0204 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Sun, 9 May 2010 14:29:35 +0200
Subject: [PATCH] lalr1.cc: don't generate location.hh when location_type is 
defined

        * data/bison.m4 (b4_percent_define_use): New.
        (b4_percent_define_get): Use it.
        Accept a default value.
        * data/c++.m4: Do not provide a default value for the %define
        variable location_type, rather, use b4_percent_define_get with a
        default argument where its value is needed.
        * data/lalr1.cc: Do not load location.cc (which outputs both
        location.hh and position.hh) if the user defined location_type.
        Do not include location.hh either.
        * data/glr.cc: Likewise.

(cherry picked from commit 7789b6e3e7199a00437f03591a4605e6c042bdea)

Conflicts:

        ChangeLog
        data/bison.m4
        data/c++.m4
        data/lalr1.cc
---
 ChangeLog     |   14 ++++++++++++++
 data/bison.m4 |   29 ++++++++++++++++++++++++-----
 data/c++.m4   |    7 ++++++-
 data/glr.cc   |    6 ++++--
 data/lalr1.cc |   13 ++++++++-----
 5 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c59e809..aa2efc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2010-05-04  Akim Demaille  <address@hidden>
 
+       lalr1.cc: don't generate location.hh when location_type is defined
+       * data/bison.m4 (b4_percent_define_use): New.
+       (b4_percent_define_get): Use it.
+       Accept a default value.
+       * data/c++.m4: Do not provide a default value for the %define
+       variable location_type, rather, use b4_percent_define_get with a
+       default argument where its value is needed.
+       * data/lalr1.cc: Do not load location.cc (which outputs both
+       location.hh and position.hh) if the user defined location_type.
+       Do not include location.hh either.
+       * data/glr.cc: Likewise.
+
+2010-05-04  Akim Demaille  <address@hidden>
+
        lalr1.cc: location_type: make sure we don't depend on loc.(begin|end).
        * tests/calc.at (Span): Instead of begin/end, as in the built-in
        location class, use first and last.
diff --git a/data/bison.m4 b/data/bison.m4
index 868f98a..d894606 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -361,10 +361,26 @@ m4_popdef([b4_start])dnl
 m4_popdef([b4_end])dnl
 ])])
 
-# b4_percent_define_get(VARIABLE)
+
+
+
+## --------------------- ##
+## b4_percent_define_*.  ##
+## --------------------- ##
+
+
+# b4_percent_define_use(VARIABLE)
 # -------------------------------
-# Mimic muscle_percent_define_get in ../src/muscle-tab.h exactly.  That is, if
-# the %define variable VARIABLE is defined, emit its value.  Also, record
+# Declare that VARIABLE was used.
+m4_define([b4_percent_define_use],
+[m4_define([b4_percent_define_bison_variables(]$1[)])dnl
+])
+
+# b4_percent_define_get(VARIABLE, [DEFAULT])
+# ------------------------------------------
+# Mimic muscle_percent_define_get in ../src/muscle-tab.h.  That is, if
+# the %define variable VARIABLE is defined, emit its value.  Contrary
+# to its C counterpart, return DEFAULT otherwise.  Also, record
 # Bison's usage of VARIABLE by defining
 # b4_percent_define_bison_variables(VARIABLE).
 #
@@ -372,8 +388,11 @@ m4_popdef([b4_end])dnl
 #
 #   b4_percent_define_get([[foo]])
 m4_define([b4_percent_define_get],
-[m4_define([b4_percent_define_bison_variables(]$1[)])dnl
-m4_ifdef([b4_percent_define(]$1[)], [m4_indir([b4_percent_define(]$1[)])])])
+[b4_percent_define_use([$1])dnl
+m4_ifdef([b4_percent_define(]$1[)],
+         [m4_indir([b4_percent_define(]$1[)])],
+         [$2])])
+
 
 # b4_percent_define_get_loc(VARIABLE)
 # -----------------------------------
diff --git a/data/c++.m4 b/data/c++.m4
index 7b58c90..2810626 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -25,7 +25,12 @@ m4_include(b4_pkgdatadir/[c.m4])
 
 # Default parser class name.
 b4_percent_define_default([[parser_class_name]], [[parser]])
-b4_percent_define_default([[location_type]], [[location]])
+
+# Don't do that so that we remember whether we're using a user
+# request, or the default value.
+#
+# b4_percent_define_default([[location_type]], [[location]])
+
 b4_percent_define_default([[filename_type]], [[std::string]])
 b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
 b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
diff --git a/data/glr.cc b/data/glr.cc
index 068f9a3..fb9a87b 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -229,7 +229,8 @@ b4_copyright([Skeleton interface for Bison GLR parsers in 
C++],
 
 #include <string>
 #include <iostream>
-#include "location.hh"
+]b4_percent_define_ifdef([[location_type]], [],
+                         [[#include "location.hh"]])[
 
 /* Using locations.  */
 #define YYLSP_NEEDED ]b4_locations_flag[
@@ -277,7 +278,8 @@ b4_user_stype
     typedef YYSTYPE semantic_type;
 #endif
     /// Symbol locations.
-    typedef ]b4_percent_define_get([[location_type]])[ location_type;
+    typedef ]b4_percent_define_get([[location_type]],
+                                   [[location]])[ location_type;
     /// Tokens.
     struct token
     {
diff --git a/data/lalr1.cc b/data/lalr1.cc
index cd54b6c..4009b7c 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -24,9 +24,10 @@ m4_define([b4_parser_class_name],
 b4_defines_if([],
               [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
 
-# Backward compatibility.
-m4_define([b4_location_constructors])
-m4_include(b4_pkgdatadir/[location.cc])
+b4_percent_define_ifdef([[location_type]], [],
+  [# Backward compatibility.
+  m4_define([b4_location_constructors])
+  m4_include(b4_pkgdatadir/[location.cc])])
 
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
@@ -46,8 +47,9 @@ dnl FIXME: This is wrong, we want computed header guards.
 
 #include <string>
 #include <iostream>
-#include "location.hh"
 #include "stack.hh"
+]b4_percent_define_ifdef([[location_type]], [],
+                         [[#include "location.hh"]])[
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -106,7 +108,8 @@ b4_user_stype
     typedef YYSTYPE semantic_type;
 #endif
     /// Symbol locations.
-    typedef ]b4_percent_define_get([[location_type]])[ location_type;
+    typedef ]b4_percent_define_get([[location_type]],
+                                   [[location]])[ location_type;
     /// Tokens.
     struct token
     {
-- 
1.7.0.5






reply via email to

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