From: Akim Demaille Date: Mon, 3 Dec 2012 15:27:23 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/maint' X-Git-Tag: v2.7.90~265 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/064e42b0aca1db0ca84b06b01cac5a40f3016591?hp=5807bb9156930091850a52b5bb9ab9f89082b04e Merge remote-tracking branch 'origin/maint' * origin/maint: parser: accept #line NUM m4: use a safer pattern to enable/disable output tests: beware of gnulib's need for config.h gnulib: update yacc.c, glr.c: check and fix the display of locations formatting changes glr.c: remove stray macro Conflicts: data/c.m4 data/glr.cc data/lalr1.cc data/lalr1.java data/location.cc data/stack.hh data/yacc.c src/scan-gram.l --- diff --git a/THANKS b/THANKS index 0c6a8172..909a6e00 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/bison.m4 b/data/bison.m4 index c652b2ec..bd8af095 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -61,6 +61,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/c.m4 b/data/c.m4 index 91126a82..6c2f5525 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -610,14 +610,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 + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +__attribute__((__unused__)) +]b4_function_define([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) \ - 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) + yy_location_print_ (File, &(Loc)) + # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif diff --git a/data/glr.c b/data/glr.c index 9038c747..1e82e589 100644 --- a/data/glr.c +++ b/data/glr.c @@ -188,13 +188,10 @@ m4_if(b4_skeleton, ["glr.c"], ## 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 @@ -305,13 +302,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 @@ -2560,17 +2550,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 8841f10b..3cecfd8e 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -319,8 +319,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++], ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]m4_divert_pop(0) -m4_changecom[#])]) +]b4_output_end()]) # Let glr.c (and b4_shared_declarations) believe that the user # arguments include the parser itself. diff --git a/data/lalr1.cc b/data/lalr1.cc index 34eef138..fa3a48d4 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -352,12 +352,11 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file]) -m4_divert_pop(0)dnl +b4_output_end() ]) -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 C++]) b4_percent_code_get([[top]])[]dnl m4_if(b4_prefix, [yy], [], @@ -1141,5 +1140,7 @@ b4_error_verbose_if([state_type yystate, int yytoken], ]b4_token_ctor_if([], [b4_yytranslate_define])[ ]b4_namespace_close[ ]b4_epilogue[]dnl -m4_divert_pop(0) +b4_output_end() + + m4_popdef([b4_copyright_years])dnl diff --git a/data/lalr1.java b/data/lalr1.java index 1cfaef38..02079fd0 100644 --- a/data/lalr1.java +++ b/data/lalr1.java @@ -30,8 +30,7 @@ m4_define([b4_symbol_no_destructor_assert], [b4_symbol_action_location([$1], [destructor])])])]) b4_symbol_foreach([b4_symbol_no_destructor_assert]) -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]) @@ -874,4 +873,4 @@ b4_percent_code_get[]dnl } b4_epilogue[]dnl -m4_divert_pop(0)dnl +b4_output_end() diff --git a/data/location.cc b/data/location.cc index 5879ea37..b49028f9 100644 --- a/data/location.cc +++ b/data/location.cc @@ -268,8 +268,7 @@ m4_define([b4_location_define], # We do want M4 expansion after # for CPP macros. m4_changecom() b4_defines_if([ -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++])[ /** @@ -289,7 +288,10 @@ b4_copyright([Positions for Bison parsers in C++])[ ]b4_position_define[ ]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++])[ /** @@ -305,7 +307,8 @@ b4_copyright([Locations for Bison parsers in C++])[ ]b4_location_define[ ]b4_namespace_close[ ]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) -m4_divert_pop(0) -])# b4_defines_if -m4_popdef([b4_copyright_years])dnl -m4_changecom([#]) +b4_output_end() +]) + + +m4_popdef([b4_copyright_years]) diff --git a/data/stack.hh b/data/stack.hh index bd94eb2d..4fd136fd 100644 --- a/data/stack.hh +++ b/data/stack.hh @@ -119,10 +119,7 @@ m4_define([b4_stack_define], ]]) b4_defines_if( -[# 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++])[ /** @@ -139,7 +136,7 @@ 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 2b6d10ac..9bd80280 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -326,10 +326,7 @@ 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([Bison implementation for Yacc-like parsers in C])[ /* C LALR(1) parser skeleton written by Richard Stallman, by @@ -1941,11 +1938,12 @@ yypushreturn:]])[ return yyresult; } ]b4_epilogue[]dnl +b4_output_end() + b4_defines_if( -[@output(b4_spec_defines_file@)@ -b4_copyright([Bison interface for Yacc-like parsers in C])[ +[b4_output_begin([b4_spec_defines_file])[ +]b4_copyright([Bison interface for Yacc-like parsers in C])[ ]b4_shared_declarations[ -]])dnl b4_defines_if -m4_divert_pop(0) -m4_popdef([b4_copyright_years]) +]b4_output_end() +])# b4_defines_if diff --git a/lib/.gitignore b/lib/.gitignore index e62b99c3..ba37d129 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -273,3 +273,9 @@ /xstrndup.h /binary-io.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 3dfdf6ad..80193dbb 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -48,7 +48,6 @@ /hash.m4 /iconv.m4 /include_next.m4 -/inline.m4 /intdiv0.m4 /intl.m4 /intl.m4~ diff --git a/src/location.c b/src/location.c index a7494158..c27ad144 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/src/scan-gram.l b/src/scan-gram.l index f5c9b88f..e6f42ea9 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -193,7 +193,7 @@ eqopt ([[:space:]]*=)? /* #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); } } @@ -974,23 +974,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 = strchr (after_num, '"') + 1; - *strchr (file, '"') = '\0'; + char *file; + unsigned long int lineno = strtoul (args, &file, 10); if (INT_MAX <= lineno) { complain (&loc, Wother, _("line number overflow")); lineno = INT_MAX; } - current_file = uniqstr_new (file); + + file = strchr (file, '"'); + if (file) + { + *strchr (file + 1, '"') = '\0'; + current_file = uniqstr_new (file + 1); + } boundary_set (&scanner_cursor, current_file, lineno, 1); } diff --git a/tests/actions.at b/tests/actions.at index 8278293d..c148391d 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. ## ## ---------------- ## diff --git a/tests/skeletons.at b/tests/skeletons.at index dafc74da..8632df16 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