m4: use a safer pattern to enable/disable output

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.
This commit is contained in:
Akim Demaille
2012-12-03 15:29:44 +01:00
parent 6ee95cd0d9
commit 1c7ec959b1
8 changed files with 64 additions and 48 deletions

View File

@@ -58,6 +58,30 @@ This special exception was added by the Free Software Foundation in
version 2.2 of Bison.])]) 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
@output(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. ## ## Error handling. ##
## ---------------- ## ## ---------------- ##

View File

@@ -179,13 +179,10 @@ m4_define([b4_shared_declarations],
## Output files. ## ## Output files. ##
## -------------- ## ## -------------- ##
# We do want M4 expansion after # for CPP macros. b4_output_begin([b4_parser_file_name])
m4_changecom()
m4_divert_push(0)dnl
@output(b4_parser_file_name@)@
b4_copyright([Skeleton implementation for Bison GLR parsers in C], b4_copyright([Skeleton implementation for Bison GLR parsers in C],
[2002-2012]) [2002-2012])[
[
/* C GLR parser skeleton written by Paul Hilfinger. */ /* C GLR parser skeleton written by Paul Hilfinger. */
]b4_identification ]b4_identification
@@ -2571,17 +2568,17 @@ yypdumpstack (yyGLRStack* yystackp)
} }
#endif #endif
]b4_epilogue[]dnl ]b4_epilogue[]dnl
dnl b4_output_end()
dnl glr.cc produces its own header.
dnl # glr.cc produces its own header.
m4_if(b4_skeleton, ["glr.c"], m4_if(b4_skeleton, ["glr.c"],
[b4_defines_if( [b4_defines_if(
[@output(b4_spec_defines_file@)@ [b4_output_begin([b4_spec_defines_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C], b4_copyright([Skeleton interface for Bison GLR parsers in C],
[2002-2012])[ [2002-2012])[
]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_cpp_guard_open([b4_spec_defines_file])[
]b4_shared_declarations[ ]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_defines_file])[ ]b4_cpp_guard_close([b4_spec_defines_file])[
]])])dnl ]b4_output_end()
m4_divert_pop(0) ])])

View File

@@ -230,8 +230,7 @@ m4_defn([b4_parse_param]))],
m4_include(b4_pkgdatadir/[glr.c]) m4_include(b4_pkgdatadir/[glr.c])
m4_popdef([b4_parse_param]) m4_popdef([b4_parse_param])
m4_divert_push(0) b4_output_begin([b4_spec_defines_file])
@output(b4_spec_defines_file@)@
b4_copyright([Skeleton interface for Bison GLR parsers in C++], b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2006, 2009-2012])[ [2002-2006, 2009-2012])[
@@ -344,4 +343,4 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
]b4_namespace_close[ ]b4_namespace_close[
]b4_percent_code_get([[provides]])[ ]b4_percent_code_get([[provides]])[
]b4_cpp_guard_close([b4_spec_defines_file])[ ]b4_cpp_guard_close([b4_spec_defines_file])[
]m4_divert_pop(0) ]b4_output_end()

View File

@@ -30,11 +30,8 @@ b4_percent_define_ifdef([[api.location.type]], [],
m4_include(b4_pkgdatadir/[location.cc])]) m4_include(b4_pkgdatadir/[location.cc])])
m4_include(b4_pkgdatadir/[stack.hh]) 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( b4_defines_if(
[@output(b4_spec_defines_file@)@ [b4_output_begin([b4_spec_defines_file])
b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++], b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
[2002-2012]) [2002-2012])
[ [
@@ -265,8 +262,11 @@ b4_user_stype
])[ ])[
]b4_percent_code_get([[provides]])[ ]b4_percent_code_get([[provides]])[
]b4_cpp_guard_close([b4_spec_defines_file]) ]b4_cpp_guard_close([b4_spec_defines_file])
])dnl b4_output_end()
@output(b4_parser_file_name@)@ ])
b4_output_begin([b4_parser_file_name])
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++], b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
[2002-2012]) [2002-2012])
b4_percent_code_get([[top]])[]dnl b4_percent_code_get([[top]])[]dnl
@@ -1140,4 +1140,4 @@ b4_error_verbose_if([int yystate, int yytoken],
]b4_namespace_close[ ]b4_namespace_close[
]b4_epilogue[]dnl ]b4_epilogue[]dnl
m4_divert_pop(0) b4_output_end()

