bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/3] m4: use a safer pattern to enable/disable output


From: Akim Demaille
Subject: [PATCH 2/3] m4: use a safer pattern to enable/disable output
Date: Mon, 3 Dec 2012 16:05:43 +0100

Work on some other areas of Bison revealed that some macros expanded
to be expanded only once were actually expanded several times.  This
was due to the fact that changecom was not properly restored each
time, and macro names appearing in comments were then expanded.

Introduce begin/end macros which are easier to match that
changecom()/changecom(#).

* data/bison.m4 (b4_output_begin, b4_output_end): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/lalr1.java,
* data/location.cc, data/stack.hh, data/yacc.c:
Use them.
---
 data/bison.m4    | 24 ++++++++++++++++++++++++
 data/glr.c       | 21 +++++++++------------
 data/glr.cc      |  5 ++---
 data/lalr1.cc    | 14 +++++++-------
 data/lalr1.java  |  5 ++---
 data/location.cc | 14 +++++++-------
 data/stack.hh    | 11 ++++-------
 data/yacc.c      | 18 +++++++++---------
 8 files changed, 64 insertions(+), 48 deletions(-)

diff --git a/data/bison.m4 b/data/bison.m4
index fac86f2..a24b162 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -58,6 +58,30 @@ This special exception was added by the Free Software 
Foundation in
 version 2.2 of Bison.])])
 
 
+## -------- ##
+## Output.  ##
+## -------- ##
+
+# b4_output_begin(FILE)
+# ---------------------
+# Enable output, i.e., send to diversion 0, expand after "#", and
+# generate the tag to output into FILE.  Must be followed by EOL.
+m4_define([b4_output_begin],
+[m4_changecom()
+m4_divert_push(0)dnl
address@hidden(m4_unquote([$1])@)@dnl
+])
+
+
+# b4_output_end()
+# ---------------
+# Output nothing, restore # as comment character (no expansions after #).
+m4_define([b4_output_end],
+[m4_divert_pop(0)
+m4_changecom([#])
+])
+
+
 ## ---------------- ##
 ## Error handling.  ##
 ## ---------------- ##
diff --git a/data/glr.c b/data/glr.c
index b6aa545..cdefd50 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -179,13 +179,10 @@ m4_define([b4_shared_declarations],
 ## Output files.  ##
 ## -------------- ##
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
address@hidden(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
-             [2002-2012])
-[
+             [2002-2012])[
+
 /* C GLR parser skeleton written by Paul Hilfinger.  */
 
 ]b4_identification
@@ -2571,17 +2568,17 @@ yypdumpstack (yyGLRStack* yystackp)
 }
 #endif
 ]b4_epilogue[]dnl
-dnl
-dnl glr.cc produces its own header.
-dnl
+b4_output_end()
+
+# glr.cc produces its own header.
 m4_if(b4_skeleton, ["glr.c"],
 [b4_defines_if(
address@hidden(b4_spec_defines_file@)@
+[b4_output_begin([b4_spec_defines_file])
 b4_copyright([Skeleton interface for Bison GLR parsers in C],
              [2002-2012])[
 
 ]b4_cpp_guard_open([b4_spec_defines_file])[
 ]b4_shared_declarations[
 ]b4_cpp_guard_close([b4_spec_defines_file])[
-]])])dnl
-m4_divert_pop(0)
+]b4_output_end()
+])])
diff --git a/data/glr.cc b/data/glr.cc
index 0e53d61..49b4fa1 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -230,8 +230,7 @@ m4_defn([b4_parse_param]))],
 m4_include(b4_pkgdatadir/[glr.c])
 m4_popdef([b4_parse_param])
 
-m4_divert_push(0)
address@hidden(b4_spec_defines_file@)@
+b4_output_begin([b4_spec_defines_file])
 b4_copyright([Skeleton interface for Bison GLR parsers in C++],
              [2002-2006, 2009-2012])[
 
@@ -344,4 +343,4 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
 ]b4_namespace_close[
 ]b4_percent_code_get([[provides]])[
 ]b4_cpp_guard_close([b4_spec_defines_file])[
-]m4_divert_pop(0)
+]b4_output_end()
diff --git a/data/lalr1.cc b/data/lalr1.cc
index e45b2e1..237b246 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -30,11 +30,8 @@ b4_percent_define_ifdef([[api.location.type]], [],
   m4_include(b4_pkgdatadir/[location.cc])])
 m4_include(b4_pkgdatadir/[stack.hh])
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
 b4_defines_if(
address@hidden(b4_spec_defines_file@)@
+[b4_output_begin([b4_spec_defines_file])
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
              [2002-2012])
 [
@@ -265,8 +262,11 @@ b4_user_stype
 ])[
 ]b4_percent_code_get([[provides]])[
 ]b4_cpp_guard_close([b4_spec_defines_file])
