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: Tue, 4 May 2010 15:30:26 +0200

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.
---
 ChangeLog     |   11 +++++++++++
 data/bison.m4 |   13 ++++++++-----
 data/c++.m4   |   10 ++++++++--
 data/lalr1.cc |   11 ++++++-----
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4b9bb5e..216c2e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 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_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.
+
+2010-05-04  Akim Demaille  <address@hidden>
+
        lalr1.cc: minor refactoring.
        * data/lalr1.cc: Don't issue empty namespaces.
 
diff --git a/data/bison.m4 b/data/bison.m4
index 5a5df0f..079a5e5 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -563,10 +563,11 @@ m4_define([b4_percent_define_use],
 [m4_define([b4_percent_define_bison_variables(]$1[)])dnl
 ])
 
-# b4_percent_define_get(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
+# 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).
 #
@@ -575,7 +576,9 @@ m4_define([b4_percent_define_use],
 #   b4_percent_define_get([[foo]])
 m4_define([b4_percent_define_get],
 [b4_percent_define_use([$1])dnl
-m4_ifdef([b4_percent_define(]$1[)], [m4_indir([b4_percent_define(]$1[)])])])
+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 80c7451..6033e17 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -24,7 +24,12 @@ m4_include(b4_pkgdatadir/[c.m4])
 ## ---------------- ##
 
 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_type]])
+
 b4_percent_define_default([[filename_type]], [[std::string]])
 b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
 
@@ -123,7 +128,8 @@ m4_define([b4_public_types_declare],
     typedef YYSTYPE semantic_type;
 #endif]b4_locations_if([
     /// Symbol locations.
-    typedef b4_percent_define_get([[location_type]]) location_type;])[
+    typedef b4_percent_define_get([[location_type]],
+                                  [[location]]) location_type;])[
 
     /// Syntax errors thrown from user actions.
     struct syntax_error : std::runtime_error
diff --git a/data/lalr1.cc b/data/lalr1.cc
index b0b075c..7cb7db6 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -124,10 +124,10 @@ m4_define([b4_parser_class_name],
 b4_defines_if([],
               [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
 
-b4_locations_if(
-[# Backward compatibility.
-m4_define([b4_location_constructors])
-m4_include(b4_pkgdatadir/[location.cc])])
+b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
+  [# Backward compatibility.
+  m4_define([b4_location_constructors])
+  m4_include(b4_pkgdatadir/[location.cc])])])
 m4_include(b4_pkgdatadir/[stack.hh])
 b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
 
@@ -149,8 +149,9 @@ dnl FIXME: This is wrong, we want computed header guards.
 #include <stdexcept>
 #include <string>
 #include <iostream>
-]b4_locations_if([#include "location.hh"])[
 #include "stack.hh"
+]b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
+                                          [[#include "location.hh"]])])[
 
 ]b4_variant_if([b4_namespace_open
 b4_variant_define
-- 
1.7.0.5






reply via email to

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