View File

@@ -22,8 +22,7 @@ m4_ifval(m4_defn([b4_symbol_destructors]),
[b4_fatal([%s: %%destructor does not make sense in Java], [b4_skeleton])], [b4_fatal([%s: %%destructor does not make sense in Java], [b4_skeleton])],
[]) [])
m4_divert_push(0)dnl b4_output_begin([b4_parser_file_name])
@output(b4_parser_file_name@)@
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
[2007-2012]) [2007-2012])
@@ -925,4 +924,4 @@ b4_percent_code_get[]dnl
} }
b4_epilogue b4_epilogue
m4_divert_pop(0)dnl b4_output_end()

View File

@@ -15,10 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# We do want M4 expansion after # for CPP macros.
m4_changecom() b4_output_begin([b4_dir_prefix[]position.hh])
m4_divert_push(0)dnl
@output(b4_dir_prefix[]position.hh@)@
b4_copyright([Positions for Bison parsers in C++], b4_copyright([Positions for Bison parsers in C++],
[2002-2007, 2009-2012])[ [2002-2007, 2009-2012])[
@@ -148,7 +146,10 @@ b4_copyright([Positions for Bison parsers in C++],
]b4_namespace_close[ ]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]position.hh]) ]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
@output(b4_dir_prefix[]location.hh@)@ b4_output_end()
b4_output_begin([b4_dir_prefix[]location.hh])
b4_copyright([Locations for Bison parsers in C++], b4_copyright([Locations for Bison parsers in C++],
[2002-2007, 2009-2012])[ [2002-2007, 2009-2012])[
@@ -292,5 +293,4 @@ b4_copyright([Locations for Bison parsers in C++],
]b4_namespace_close[ ]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) ]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
m4_divert_pop(0) b4_output_end()
m4_changecom([#])

View File

@@ -18,10 +18,7 @@
m4_pushdef([b4_copyright_years], m4_pushdef([b4_copyright_years],
[2002-2012]) [2002-2012])
# We do want M4 expansion after # for CPP macros. b4_output_begin([b4_dir_prefix[]stack.hh])
m4_changecom()
m4_divert_push(0)dnl
@output(b4_dir_prefix[]stack.hh@)@
b4_copyright([Stack handling for Bison parsers in C++], b4_copyright([Stack handling for Bison parsers in C++],
[2002-2012])[ [2002-2012])[
@@ -119,6 +116,6 @@ b4_copyright([Stack handling for Bison parsers in C++],
]b4_namespace_close[ ]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
m4_divert_pop(0) b4_output_end()
m4_popdef([b4_copyright_years])dnl
m4_changecom([#]) m4_popdef([b4_copyright_years])

View File

@@ -326,14 +326,12 @@ m4_define([b4_shared_declarations],
]b4_cpp_guard_close([b4_spec_defines_file])[]dnl ]b4_cpp_guard_close([b4_spec_defines_file])[]dnl
]) ])
## -------------- ## ## -------------- ##
## Output files. ## ## Output files. ##
## -------------- ## ## -------------- ##
# We do want M4 expansion after # for CPP macros. b4_output_begin([b4_parser_file_name])
m4_changecom()
m4_divert_push(0)dnl
@output(b4_parser_file_name@)@
b4_copyright([Bison implementation for Yacc-like parsers in C], b4_copyright([Bison implementation for Yacc-like parsers in C],
[1984, 1989-1990, 2000-2012])[ [1984, 1989-1990, 2000-2012])[
@@ -2052,11 +2050,13 @@ yypushreturn:]])[
]b4_epilogue[]dnl ]b4_epilogue[]dnl
b4_output_end()
b4_defines_if( b4_defines_if(
[@output(b4_spec_defines_file@)@ [b4_output_begin([b4_spec_defines_file])[
b4_copyright([Bison interface for Yacc-like parsers in C], ]b4_copyright([Bison interface for Yacc-like parsers in C],
[1984, 1989-1990, 2000-2012])[ [1984, 1989-1990, 2000-2012])[
]b4_shared_declarations[ ]b4_shared_declarations[
]])dnl b4_defines_if ]b4_output_end()
m4_divert_pop(0) ])