-])dnl
address@hidden(b4_parser_file_name@)@
+b4_output_end()
+])
+
+
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
              [2002-2012])
 b4_percent_code_get([[top]])[]dnl
@@ -1140,4 +1140,4 @@ b4_error_verbose_if([int yystate, int yytoken],
 
 ]b4_namespace_close[
 ]b4_epilogue[]dnl
-m4_divert_pop(0)
+b4_output_end()
diff --git a/data/lalr1.java b/data/lalr1.java
index d1410a1..e961fc5 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -22,8 +22,7 @@ m4_ifval(m4_defn([b4_symbol_destructors]),
         [b4_fatal([%s: %%destructor does not make sense in Java], 
[b4_skeleton])],
         [])
 
-m4_divert_push(0)dnl
address@hidden(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
              [2007-2012])
 
@@ -925,4 +924,4 @@ b4_percent_code_get[]dnl
 }
 
 b4_epilogue
-m4_divert_pop(0)dnl
+b4_output_end()
diff --git a/data/location.cc b/data/location.cc
index 49f5f34..58182a3 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -15,10 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
address@hidden(b4_dir_prefix[]position.hh@)@
+
+b4_output_begin([b4_dir_prefix[]position.hh])
 b4_copyright([Positions for Bison parsers in C++],
              [2002-2007, 2009-2012])[
 
@@ -148,7 +146,10 @@ b4_copyright([Positions for Bison parsers in C++],
 
 ]b4_namespace_close[
 ]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
address@hidden(b4_dir_prefix[]location.hh@)@
+b4_output_end()
+
+
+b4_output_begin([b4_dir_prefix[]location.hh])
 b4_copyright([Locations for Bison parsers in C++],
              [2002-2007, 2009-2012])[
 
@@ -292,5 +293,4 @@ b4_copyright([Locations for Bison parsers in C++],
 ]b4_namespace_close[
 
 ]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
-m4_divert_pop(0)
-m4_changecom([#])
+b4_output_end()
diff --git a/data/stack.hh b/data/stack.hh
index ddedc79..ab1049c 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -18,10 +18,7 @@
 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_output_begin([b4_dir_prefix[]stack.hh])
 b4_copyright([Stack handling for Bison parsers in C++],
              [2002-2012])[
 
@@ -119,6 +116,6 @@ b4_copyright([Stack handling for Bison parsers in C++],
 ]b4_namespace_close[
 
 ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
-m4_divert_pop(0)
-m4_popdef([b4_copyright_years])dnl
-m4_changecom([#])
+b4_output_end()
+
+m4_popdef([b4_copyright_years])
diff --git a/data/yacc.c b/data/yacc.c
index 0f31552..810e2b2 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -326,14 +326,12 @@ m4_define([b4_shared_declarations],
 ]b4_cpp_guard_close([b4_spec_defines_file])[]dnl
 ])
 
+
 ## -------------- ##
 ## Output files.  ##
 ## -------------- ##
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
address@hidden(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Bison implementation for Yacc-like parsers in C],
              [1984, 1989-1990, 2000-2012])[
 
@@ -2052,11 +2050,13 @@ yypushreturn:]])[
 
 
 ]b4_epilogue[]dnl
+b4_output_end()
+
 b4_defines_if(
address@hidden(b4_spec_defines_file@)@
-b4_copyright([Bison interface for Yacc-like parsers in C],
-             [1984, 1989-1990, 2000-2012])[
+[b4_output_begin([b4_spec_defines_file])[
+]b4_copyright([Bison interface for Yacc-like parsers in C],
+              [1984, 1989-1990, 2000-2012])[
 
 ]b4_shared_declarations[
-]])dnl b4_defines_if
-m4_divert_pop(0)
+]b4_output_end()
+])
-- 
1.8.0.1




reply via email to

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