bison-patches
[Top][All Lists]
Advanced

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

[PATCH 6/8] lalr1.cc: do not create stack.hh without %defines


From: Akim Demaille
Subject: [PATCH 6/8] lalr1.cc: do not create stack.hh without %defines
Date: Tue, 31 Jul 2012 11:17:29 +0200

* data/stack.hh (b4_stack_define): New.
* data/lalr1.cc: Use it when %defines is not passed.
* tests/output.at: Adjust expected output.
---
 NEWS            |  3 ++-
 TODO            |  5 +++++
 data/lalr1.cc   | 18 ++++++++++--------
 data/stack.hh   | 42 +++++++++++++++++++++++++-----------------
 tests/output.at |  6 +++---
 5 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/NEWS b/NEWS
index ef01a6a..fa1b948 100644
--- a/NEWS
+++ b/NEWS
@@ -87,7 +87,8 @@ GNU Bison NEWS
 *** parser header (%defines) is no longer mandatory (lalr1.cc)
 
   In which case, if needed, the support classes are defined in the generated
-  parser, instead of additional files such as position.hh and location.hh.
+  parser, instead of additional files (location.hh, position.hh and
+  stack.hh).
 
 *** locations are no longer mandatory (lalr1.cc, glr.cc)
 
diff --git a/TODO b/TODO
index 9eb1092..1c5d358 100644
--- a/TODO
+++ b/TODO
@@ -10,6 +10,11 @@ b4_parser_declaration for instance.
 ** glr.cc: %defines
 it should not be mandatory.
 
+** stack.hh
+Get rid of it.  The original idea is nice, but actually it makes
+the code harder to follow, and uselessly different from the other
+skeletons.
+
 ** Variable names.
 What should we name `variant' and `lex_symbol'?
 
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 6e299d5..8cf2043 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -134,20 +134,22 @@ b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
 m4_define([b4_shared_declarations],
 [b4_percent_code_get([[requires]])[
 ]b4_parse_assert_if([# include <cassert>])[
-# include <stdexcept>
-# include <string>
+# include <deque>
 # include <iostream>
-
-]b4_YYDEBUG_define[
-
+# include <stdexcept>
+# include <string>]b4_defines_if([[
 # include "stack.hh"
 ]b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
-    [b4_defines_if([[# include "location.hh"]])])])[
+                                          [[# include "location.hh"]])])])[
+
+]b4_YYDEBUG_define[
 
 ]b4_namespace_open[
 
-]b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
-  [b4_defines_if([], [b4_position_define
+]b4_defines_if([],
+[b4_stack_define
+b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
+                                         [b4_position_define
 b4_location_define])])])[
 
 ]b4_variant_if([b4_variant_define])[
diff --git a/data/stack.hh b/data/stack.hh
index cea7b41..bd94eb2 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -18,23 +18,10 @@
 m4_pushdef([b4_copyright_years],
            [2002-2012])
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
address@hidden(b4_dir_prefix[]stack.hh@)@
-b4_copyright([Stack handling for Bison parsers in C++])[
-
-/**
- ** \file ]b4_dir_prefix[stack.hh
- ** Define the ]b4_namespace_ref[::stack class.
- */
-
-]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
-
-# include <deque>
-
-]b4_namespace_open[
-  template <class T, class S = std::deque<T> >
+# b4_stack_define
+# ---------------
+m4_define([b4_stack_define],
+[[  template <class T, class S = std::deque<T> >
   class stack
   {
   public:
@@ -129,9 +116,30 @@ b4_copyright([Stack handling for Bison parsers in C++])[
     const S& stack_;
     unsigned int range_;
   };
+]])
+
+b4_defines_if(
+[# We do want M4 expansion after # for CPP macros.
+m4_changecom()
+m4_divert_push(0)dnl
address@hidden(b4_dir_prefix[]stack.hh@)@
+b4_copyright([Stack handling for Bison parsers in C++])[
+
+/**
+ ** \file ]b4_dir_prefix[stack.hh
+ ** Define the ]b4_namespace_ref[::stack class.
+ */
+
+]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
+
+# include <deque>
+
+]b4_namespace_open[
+]b4_stack_define[
 ]b4_namespace_close[
 
 ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
 m4_divert_pop(0)
 m4_popdef([b4_copyright_years])dnl
 m4_changecom([#])
+])
diff --git a/tests/output.at b/tests/output.at
index e8019c2..400f5c2 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -114,13 +114,13 @@ AT_CHECK([grep 'include .subdir/' $1.hh], 1, [])
 ])
 
 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose], [],
-                [foo.tab.cc foo.output stack.hh])
+                [foo.tab.cc foo.output])
 
 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %defines %verbose], [],
-                [foo.tab.cc foo.tab.hh foo.output stack.hh])
+                [foo.tab.cc foo.tab.hh foo.output])
 
 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %verbose %locations], [],
-                [foo.tab.cc foo.output stack.hh])
+                [foo.tab.cc foo.output])
 
 AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %defines %verbose %locations], 
[],
                 [foo.tab.cc foo.tab.hh foo.output location.hh stack.hh 
position.hh])
-- 
1.7.11.3




reply via email to

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