From 5215919366833a0a37bb321189ad9d22398ab260 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 30 Nov 2012 11:15:12 +0100 Subject: [PATCH 1/7] glr.c: remove stray macro * data/glr.c (YYOPTIONAL_LOC): Remove, unused since commit 769a8ef9bcb5e14d0be9d0869f5dca20ab093930. --- data/glr.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/data/glr.c b/data/glr.c index 9bd95228..b6aa545c 100644 --- a/data/glr.c +++ b/data/glr.c @@ -306,13 +306,6 @@ b4_percent_code_get[]dnl # endif #endif -]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[ -#ifdef __cplusplus -# define YYOPTIONAL_LOC(Name) /* empty */ -#else -# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) -#endif])[ - #ifndef YYASSERT # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) #endif From 4c36bc2b8d65cb76480a30b3fcd2d7824ea12de9 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 30 Nov 2012 11:19:33 +0100 Subject: [PATCH 2/7] formatting changes * data/c.m4: Fix comments, put macros in a more natural order. Space changes (from M-x whitespace-cleanup). * src/location.c: Fix spaces. * tests/actions.at: Space changes. --- data/c.m4 | 50 ++++++++++++++++++++++++------------------------ src/location.c | 4 ++-- tests/actions.at | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/data/c.m4 b/data/c.m4 index 8bd96b85..c2f1a053 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -163,7 +163,7 @@ m4_define([b4_int_type], m4_eval([0 <= $1]), [1], [unsigned int], - [int])]) + [int])]) # b4_int_type_for(NAME) @@ -256,7 +256,7 @@ m4_define([b4_token_enums], enum ]b4_api_prefix[tokentype { ]m4_map_sep([ b4_token_enum], [, ], - [$@])[ + [$@])[ }; #endif ]])]) @@ -320,7 +320,7 @@ $1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl m4_define([b4_c_ansi_formals], [m4_if([$#], [0], [void], [$#$1], [1], [void], - [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) + [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) m4_define([b4_c_ansi_formal], [$1]) @@ -341,9 +341,9 @@ m4_define([b4_c_knr_formal_name], # Output the K&R argument declarations. m4_define([b4_c_knr_formal_decls], [m4_map_sep([b4_c_knr_formal_decl], - [ + [ ], - [$@])]) + [$@])]) m4_define([b4_c_knr_formal_decl], [ $1;]) @@ -355,9 +355,18 @@ m4_define([b4_c_knr_formal_decl], ## ------------------------------------------------------------ ## +# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) +# ---------------------------------------------------------------- +# Declare the function NAME ANSI C style. +m4_define([b4_c_ansi_function_decl], +[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl +]) + + + # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) # ----------------------------------------------------------- -# Declare the function NAME. +# Declare the function NAME in both K&R and ANSI C. m4_define([b4_c_function_decl], [#if defined __STDC__ || defined __cplusplus b4_c_ansi_function_decl($@) @@ -367,15 +376,6 @@ $2 $1 (); ]) -# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) -# ---------------------------------------------------------------- -# Declare the function NAME. -m4_define([b4_c_ansi_function_decl], -[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl -]) - - - ## --------------------- ## ## Calling C functions. ## @@ -432,9 +432,9 @@ m4_define([b4_symbol_actions], [b4_dollar_pushdef([(*yyvaluep)], [$6], [(*yylocationp)])dnl case $4: /* $3 */ b4_syncline([$2], [$1]) - $5; + $5; b4_syncline([@oline@], [@ofile@]) - break; + break; b4_dollar_popdef[]dnl ]) @@ -471,7 +471,7 @@ b4_parse_param_use[]dnl { ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ default: - break; + break; } }]dnl ]) @@ -491,9 +491,9 @@ m4_define_default([b4_yy_symbol_print_generate], /*ARGSUSED*/ ]$1([yy_symbol_value_print], [static void], - [[FILE *yyoutput], [yyoutput]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl + [[FILE *yyoutput], [yyoutput]], + [[int yytype], [yytype]], + [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { @@ -514,7 +514,7 @@ b4_parse_param_use[]dnl { ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl [ default: - break; + break; } } @@ -525,9 +525,9 @@ b4_parse_param_use[]dnl ]$1([yy_symbol_print], [static void], - [[FILE *yyoutput], [yyoutput]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl + [[FILE *yyoutput], [yyoutput]], + [[int yytype], [yytype]], + [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { diff --git a/src/location.c b/src/location.c index 11df5aa0..fa1b53cb 100644 --- a/src/location.c +++ b/src/location.c @@ -107,7 +107,7 @@ location_print (FILE *out, location loc) quotearg_n_style (3, escape_quoting_style, loc.start.file)); if (0 <= loc.start.line) { - res += fprintf(out, ":%d", loc.start.line); + res += fprintf (out, ":%d", loc.start.line); if (0 <= loc.start.column) res += fprintf (out, ".%d", loc.start.column); } @@ -118,7 +118,7 @@ location_print (FILE *out, location loc) loc.end.file)); if (0 <= loc.end.line) { - res += fprintf(out, ":%d", loc.end.line); + res += fprintf (out, ":%d", loc.end.line); if (0 <= end_col) res += fprintf (out, ".%d", end_col); } diff --git a/tests/actions.at b/tests/actions.at index e6df7551..f3af0ef7 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -365,7 +365,7 @@ input: V(input, $$, @$, ": /* Nothing */\n"); } | line input /* Right recursive to load the stack so that popping at - END can be exercised. */ + END can be exercised. */ { $$ = 2; V(input, $$, @$, ": "); From 3804aa260b956dd012adde3894767254422a5fcf Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 30 Nov 2012 11:19:43 +0100 Subject: [PATCH 3/7] yacc.c, glr.c: check and fix the display of locations In some case, negative column number could be displayed. Make YY_LOCATION_PRINT similar to bison's own implementation of locations. Since the macro is getting fat, make it a static function. Reported by Jonathan Fabrizio. * data/c.m4 (yy_location_print_define): Improve the implementation, and generate the yy_location_print_ function. Adjust YY_LOCATION_PRINT. * tests/actions.at (Location Print): New tests. --- THANKS | 1 + data/c.m4 | 42 +++++++++++++++++++++------ tests/actions.at | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 8 deletions(-) diff --git a/THANKS b/THANKS index 8ae024fb..218eea79 100644 --- a/THANKS +++ b/THANKS @@ -58,6 +58,7 @@ Jim Kent jkent@arch.sel.sony.com Jim Meyering jim@meyering.net Joel E. Denny joeldenny@joeldenny.org Johan van Selst johans@stack.nl +Jonathan Fabrizio jonathan.fabrizio@lrde.epita.fr Jonathan Nieder jrnieder@gmail.com Juan Manuel Guerrero juan.guerrero@gmx.de Kees Zeelenberg kzlg@users.sourceforge.net diff --git a/data/c.m4 b/data/c.m4 index c2f1a053..dc3d3036 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -655,14 +655,40 @@ m4_define([b4_yy_location_print_define], #ifndef YY_LOCATION_PRINT # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - do { \ - fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ - if ((Loc).first_line < (Loc).last_line) \ - fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ - else if ((Loc).first_column < (Loc).last_column - 1) \ - fprintf (File, "-%d", (Loc).last_column - 1); \ - } while (0) + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +__attribute__((__unused__)) +]b4_c_function_def([yy_location_print_], + [static unsigned], + [[FILE *yyo], [yyo]], + [[YYLTYPE const * const yylocp], [yylocp]])[ +{ + unsigned res = 0; + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; + if (0 <= yylocp->first_line) + { + res += fprintf (yyo, "%d", yylocp->first_line); + if (0 <= yylocp->first_column) + res += fprintf (yyo, ".%d", yylocp->first_column); + } + if (0 <= yylocp->last_line) + { + if (yylocp->first_line < yylocp->last_line) + { + res += fprintf (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += fprintf (yyo, ".%d", end_col); + } + else if (0 <= end_col && yylocp->first_column < end_col) + res += fprintf (yyo, "-%d", end_col); + } + return res; + } + +# define YY_LOCATION_PRINT(File, Loc) \ + yy_location_print_ (File, &(Loc)) + # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif diff --git a/tests/actions.at b/tests/actions.at index f3af0ef7..17e6085b 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -174,6 +174,81 @@ m4_popdef([AT_TEST]) +## ---------------- ## +## Location Print. ## +## ---------------- ## + +# AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1]) +# ----------------------------------------------------------------------- +# Check that the initial location is correct. +m4_pushdef([AT_TEST], +[AT_SETUP([Location print: $1 $2]) + +AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2]) +AT_DATA_GRAMMAR([[input.y]], +[[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */ +%locations +%debug +%skeleton "$1" +]$2[ +]$3[ +%code +{ +# include +# include // getenv +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ +} +%% +exp:; +%% +]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE[ + +int +main (void) +{ +#define TEST(L1, C1, L2, C2) \ + ]AT_LOC_FIRST_LINE[ = L1; \ + ]AT_LOC_FIRST_COLUMN[ = C1; \ + ]AT_LOC_LAST_LINE[ = L2; \ + ]AT_LOC_LAST_COLUMN[ = C2; \ + ]YY_LOCATION_PRINT(stdout, AT_LOC)[;\ + putchar ('\n'); + + TEST(1, 1, 1, 1); + TEST(2, 1, 2, 10); + TEST(3, 1, 4, 1); + TEST(5, 1, 6, 10); + + TEST(7, 2, 0, 2); + TEST(8, 0, 8, 0); +} +]]) + +AT_FULL_COMPILE([input]) +AT_PARSER_CHECK([./input], 0, +[[1.1 +2.1-9 +3.1-4.0 +5.1-6.9 +7.2 +8.0 +]]) +AT_BISON_OPTION_POPDEFS +AT_CLEANUP +]) + +## FIXME: test Java, and iterate over skeletons. +AT_TEST([yacc.c]) +AT_TEST([glr.c]) +#AT_TEST([lalr1.cc]) +#AT_TEST([glr.cc]) + +m4_popdef([AT_TEST]) + + + ## ---------------- ## ## Exotic Dollars. ## ## ---------------- ## From 8aef6e0db593eff8e7c1c10259d452fb5879e9e0 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 30 Nov 2012 12:17:10 +0100 Subject: [PATCH 4/7] gnulib: update * lib/yyerror.c: Include config.h since the following stdio.h might be from gnulib. --- gnulib | 2 +- lib/.gitignore | 6 ++++++ lib/yyerror.c | 2 ++ m4/.gitignore | 1 - 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gnulib b/gnulib index daf7f8c0..e6575738 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit daf7f8c02242c535d596231e2f655109b97fa2bc +Subproject commit e657573866e8aded3b3b1461c346cf9ad02a5148 diff --git a/lib/.gitignore b/lib/.gitignore index a5595ab9..15354476 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -272,3 +272,9 @@ /binary-io.c /mbuiter.c /xsize.c +/bitrotate.c +/math.c +/sig-handler.c +/stdio.c +/unistd.c +/wctype-h.c diff --git a/lib/yyerror.c b/lib/yyerror.c index c9f492f8..332e91e2 100644 --- a/lib/yyerror.c +++ b/lib/yyerror.c @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + #include int yyerror (char const *); diff --git a/m4/.gitignore b/m4/.gitignore index e85072b3..7d112490 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -48,7 +48,6 @@ /hash.m4 /iconv.m4 /include_next.m4 -/inline.m4 /intdiv0.m4 /intl.m4 /intldir.m4 From 6ee95cd0d900362be987c3910d634e20460d7ad0 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 3 Dec 2012 15:43:57 +0100 Subject: [PATCH 5/7] tests: beware of gnulib's need for config.h * tests/skeletons.at, tests/torture.at: Be sure to include config.h where appropriate. --- tests/skeletons.at | 4 ++-- tests/torture.at | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/skeletons.at b/tests/skeletons.at index 7b5b8f27..fa496c97 100644 --- a/tests/skeletons.at +++ b/tests/skeletons.at @@ -114,10 +114,10 @@ main (void) } ]]) -AT_DATA([[input-cmd-line.y]], +AT_DATA_GRAMMAR([[input-cmd-line.y]], [AT_GRAM]) -AT_DATA([[input-gram.y]], +AT_DATA_GRAMMAR([[input-gram.y]], [[%skeleton "yacc.c"] AT_GRAM]) diff --git a/tests/torture.at b/tests/torture.at index 5aa18900..ac9e91ea 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -269,6 +269,7 @@ print < # include # include @@ -383,7 +384,7 @@ m4_define([AT_DATA_STACK_TORTURE], [AT_BISON_OPTION_PUSHDEFS([$2]) # A grammar of parens growing the stack thanks to right recursion. # exp: -AT_DATA([input.y], +AT_DATA_GRAMMAR([input.y], [[%{ #include #include From 1c7ec959b1dddfbf594d5b76572e4b473c055be2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 3 Dec 2012 15:29:44 +0100 Subject: [PATCH 6/7] 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. --- 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 fac86f2a..a24b162c 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 +@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. ## ## ---------------- ## diff --git a/data/glr.c b/data/glr.c index b6aa545c..cdefd507 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 -@output(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( -[@output(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 0e53d619..49b4fa10 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) -@output(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 e45b2e1f..237b246f 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( -[@output(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 -@output(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 d1410a10..e961fc5b 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 -@output(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 49f5f349..58182a34 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 . -# We do want M4 expansion after # for CPP macros. -m4_changecom() -m4_divert_push(0)dnl -@output(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]) -@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++], [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 ddedc79b..ab1049c1 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 -@output(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 0f315523..810e2b21 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 -@output(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( -[@output(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() +]) From 03dbf629d54bab4b5903f35c881bb240511d1f39 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 3 Dec 2012 15:59:57 +0100 Subject: [PATCH 7/7] parser: accept #line NUM * src/scan-gram.l (scanner): Accept '#line NUM'. (handle_syncline): Adjust to the possible missing file name. --- src/scan-gram.l | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/scan-gram.l b/src/scan-gram.l index fd6458fa..5e78cb9b 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -157,7 +157,7 @@ splice (\\[ \f\t\v]*\n)* /* #line directives are not documented, and may be withdrawn or modified in future versions of Bison. */ - ^"#line "{int}" \"".*"\"\n" { + ^"#line "{int}(" \"".*"\"")?"\n" { handle_syncline (yytext + sizeof "#line " - 1, *loc); } } @@ -845,23 +845,27 @@ convert_ucn_to_byte (char const *ucn) } -/*----------------------------------------------------------------. -| Handle '#line INT "FILE"'. ARGS has already skipped '#line '. | -`----------------------------------------------------------------*/ +/*---------------------------------------------------------------------. +| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. | +`---------------------------------------------------------------------*/ static void handle_syncline (char *args, location loc) { - char *after_num; - unsigned long int lineno = strtoul (args, &after_num, 10); - char *file = mbschr (after_num, '"') + 1; - *mbschr (file, '"') = '\0'; + char *file; + unsigned long int lineno = strtoul (args, &file, 10); if (INT_MAX <= lineno) { warn_at (loc, _("line number overflow")); lineno = INT_MAX; } - current_file = uniqstr_new (file); + + file = mbschr (file, '"'); + if (file) + { + *mbschr (file + 1, '"') = '\0'; + current_file = uniqstr_new (file + 1); + } boundary_set (&scanner_cursor, current_file, lineno, 1); }