From 4f4a54ab92aeea1b6ea7ebced11ef58a35e090c8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 25 Oct 2012 14:45:36 +0200 Subject: [PATCH 01/24] yacc.c: don't use _Pragma GCC diagnostic with 4.6 Reported by Peter Simons. http://lists.gnu.org/archive/html/bug-bison/2012-10/msg00033.html * data/yacc.c (b4_declare_scanner_communication_variables): 4.7 seems fine though. --- THANKS | 1 + data/yacc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/THANKS b/THANKS index b6a2b2d8..ee05b564 100644 --- a/THANKS +++ b/THANKS @@ -87,6 +87,7 @@ Paul Hilfinger Hilfinger@CS.Berkeley.EDU Per Allansson per@appgate.com Peter Fales psfales@lucent.com Peter Hamorsky hamo@upjs.sk +Peter Simons simons@cryp.to Piotr Gackiewicz gacek@intertel.com.pl Quoc Peyrot chojin@lrde.epita.fr R Blake blakers@mac.com diff --git a/data/yacc.c b/data/yacc.c index 1b3dc752..3b111d12 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -171,7 +171,7 @@ m4_define([b4_declare_scanner_communication_variables], [[ int yychar; ]b4_pure_if([[ -#if defined __GNUC__ && (4 < __GNUC__ + (6 <= __GNUC_MINOR__)) +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ From 0fb7b95c5fd7812b0700dd1a088513626129252f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 25 Oct 2012 14:49:11 +0200 Subject: [PATCH 02/24] regen --- src/parse-gram.c | 6 +++--- src/parse-gram.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/parse-gram.c b/src/parse-gram.c index 2c08b106..5b063793 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.4.11-d01f-dirty. */ +/* A Bison parser, made by GNU Bison 2.6.4.9-5fb07-dirty. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.6.4.11-d01f-dirty" +#define YYBISON_VERSION "2.6.4.9-5fb07-dirty" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -1877,7 +1877,7 @@ yyparse () int yychar; -#if defined __GNUC__ && (4 < __GNUC__ + (6 <= __GNUC_MINOR__)) +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ diff --git a/src/parse-gram.h b/src/parse-gram.h index 39e29986..4b1247a6 100644 --- a/src/parse-gram.h +++ b/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.4.11-d01f-dirty. */ +/* A Bison parser, made by GNU Bison 2.6.4.9-5fb07-dirty. */ /* Bison interface for Yacc-like parsers in C From a68b1f237e63c96ee905916424013f79d01908ba Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 26 Oct 2012 11:25:41 +0200 Subject: [PATCH 03/24] yacc.c: initialize yylval and yylloc. When generating a pure push parser, the initialization of yylval and yylloc may not be visible to the compiler. With warnings enabled, GCC 4.3.6, 4.4.7, 4.5.4, and 4.6.3 report uninitialized uses of yylval/yylloc. Using local pragmas to disable these warnings is not supported before 4.6, and 4.6 does not support it properly. So initialize yylval and yylloc at their definition. Reported by Peter Simons. See http://lists.gnu.org/archive/html/bison-patches/2012-10/msg00133.html * data/c.m4 (b4_yyloc_default_define): New. * data/yacc.c: Use it when locations are requested. (YYLVAL_INITIALIZE): Replace by... (YY_INITIAL_VALUE): this. (yyparse): Initialize yylloc and yylval. Therefore, remove the initialization of yylloc's field. * data/glr.c: Likewise. --- NEWS | 11 +++++++++++ data/c.m4 | 16 ++++++++++++++++ data/glr.c | 21 ++++++++------------- data/yacc.c | 24 +++++++++--------------- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index 895f55db..8c5bf593 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,17 @@ GNU Bison NEWS * Noteworthy changes in release ?.? (????-??-??) [?] + We consider compiler warnings about Bison generated parsers to be bugs. + Rather than working around them in your own project, please consider + reporting them to us. + +** Bug fixes + + Warnings about uninitialized yylval and/or yylloc for push parsers with a + pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to + 3.2. + + Other issues in the test suite have been addressed. * Noteworthy changes in release 2.6.4 (2012-10-23) [stable] diff --git a/data/c.m4 b/data/c.m4 index 561900af..136b46e1 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -643,3 +643,19 @@ m4_define([b4_yylloc_default_define], while (YYID (0)) #endif ]]) + +# b4_yyloc_default_define +# ------------------------ +# Define yyloc_default, which can be used to initialize location +# variables. +m4_define([b4_yyloc_default_define], +[[static YYLTYPE yyloc_default +# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL + = { ]m4_join([, ], + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]), + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]))[ } +# endif + ;]dnl +]) diff --git a/data/glr.c b/data/glr.c index 79d6ffd0..89a76e3e 100644 --- a/data/glr.c +++ b/data/glr.c @@ -223,11 +223,11 @@ b4_percent_code_get([[top]])[ #endif /* Default (constant) value used for initialization for null - right-hand sides. Unlike the standard yacc.c template, - here we set the default value of $$ to a zeroed-out value. - Since the default value is undefined, this behavior is - technically correct. */ -static YYSTYPE yyval_default; + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ +static YYSTYPE yyval_default;]b4_locations_if([ +b4_yyloc_default_define])[ /* Copy the second part of user declarations. */ ]b4_user_post_prologue @@ -2295,14 +2295,9 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; - yylval = yyval_default; -]b4_locations_if([ -#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL - yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; - yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; -#endif -]) -m4_ifdef([b4_initial_action], [ + yylval = yyval_default;]b4_locations_if([ + yylloc = yyloc_default;])[ +]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([yylval], [], [yylloc])dnl /* User initialization code. */ b4_user_initial_action diff --git a/data/yacc.c b/data/yacc.c index 3b111d12..5d68bd4e 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -181,22 +181,23 @@ int yychar; #else /* Default value used for initialization, for pacifying older GCCs or non-GCC compilers. */ -static YYSTYPE yyval_default; -# define YYLVAL_INITIALIZE() (yylval = yyval_default) +static YYSTYPE yyval_default;]b4_locations_if([ +b4_yyloc_default_define])[ +# define YY_INITIAL_VALUE(Value) = Value #endif]])[ -#ifndef YYLVAL_INITIALIZE -# define YYLVAL_INITIALIZE() -#endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval;]b4_locations_if([[ +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);]b4_locations_if([[ /* Location data for the lookahead symbol. */ -YYLTYPE yylloc;]])b4_pure_if([], [[ +YYLTYPE yylloc YY_INITIAL_VALUE(yyloc_default);]])b4_pure_if([], [[ /* Number of syntax errors so far. */ int yynerrs;]])]) @@ -1581,14 +1582,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ yyssp = yyss; yyvsp = yyvs;]b4_locations_if([[ yylsp = yyls;]])[ - - YYLVAL_INITIALIZE ();]b4_locations_if([[ -#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[; - yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[; -#endif]]) -m4_ifdef([b4_initial_action],[ +]m4_ifdef([b4_initial_action],[ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [m4_define([b4_at_dollar_used])yylloc])dnl /* User initialization code. */ From a21733f2b4c25558b81b340270b685460e14a8bb Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 26 Oct 2012 14:23:18 +0200 Subject: [PATCH 04/24] regen --- src/parse-gram.c | 298 +++++++++++++++++++++++------------------------ src/parse-gram.h | 6 +- 2 files changed, 151 insertions(+), 153 deletions(-) diff --git a/src/parse-gram.c b/src/parse-gram.c index 5b063793..a02e68b6 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.4.9-5fb07-dirty. */ +/* A Bison parser, made by GNU Bison 2.6.4.15-c3a5a-dirty. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.6.4.9-5fb07-dirty" +#define YYBISON_VERSION "2.6.4.15-c3a5a-dirty" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -72,7 +72,7 @@ #define yylloc gram_lloc /* Copy the first part of user declarations. */ -/* Line 358 of yacc.c */ +/* Line 359 of yacc.c */ #line 1 "parse-gram.y" /* Bison Grammar Parser -*- C -*- @@ -168,7 +168,7 @@ current_lhs(symbol *sym, location loc, named_ref *ref) #define YYTYPE_UINT16 uint_fast16_t #define YYTYPE_UINT8 uint_fast8_t -/* Line 358 of yacc.c */ +/* Line 359 of yacc.c */ #line 173 "parse-gram.c" # ifndef YY_NULL @@ -334,7 +334,7 @@ extern int gram_debug; #if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED typedef union GRAM_STYPE { -/* Line 374 of yacc.c */ +/* Line 375 of yacc.c */ #line 115 "parse-gram.y" symbol *symbol; @@ -348,7 +348,7 @@ typedef union GRAM_STYPE named_ref *named_ref; -/* Line 374 of yacc.c */ +/* Line 375 of yacc.c */ #line 353 "parse-gram.c" } GRAM_STYPE; # define GRAM_STYPE_IS_TRIVIAL 1 @@ -388,7 +388,7 @@ int gram_parse (); /* Copy the second part of user declarations. */ -/* Line 377 of yacc.c */ +/* Line 378 of yacc.c */ #line 393 "parse-gram.c" #ifdef short @@ -1078,129 +1078,129 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) switch (yytype) { case 3: /* "string" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 205 "parse-gram.y" { fputs (quotearg_style (c_quoting_style, ((*yyvaluep).chars)), stderr); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1086 "parse-gram.c" break; case 4: /* "integer" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 217 "parse-gram.y" { fprintf (stderr, "%d", ((*yyvaluep).integer)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1093 "parse-gram.c" break; case 43: /* "{...}" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 207 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", ((*yyvaluep).code)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1100 "parse-gram.c" break; case 44: /* "[identifier]" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 212 "parse-gram.y" { fprintf (stderr, "[%s]", ((*yyvaluep).uniqstr)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1107 "parse-gram.c" break; case 45: /* "char" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 199 "parse-gram.y" { fputs (char_name (((*yyvaluep).character)), stderr); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1114 "parse-gram.c" break; case 46: /* "epilogue" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 207 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", ((*yyvaluep).chars)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1121 "parse-gram.c" break; case 48: /* "identifier" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 211 "parse-gram.y" { fputs (((*yyvaluep).uniqstr), stderr); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1128 "parse-gram.c" break; case 49: /* "identifier:" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 213 "parse-gram.y" { fprintf (stderr, "%s:", ((*yyvaluep).uniqstr)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1135 "parse-gram.c" break; case 52: /* "%{...%}" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 207 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", ((*yyvaluep).chars)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1142 "parse-gram.c" break; case 54: /* "type" */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 214 "parse-gram.y" { fprintf (stderr, "<%s>", ((*yyvaluep).uniqstr)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1149 "parse-gram.c" break; case 71: /* symbol.prec */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 220 "parse-gram.y" { fprintf (stderr, "%s", ((*yyvaluep).symbol)->tag); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1156 "parse-gram.c" break; case 84: /* variable */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 211 "parse-gram.y" { fputs (((*yyvaluep).uniqstr), stderr); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1163 "parse-gram.c" break; case 85: /* content.opt */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 207 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", ((*yyvaluep).chars)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1170 "parse-gram.c" break; case 86: /* braceless */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 207 "parse-gram.y" { fprintf (stderr, "{\n%s\n}", ((*yyvaluep).chars)); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1177 "parse-gram.c" break; case 87: /* id */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 220 "parse-gram.y" { fprintf (stderr, "%s", ((*yyvaluep).symbol)->tag); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1184 "parse-gram.c" break; case 88: /* id_colon */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 221 "parse-gram.y" { fprintf (stderr, "%s:", ((*yyvaluep).symbol)->tag); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1191 "parse-gram.c" break; case 89: /* symbol */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 220 "parse-gram.y" { fprintf (stderr, "%s", ((*yyvaluep).symbol)->tag); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1198 "parse-gram.c" break; case 90: /* string_as_id */ -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 220 "parse-gram.y" { fprintf (stderr, "%s", ((*yyvaluep).symbol)->tag); }; -/* Line 828 of yacc.c */ +/* Line 829 of yacc.c */ #line 1205 "parse-gram.c" break; default: @@ -1888,21 +1888,26 @@ int yychar; /* Default value used for initialization, for pacifying older GCCs or non-GCC compilers. */ static YYSTYPE yyval_default; -# define YYLVAL_INITIALIZE() (yylval = yyval_default) -#endif -#ifndef YYLVAL_INITIALIZE -# define YYLVAL_INITIALIZE() +static YYLTYPE yyloc_default +# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif + ; +# define YY_INITIAL_VALUE(Value) = Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc YY_INITIAL_VALUE(yyloc_default); /* Number of syntax errors so far. */ int yynerrs; @@ -1991,15 +1996,8 @@ YYLTYPE yylloc; yyvsp = yyvs; yylsp = yyls; - YYLVAL_INITIALIZE (); -#if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif - /* User initialization code. */ -/* Line 1591 of yacc.c */ +/* Line 1585 of yacc.c */ #line 107 "parse-gram.y" { /* Bison's grammar can initial empty locations, hence a default @@ -2007,8 +2005,8 @@ YYLTYPE yylloc; boundary_set (&yylloc.start, current_file, 1, 1); boundary_set (&yylloc.end, current_file, 1, 1); } -/* Line 1591 of yacc.c */ -#line 2012 "parse-gram.c" +/* Line 1585 of yacc.c */ +#line 2010 "parse-gram.c" yylsp[0] = yylloc; goto yysetstate; @@ -2202,7 +2200,7 @@ yyreduce: switch (yyn) { case 6: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 246 "parse-gram.y" { code_props plain_code; @@ -2216,13 +2214,13 @@ yyreduce: break; case 7: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 255 "parse-gram.y" { debug = true; } break; case 8: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 257 "parse-gram.y" { muscle_percent_define_insert ((yyvsp[(2) - (3)].uniqstr), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].chars), @@ -2231,13 +2229,13 @@ yyreduce: break; case 9: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 261 "parse-gram.y" { defines_flag = true; } break; case 10: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 263 "parse-gram.y" { defines_flag = true; @@ -2246,37 +2244,37 @@ yyreduce: break; case 11: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 267 "parse-gram.y" { error_verbose = true; } break; case 12: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 268 "parse-gram.y" { expected_sr_conflicts = (yyvsp[(2) - (2)].integer); } break; case 13: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 269 "parse-gram.y" { expected_rr_conflicts = (yyvsp[(2) - (2)].integer); } break; case 14: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 270 "parse-gram.y" { spec_file_prefix = (yyvsp[(2) - (2)].chars); } break; case 15: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 271 "parse-gram.y" { spec_file_prefix = (yyvsp[(3) - (3)].chars); } break; case 16: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 273 "parse-gram.y" { nondeterministic_parser = true; @@ -2285,7 +2283,7 @@ yyreduce: break; case 17: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 278 "parse-gram.y" { code_props action; @@ -2298,67 +2296,67 @@ yyreduce: break; case 18: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 286 "parse-gram.y" { language_argmatch ((yyvsp[(2) - (2)].chars), grammar_prio, (yylsp[(1) - (2)])); } break; case 19: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 287 "parse-gram.y" { add_param ("lex_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); } break; case 20: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 288 "parse-gram.y" { locations_flag = true; } break; case 21: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 289 "parse-gram.y" { spec_name_prefix = (yyvsp[(2) - (2)].chars); } break; case 22: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 290 "parse-gram.y" { spec_name_prefix = (yyvsp[(3) - (3)].chars); } break; case 23: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 291 "parse-gram.y" { no_lines_flag = true; } break; case 24: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 292 "parse-gram.y" { nondeterministic_parser = true; } break; case 25: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 293 "parse-gram.y" { spec_outfile = (yyvsp[(2) - (2)].chars); } break; case 26: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 294 "parse-gram.y" { spec_outfile = (yyvsp[(3) - (3)].chars); } break; case 27: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 295 "parse-gram.y" { add_param ("parse_param", (yyvsp[(2) - (2)].code), (yylsp[(2) - (2)])); } break; case 28: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 297 "parse-gram.y" { /* %pure-parser is deprecated in favor of `%define api.pure', so use @@ -2377,13 +2375,13 @@ yyreduce: break; case 29: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 311 "parse-gram.y" { version_check (&(yylsp[(2) - (2)]), (yyvsp[(2) - (2)].chars)); } break; case 30: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 313 "parse-gram.y" { char const *skeleton_user = (yyvsp[(2) - (2)].chars); @@ -2411,25 +2409,25 @@ yyreduce: break; case 31: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 336 "parse-gram.y" { token_table_flag = true; } break; case 32: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 337 "parse-gram.y" { report_flag |= report_states; } break; case 33: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 338 "parse-gram.y" { yacc_flag = true; } break; case 37: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 346 "parse-gram.y" { grammar_start_symbol_set ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)])); @@ -2437,7 +2435,7 @@ yyreduce: break; case 38: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 350 "parse-gram.y" { code_props code; @@ -2453,7 +2451,7 @@ yyreduce: break; case 39: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 362 "parse-gram.y" { code_props code; @@ -2469,7 +2467,7 @@ yyreduce: break; case 40: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 374 "parse-gram.y" { default_prec = true; @@ -2477,7 +2475,7 @@ yyreduce: break; case 41: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 378 "parse-gram.y" { default_prec = false; @@ -2485,7 +2483,7 @@ yyreduce: break; case 42: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 382 "parse-gram.y" { /* Do not invoke muscle_percent_code_grow here since it invokes @@ -2496,7 +2494,7 @@ yyreduce: break; case 43: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 389 "parse-gram.y" { muscle_percent_code_grow ((yyvsp[(2) - (3)].uniqstr), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].chars), (yylsp[(3) - (3)])); @@ -2505,19 +2503,19 @@ yyreduce: break; case 44: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 403 "parse-gram.y" {} break; case 45: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 404 "parse-gram.y" { muscle_code_grow ("union_name", (yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 46: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 409 "parse-gram.y" { union_seen = true; @@ -2527,13 +2525,13 @@ yyreduce: break; case 47: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 420 "parse-gram.y" { current_class = nterm_sym; } break; case 48: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 421 "parse-gram.y" { current_class = unknown_sym; @@ -2542,13 +2540,13 @@ yyreduce: break; case 49: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 425 "parse-gram.y" { current_class = token_sym; } break; case 50: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 426 "parse-gram.y" { current_class = unknown_sym; @@ -2557,7 +2555,7 @@ yyreduce: break; case 51: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 431 "parse-gram.y" { symbol_list *list; @@ -2569,7 +2567,7 @@ yyreduce: break; case 52: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 442 "parse-gram.y" { symbol_list *list; @@ -2585,109 +2583,109 @@ yyreduce: break; case 53: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 456 "parse-gram.y" { (yyval.assoc) = left_assoc; } break; case 54: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 457 "parse-gram.y" { (yyval.assoc) = right_assoc; } break; case 55: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 458 "parse-gram.y" { (yyval.assoc) = non_assoc; } break; case 56: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 462 "parse-gram.y" { current_type = NULL; } break; case 57: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 463 "parse-gram.y" { current_type = (yyvsp[(1) - (1)].uniqstr); tag_seen = true; } break; case 58: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 469 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 59: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 471 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), symbol_list_sym_new ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]))); } break; case 60: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 475 "parse-gram.y" { (yyval.symbol) = (yyvsp[(1) - (1)].symbol); } break; case 61: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 476 "parse-gram.y" { (yyval.symbol) = (yyvsp[(1) - (2)].symbol); symbol_user_token_number_set ((yyvsp[(1) - (2)].symbol), (yyvsp[(2) - (2)].integer), (yylsp[(2) - (2)])); } break; case 62: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 482 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 63: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 484 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), symbol_list_sym_new ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]))); } break; case 64: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 488 "parse-gram.y" { (yyval.list) = (yyvsp[(1) - (1)].list); } break; case 65: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 489 "parse-gram.y" { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].list)); } break; case 66: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 493 "parse-gram.y" { (yyval.list) = symbol_list_sym_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - (1)])); } break; case 67: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 494 "parse-gram.y" { (yyval.list) = symbol_list_type_new ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 68: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 495 "parse-gram.y" { (yyval.list) = symbol_list_default_tagged_new ((yylsp[(1) - (1)])); } break; case 69: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 496 "parse-gram.y" { (yyval.list) = symbol_list_default_tagless_new ((yylsp[(1) - (1)])); } break; case 70: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 502 "parse-gram.y" { current_type = (yyvsp[(1) - (1)].uniqstr); @@ -2696,7 +2694,7 @@ yyreduce: break; case 71: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 507 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (1)].symbol), current_class, (yylsp[(1) - (1)]), true); @@ -2705,7 +2703,7 @@ yyreduce: break; case 72: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 512 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true); @@ -2715,7 +2713,7 @@ yyreduce: break; case 73: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 518 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - (2)]), true); @@ -2725,7 +2723,7 @@ yyreduce: break; case 74: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 524 "parse-gram.y" { symbol_class_set ((yyvsp[(1) - (3)].symbol), current_class, (yylsp[(1) - (3)]), true); @@ -2736,7 +2734,7 @@ yyreduce: break; case 81: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 554 "parse-gram.y" { yyerrok; @@ -2744,13 +2742,13 @@ yyreduce: break; case 82: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 560 "parse-gram.y" { current_lhs ((yyvsp[(1) - (2)].symbol), (yylsp[(1) - (2)]), (yyvsp[(2) - (2)].named_ref)); } break; case 83: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 561 "parse-gram.y" { /* Free the current lhs. */ @@ -2759,86 +2757,86 @@ yyreduce: break; case 84: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 568 "parse-gram.y" { grammar_current_rule_end ((yylsp[(1) - (1)])); } break; case 85: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 569 "parse-gram.y" { grammar_current_rule_end ((yylsp[(3) - (3)])); } break; case 87: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 575 "parse-gram.y" { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location, current_lhs_named_ref); } break; case 88: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 578 "parse-gram.y" { grammar_current_rule_symbol_append ((yyvsp[(2) - (3)].symbol), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].named_ref)); } break; case 89: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 580 "parse-gram.y" { grammar_current_rule_action_append ((yyvsp[(2) - (3)].code), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].named_ref)); } break; case 90: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 582 "parse-gram.y" { grammar_current_rule_prec_set ((yyvsp[(3) - (3)].symbol), (yylsp[(3) - (3)])); } break; case 91: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 584 "parse-gram.y" { grammar_current_rule_dprec_set ((yyvsp[(3) - (3)].integer), (yylsp[(3) - (3)])); } break; case 92: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 586 "parse-gram.y" { grammar_current_rule_merge_set ((yyvsp[(3) - (3)].uniqstr), (yylsp[(3) - (3)])); } break; case 93: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 590 "parse-gram.y" { (yyval.named_ref) = 0; } break; case 94: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 592 "parse-gram.y" { (yyval.named_ref) = named_ref_new((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 96: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 604 "parse-gram.y" { (yyval.uniqstr) = uniqstr_new ((yyvsp[(1) - (1)].chars)); } break; case 97: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 609 "parse-gram.y" { (yyval.chars) = ""; } break; case 98: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 610 "parse-gram.y" { (yyval.chars) = (yyvsp[(1) - (1)].uniqstr); } break; case 100: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 621 "parse-gram.y" { code_props plain_code; @@ -2851,13 +2849,13 @@ yyreduce: break; case 101: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 641 "parse-gram.y" { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 102: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 643 "parse-gram.y" { (yyval.symbol) = symbol_get (char_name ((yyvsp[(1) - (1)].character)), (yylsp[(1) - (1)])); @@ -2867,13 +2865,13 @@ yyreduce: break; case 103: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 651 "parse-gram.y" { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[(1) - (1)].uniqstr), (yylsp[(1) - (1)])); } break; case 106: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 663 "parse-gram.y" { (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) - (1)].chars)), (yylsp[(1) - (1)])); @@ -2882,7 +2880,7 @@ yyreduce: break; case 108: -/* Line 1808 of yacc.c */ +/* Line 1802 of yacc.c */ #line 672 "parse-gram.y" { code_props plain_code; @@ -2895,8 +2893,8 @@ yyreduce: break; -/* Line 1808 of yacc.c */ -#line 2900 "parse-gram.c" +/* Line 1802 of yacc.c */ +#line 2898 "parse-gram.c" default: break; } if (yychar_backup != yychar) @@ -3146,7 +3144,7 @@ yyreturn: } -/* Line 2071 of yacc.c */ +/* Line 2065 of yacc.c */ #line 682 "parse-gram.y" diff --git a/src/parse-gram.h b/src/parse-gram.h index 4b1247a6..22b467e0 100644 --- a/src/parse-gram.h +++ b/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.4.9-5fb07-dirty. */ +/* A Bison parser, made by GNU Bison 2.6.4.15-c3a5a-dirty. */ /* Bison interface for Yacc-like parsers in C @@ -175,7 +175,7 @@ extern int gram_debug; #if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED typedef union GRAM_STYPE { -/* Line 2072 of yacc.c */ +/* Line 2066 of yacc.c */ #line 115 "parse-gram.y" symbol *symbol; @@ -189,7 +189,7 @@ typedef union GRAM_STYPE named_ref *named_ref; -/* Line 2072 of yacc.c */ +/* Line 2066 of yacc.c */ #line 194 "parse-gram.h" } GRAM_STYPE; # define GRAM_STYPE_IS_TRIVIAL 1 From 003db649bb79f7575cff199898c527b672bfe9fc Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 15:34:03 +0100 Subject: [PATCH 05/24] gnulib: update --- gnulib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnulib b/gnulib index d245e6dd..0dbbe3f5 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit d245e6ddd6ab2624d0d83acd8f111454f984f50f +Subproject commit 0dbbe3f55352241d290403577dfebed802d6fd9a From a7ab55af2a7bf441863c5e730e92a56c375c3880 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 15:36:44 +0100 Subject: [PATCH 06/24] autoconf: update There are comment changes only in the files we use. --- submodules/autoconf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/autoconf b/submodules/autoconf index 0db9c1a1..26cb0918 160000 --- a/submodules/autoconf +++ b/submodules/autoconf @@ -1 +1 @@ -Subproject commit 0db9c1a19fbbdbf8728ec8d9c5a020d070ec23b2 +Subproject commit 26cb0918d38d756b7c2a3f82226551f6facee47e From b720fedf831100246614059576a7bdac91dd2e71 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 15:38:32 +0100 Subject: [PATCH 07/24] comment changes * data/lalr1.cc: here. --- data/lalr1.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/data/lalr1.cc b/data/lalr1.cc index 82e68244..4eac6351 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -510,12 +510,12 @@ do { \ int yychar = yyempty_; int yytoken = 0; - /* State. */ + // State. int yyn; int yylen = 0; int yystate = 0; - /* Error handling. */ + // Error handling. int yynerrs_ = 0; int yyerrstatus_ = 0; @@ -580,7 +580,6 @@ b4_locations_if([, [[location*], [&yylloc]]])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; } - /* Convert token to internal form. */ if (yychar <= yyeof_) { From 623a5147e67ac2f657f23fcedb660df87515c806 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 16:11:13 +0100 Subject: [PATCH 08/24] tests: cosmetic changes * tests/actions.at (AT_CHECK_PRINTER_AND_DESTRUCTOR): Improve the displayed title. --- tests/actions.at | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 1ec8ef9a..9ec02372 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -557,7 +557,7 @@ AT_BISON_OPTION_POPDEFS # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG]) # --------------------------------------------------------------------------- m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR], -[AT_SETUP([Printers and Destructors $2: $1]) +[AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]])) $3 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4], @@ -572,13 +572,13 @@ AT_CLEANUP AT_CHECK_PRINTER_AND_DESTRUCTOR([]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([], [ with union]) AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [ with union]) AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [ with union]) From baf0bd614507a86f280312e401dff03b4acb031f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 13:54:36 +0100 Subject: [PATCH 09/24] tests: sort * tests/regression.at (Invalid inputs, Invalid inputs with {}): Move to... * tests/input.at: here, for consistency. --- tests/input.at | 54 +++++++++++++++++++++++++++++++++++++++++++++ tests/regression.at | 52 ------------------------------------------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/tests/input.at b/tests/input.at index 07c3e873..cd1d6d6d 100644 --- a/tests/input.at +++ b/tests/input.at @@ -20,6 +20,60 @@ AT_BANNER([[Input Processing.]]) # Mostly test that we are robust to mistakes. +## ---------------- ## +## Invalid inputs. ## +## ---------------- ## + +AT_SETUP([Invalid inputs]) + +AT_DATA([input.y], +[[%% +? +default: 'a' } +%& +%a-does-not-exist +%- +%{ +]]) + +AT_BISON_CHECK([input.y], [1], [], +[[input.y:2.1: invalid character: '?' +input.y:3.14: invalid character: '}' +input.y:4.1: invalid character: '%' +input.y:4.2: invalid character: '&' +input.y:5.1-17: invalid directive: '%a-does-not-exist' +input.y:6.1: invalid character: '%' +input.y:6.2: invalid character: '-' +input.y:7.1-8.0: missing '%}' at end of file +input.y:7.1-8.0: syntax error, unexpected %{...%} +]]) + +AT_CLEANUP + + +AT_SETUP([Invalid inputs with {}]) + +# We used to SEGV here. See +# http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html + +AT_DATA([input.y], +[[ +%destructor +%initial-action +%lex-param +%parse-param +%printer +%union +]]) + +AT_BISON_CHECK([input.y], [1], [], +[[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} +]]) + +AT_CLEANUP + + + ## ------------ ## ## Invalid $n. ## ## ------------ ## diff --git a/tests/regression.at b/tests/regression.at index 758825c7..1087379e 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -383,58 +383,6 @@ AT_CLEANUP -## ---------------- ## -## Invalid inputs. ## -## ---------------- ## - - -AT_SETUP([Invalid inputs]) - -AT_DATA([input.y], -[[%% -? -default: 'a' } -%& -%a-does-not-exist -%- -%{ -]]) - -AT_BISON_CHECK([input.y], [1], [], -[[input.y:2.1: invalid character: '?' -input.y:3.14: invalid character: '}' -input.y:4.1: invalid character: '%' -input.y:4.2: invalid character: '&' -input.y:5.1-17: invalid directive: '%a-does-not-exist' -input.y:6.1: invalid character: '%' -input.y:6.2: invalid character: '-' -input.y:7.1-8.0: missing '%}' at end of file -input.y:7.1-8.0: syntax error, unexpected %{...%} -]]) - -AT_CLEANUP - - -AT_SETUP([Invalid inputs with {}]) - -AT_DATA([input.y], -[[ -%destructor -%initial-action -%lex-param -%parse-param -%printer -%union -]]) - -AT_BISON_CHECK([input.y], [1], [], -[[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} -]]) - -AT_CLEANUP - - - ## ------------------- ## ## Token definitions. ## ## ------------------- ## From 95066e92087dfe296b74d637cab4dfb8d8fc253b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 13:47:12 +0100 Subject: [PATCH 10/24] grammars: fix display of nul character in error message Reported by Marc Mendiola. http://lists.gnu.org/archive/html/help-bison/2012-10/msg00017.html * gnulib: Update to get quote_mem. * src/scan-gram.l: Use it. * tests/input.at (Invalid inputs): Additional checks. * tests/named-refs.at: Likewise. --- NEWS | 2 ++ THANKS | 1 + src/scan-gram.l | 4 ++-- tests/input.at | 27 +++++++++++++++++---------- tests/named-refs.at | 7 ++++++- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 8c5bf593..37b8e2c0 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ GNU Bison NEWS Other issues in the test suite have been addressed. + Nul characters are correctly displayed in error messages. + * Noteworthy changes in release 2.6.4 (2012-10-23) [stable] Bison 2.6.3's --version was incorrect. This release fixes this issue. diff --git a/THANKS b/THANKS index ee05b564..77d35be7 100644 --- a/THANKS +++ b/THANKS @@ -64,6 +64,7 @@ Laurent Mascherpa laurent.mascherpa@epita.fr Lie Yan lie.yan@kaust.edu.sa Magnus Fromreide magfr@lysator.liu.se Marc Autret autret_m@epita.fr +Marc Mendiola mmendiol@usc.edu Martin Jacobs martin.jacobs@arcor.de Martin Mokrejs mmokrejs@natur.cuni.cz Martin Nylin martin.nylin@linuxmail.org diff --git a/src/scan-gram.l b/src/scan-gram.l index dbea2a1d..ad061cc6 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -291,7 +291,7 @@ splice (\\[ \f\t\v]*\n)* } . { - complain_at (*loc, _("invalid character: %s"), quote (yytext)); + complain_at (*loc, _("invalid character: %s"), quote_mem (yytext, yyleng)); } <> { @@ -375,7 +375,7 @@ splice (\\[ \f\t\v]*\n)* } . { complain_at (*loc, _("invalid character in bracketed name: %s"), - quote (yytext)); + quote_mem (yytext, yyleng)); } <> { BEGIN bracketed_id_context_state; diff --git a/tests/input.at b/tests/input.at index cd1d6d6d..2848562d 100644 --- a/tests/input.at +++ b/tests/input.at @@ -27,7 +27,8 @@ AT_BANNER([[Input Processing.]]) AT_SETUP([Invalid inputs]) AT_DATA([input.y], -[[%% +[[\000\001\002\377? +%% ? default: 'a' } %& @@ -35,17 +36,23 @@ default: 'a' } %- %{ ]]) +AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]]) AT_BISON_CHECK([input.y], [1], [], -[[input.y:2.1: invalid character: '?' -input.y:3.14: invalid character: '}' -input.y:4.1: invalid character: '%' -input.y:4.2: invalid character: '&' -input.y:5.1-17: invalid directive: '%a-does-not-exist' -input.y:6.1: invalid character: '%' -input.y:6.2: invalid character: '-' -input.y:7.1-8.0: missing '%}' at end of file -input.y:7.1-8.0: syntax error, unexpected %{...%} +[[input.y:1.1: invalid character: '\0' +input.y:1.1: invalid character: '\001' +input.y:1.1: invalid character: '\002' +input.y:1.1: invalid character: '\377' +input.y:1.2: invalid character: '?' +input.y:3.1: invalid character: '?' +input.y:4.14: invalid character: '}' +input.y:5.1: invalid character: '%' +input.y:5.2: invalid character: '&' +input.y:6.1-17: invalid directive: '%a-does-not-exist' +input.y:7.1: invalid character: '%' +input.y:7.2: invalid character: '-' +input.y:8.1-9.0: missing '%}' at end of file +input.y:8.1-9.0: syntax error, unexpected %{...%} ]]) AT_CLEANUP diff --git a/tests/named-refs.at b/tests/named-refs.at index 3ccf1f66..744eab82 100644 --- a/tests/named-refs.at +++ b/tests/named-refs.at @@ -443,14 +443,19 @@ AT_SETUP([Stray symbols in brackets]) AT_DATA_GRAMMAR([test.y], [[ %% -start: foo[ /* aaa */ *&-.+ ] bar +start: foo[ /* aaa */ *&-.+\000\001\002\377 ] bar { s = $foo; } ]]) +AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y || exit 77]]) AT_BISON_CHECK([-o test.c test.y], 1, [], [[test.y:11.23: invalid character in bracketed name: '*' test.y:11.24: invalid character in bracketed name: '&' test.y:11.25: invalid character in bracketed name: '-' test.y:11.27: invalid character in bracketed name: '+' +test.y:11.28: invalid character in bracketed name: '\0' +test.y:11.28: invalid character in bracketed name: '\001' +test.y:11.28: invalid character in bracketed name: '\002' +test.y:11.28: invalid character in bracketed name: '\377' ]]) AT_CLEANUP From 3112e7a82b61724d5a240a60ffeaee613431f85d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 2 Nov 2012 18:20:56 +0100 Subject: [PATCH 11/24] tests: simplifications * tests/actions.at (Exotic Dollars): Formatting changes. Use AT_FULL_COMPILE. (AT_CHECK_PRINTER_AND_DESTRUCTOR): Remove useless initialization of @$. --- tests/actions.at | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 9ec02372..b2d5e9d1 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -159,8 +159,7 @@ main (void) } ]]) -AT_BISON_CHECK([[-o input.c input.y]]) -AT_COMPILE([[input]]) +AT_FULL_COMPILE([input]) AT_PARSER_CHECK([[./input]], [[0]], [[6 ]]) @@ -305,7 +304,7 @@ line: $$ = -1; V(line, $$, @$, ": "); V('(', $1, @1, " "); - fprintf (stderr, "error (@%d-%d) ", RANGE(@2)); + fprintf (stderr, "error (@%d-%d) ", RANGE (@2)); V(')', $3, @3, "\n"); } ; @@ -595,10 +594,6 @@ AT_DATA_GRAMMAR([[input.y]], [[%error-verbose %debug %locations -%initial-action { - @$.first_line = @$.last_line = 1; - @$.first_column = @$.last_column = 1; -} %{ # include @@ -1237,7 +1232,7 @@ AT_CHECK_ACTION_LOCATIONS([[%printer]]) # Check that we can used qualified $$ (v.g., $$) not only in # rule actions, but also where $$ is valid: %printer and %destructor. # -# FIXME: Not actually checking %desctructor, but it's the same code as +# FIXME: Not actually checking %destructor, but it's the same code as # %printer... # # To do that, use a semantic value that has two fields (sem_type), From 3472de825e2ffcafee51cc5e81a031e302420f6f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 3 Nov 2012 10:05:03 +0100 Subject: [PATCH 12/24] tests: handle %parse-param in the generated yyerror * tests/local.at (AT_PARSE_PARAMS): New. (AT_YYERROR_FORMALS, AT_YYERROR_DEFINE): Use it to add the parse-param to yyerror. * tests/calc.at, tests/regression.at: Use AT_YYERROR_DEFINE and AT_YYERROR_DECLARE, now that they handle properly the parse-params. Be sure to let AT_BISON_OPTION_PUSHDEFS now what parse-params are used. --- tests/calc.at | 29 +++-------------------------- tests/local.at | 16 +++++++++++++--- tests/regression.at | 26 +++++++++----------------- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index 9518c3c3..2581a5b0 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -280,11 +280,7 @@ AT_SKEL_CC_IF( FILE *input; static int power (int base, int exponent); -]AT_SKEL_CC_IF(, -[static void yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ]) - AT_PARAM_IF([semantic_value *result, int *count, ]) - const char *s - );])[ +]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE_EXTERN[ } @@ -365,27 +361,8 @@ power (int base, int exponent) o << '-' << s.last.c - 1; return o; } -]]) -AT_YYERROR_DEFINE], -[/* A C error reporting function. */ -static void -yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ]) - AT_PARAM_IF([semantic_value *result, int *count, ]) - const char *s) -{ -AT_PARAM_IF([(void) result; (void) count;]) -AT_YYERROR_SEES_LOC_IF([ - fprintf (stderr, "%d.%d", - AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN); - if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE) - fprintf (stderr, "-%d.%d", - AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1); - else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1) - fprintf (stderr, "-%d", - AT_LOC_LAST_COLUMN - 1); - fprintf (stderr, ": ");]) - fprintf (stderr, "%s\n", s); -}])[ +]])])[ +]AT_YYERROR_DEFINE[ ]AT_DEFINES_IF([], [AT_CALC_LEX AT_CALC_MAIN])]) diff --git a/tests/local.at b/tests/local.at index 97107a55..b0ec647f 100644 --- a/tests/local.at +++ b/tests/local.at @@ -119,6 +119,7 @@ m4_pushdef([AT_SKEL_CC_IF], [m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])]) m4_pushdef([AT_SKEL_JAVA_IF], [m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])]) +# The target language: "c", "c++", or "java". m4_pushdef([AT_LANG], [AT_SKEL_JAVA_IF([java], [AT_SKEL_CC_IF([c++], @@ -140,6 +141,12 @@ m4_pushdef([AT_LOCATION_TYPE_IF], [m4_bmatch([$3], [%define location_type], [$1], [$2])]) m4_pushdef([AT_PARAM_IF], [m4_bmatch([$3], [%parse-param], [$1], [$2])]) +# Comma-terminated list of formals parse-parameters. +# E.g., %parse-param { int x } {int y} -> "int x, int y, ". +m4_pushdef([AT_PARSE_PARAMS]) +m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}], + [m4_append([AT_PARSE_PARAMS], [\1, ])]) + m4_pushdef([AT_PURE_IF], [m4_bmatch([$3], [%define *api\.pure\|%pure-parser], [m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])], @@ -241,6 +248,7 @@ m4_popdef([AT_GLR_OR_PARAM_IF]) m4_popdef([AT_PURE_AND_LOC_IF]) m4_popdef([AT_LOCATION_TYPE_IF]) m4_popdef([AT_LOCATION_IF]) +m4_popdef([AT_PARSE_PARAMS]) m4_popdef([AT_PARAM_IF]) m4_popdef([AT_LEXPARAM_IF]) m4_popdef([AT_YACC_IF]) @@ -350,7 +358,7 @@ static # Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair. m4_define([AT_YYERROR_FORMALS], [m4_case(AT_LANG, -[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])[const char *msg]])[]dnl +[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])AT_PARSE_PARAMS [const char *msg]])[]dnl ]) m4_define([AT_YYERROR_PROTOTYPE], @@ -374,8 +382,10 @@ m4_define([AT_YYERROR_DEFINE], /* A C error reporting function. */ static ]AT_YYERROR_PROTOTYPE[ -{ -]AT_YYERROR_SEES_LOC_IF([[ +{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]), + [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [ + YYUSE(\1);])dnl +AT_YYERROR_SEES_LOC_IF([[ fprintf (stderr, "%d.%d", ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[); if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[) diff --git a/tests/regression.at b/tests/regression.at index 1087379e..6cf22685 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -1545,14 +1545,14 @@ AT_CLEANUP m4_pushdef([AT_TEST], [AT_SETUP([[Lex and parse params: $1]]) -AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1]) +AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" %parse-param { int x } %parse-param { int y }]) ## FIXME: Improve parsing of parse-param and use the generated ## yyerror. AT_DATA_GRAMMAR([input.y], [[%defines %locations -%skeleton $1 +%skeleton "$1" %union { int ival; } %parse-param { int x } // Spaces, tabs, and new lines. @@ -1566,26 +1566,18 @@ AT_DATA_GRAMMAR([input.y], #include #include -]AT_SKEL_CC_IF([], [[ -static -void -yyerror (int x, int y, const char *msg) -{ - fprintf (stderr, "x: %d, y: %d, %s\n", x, y, msg); -}]])[ - + ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ %} %% exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); }; %% +]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["a"])[ ]AT_SKEL_CC_IF( -[AT_YYERROR_DEFINE - -int +[int yyparse (int x, int y) { yy::parser parser(x, y); @@ -1609,9 +1601,9 @@ 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") +AT_TEST([yacc.c]) +AT_TEST([glr.c]) +AT_TEST([lalr1.cc]) +AT_TEST([glr.cc]) m4_popdef([AT_TEST]) From 7dbb8d8aba43ba020cb2d8f580e01997b8dbc875 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 3 Nov 2012 17:15:43 +0100 Subject: [PATCH 13/24] tests: fix locations in C * tests/local.at (AT_YYERROR_DEFINE): Don't display the end of the location if it is not after its beginning. * tests/actions.at, tests/cxx-type.at: Adjust the expected output. --- tests/actions.at | 2 +- tests/cxx-type.at | 4 ++-- tests/local.at | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index b2d5e9d1..2314c1cd 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -664,7 +664,7 @@ Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4) Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4) Entering state 6 Reading a token: Now at end of input. -1.5-4: syntax error, unexpected $end, expecting 'e' +1.5: syntax error, unexpected $end, expecting 'e' Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4) Stack now 0 1 3 5 Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) diff --git a/tests/cxx-type.at b/tests/cxx-type.at index f5e7c559..b0e5fdcd 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -376,7 +376,7 @@ m4_define([_AT_GLR_STDERR], ]]) m4_define([_AT_GLR_STDERR_WITH_LOC], -[[17.5-4: syntax error +[[17.5: syntax error ]]) m4_define([_AT_VERBOSE_GLR_STDERR], @@ -384,7 +384,7 @@ m4_define([_AT_VERBOSE_GLR_STDERR], ]]) m4_define([_AT_VERBOSE_GLR_STDERR_WITH_LOC], -[[17.5-4: syntax error, unexpected ID, expecting '=' or '+' or ')' +[[17.5: syntax error, unexpected ID, expecting '=' or '+' or ')' ]]) ## ---------------------------------------------------- ## diff --git a/tests/local.at b/tests/local.at index b0ec647f..2af7971b 100644 --- a/tests/local.at +++ b/tests/local.at @@ -388,10 +388,10 @@ static AT_YYERROR_SEES_LOC_IF([[ fprintf (stderr, "%d.%d", ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[); - if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[) + if (]AT_LOC_FIRST_LINE[ < ]AT_LOC_LAST_LINE[) fprintf (stderr, "-%d.%d", ]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1); - else if (]AT_LOC_FIRST_COLUMN[ != ]AT_LOC_LAST_COLUMN[ - 1) + else if (]AT_LOC_FIRST_COLUMN[ < ]AT_LOC_LAST_COLUMN[ - 1) fprintf (stderr, "-%d", ]AT_LOC_LAST_COLUMN[ - 1); fprintf (stderr, ": ");]])[ From 86649705b4dc7a12e753405a3946ec36ba6a0bb9 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 3 Nov 2012 17:29:07 +0100 Subject: [PATCH 14/24] tests: remove useless location initialization. * tests/glr-regression.at: here. glr.c does initialize yylloc. --- tests/glr-regression.at | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 07c9fe25..8570b19d 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -1543,13 +1543,6 @@ AT_DATA_GRAMMAR([glr-regr17.y], ]AT_YYLEX_DECLARE[ %} -%initial-action { - @$.first_line = 1; - @$.first_column = 1; - @$.last_line = 1; - @$.last_column = 1; -} - %% /* Tests the case of an empty RHS that has inherited the location of the From 0e1ccdfae04efce6a1122ad9c4b0e85d9625c0bc Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 3 Nov 2012 16:22:15 +0100 Subject: [PATCH 15/24] c++: fix position operator signatures * data/location.cc (operator+=, operator-=): Remove const from return type. --- data/location.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/location.cc b/data/location.cc index 92b6d096..49f5f349 100644 --- a/data/location.cc +++ b/data/location.cc @@ -87,7 +87,7 @@ b4_copyright([Positions for Bison parsers in C++], }; /// Add and assign a position. - inline const position& + inline position& operator+= (position& res, const int width) { res.columns (width); @@ -103,7 +103,7 @@ b4_copyright([Positions for Bison parsers in C++], } /// Add and assign a position. - inline const position& + inline position& operator-= (position& res, const int width) { return res += -width; From 8b49e6bfc564b350f834b4c40d30bc0cee62378a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 3 Nov 2012 17:52:13 +0100 Subject: [PATCH 16/24] doc: formatting changes * doc/bison.texi: In a pointer type. --- doc/bison.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/bison.texi b/doc/bison.texi index ba18d9a9..18d3bb05 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -9528,8 +9528,8 @@ factor both as follows. // Tell Flex the lexer's prototype ... # define YY_DECL \ yy::calcxx_parser::token_type \ - yylex (yy::calcxx_parser::semantic_type* yylval, \ - yy::calcxx_parser::location_type* yylloc, \ + yylex (yy::calcxx_parser::semantic_type *yylval, \ + yy::calcxx_parser::location_type *yylloc, \ calcxx_driver& driver) // ... and declare it for the parser's sake. YY_DECL; From 7d846072c727c9314040cb209431c98ff0d299c6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 5 Nov 2012 15:19:45 +0100 Subject: [PATCH 17/24] yacc.c: simplify initialization * data/yacc.c: Fuse the initializations of yyssp, yyss and the like. Remove an obsolete comment: we do initialize these initial stack members (in some cases). --- data/yacc.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/data/yacc.c b/data/yacc.c index 5d68bd4e..77f86ec9 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -1558,9 +1558,9 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ goto yyread_pushed_token; }]])[ - yyss = yyssa; - yyvs = yyvsa;]b4_locations_if([[ - yyls = yylsa;]])[ + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa;]b4_locations_if([[ + yylsp = yyls = yylsa;]])[ yystacksize = YYINITDEPTH;]b4_lac_if([[ yyes = yyesa; @@ -1574,14 +1574,6 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs;]b4_locations_if([[ - yylsp = yyls;]])[ ]m4_ifdef([b4_initial_action],[ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [m4_define([b4_at_dollar_used])yylloc])dnl From 3237f570964d5f6cccad349f946dd301448e206e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 5 Nov 2012 16:58:24 +0100 Subject: [PATCH 18/24] yacc.c, glr.c: a better YY_LOCATION_PRINT * data/c.m4 (b4_yy_location_print_define): New. Now issues "short" locations, e.g., "1.1" instead of "1.1-1.1". Was initially a function, but then we face "static but unused" warnings. Simpler as a macro. * tests/local.at, data/glr.c, data/yacc.c: Use it instead of duplicating. * tests/actions.at: Adjust expectations. --- data/c.m4 | 31 ++++++++++++++++++++++++++++++- data/glr.c | 22 ++-------------------- data/yacc.c | 24 +++--------------------- tests/actions.at | 34 +++++++++++++++++----------------- tests/local.at | 9 +-------- 5 files changed, 53 insertions(+), 67 deletions(-) diff --git a/data/c.m4 b/data/c.m4 index 136b46e1..a1013ccc 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -644,8 +644,37 @@ m4_define([b4_yylloc_default_define], #endif ]]) +# b4_yy_location_print_define +# --------------------------- +# Define YY_LOCATION_PRINT. +m4_define([b4_yy_location_print_define], +[b4_locations_if([[ +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#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) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif]], +[[/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif]]) +]) + # b4_yyloc_default_define -# ------------------------ +# ----------------------- # Define yyloc_default, which can be used to initialize location # variables. m4_define([b4_yyloc_default_define], diff --git a/data/glr.c b/data/glr.c index 89a76e3e..a2992e08 100644 --- a/data/glr.c +++ b/data/glr.c @@ -475,28 +475,10 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = #define YYTERROR 1 ]b4_locations_if([[ -#ifndef YYLLOC_DEFAULT ]b4_yylloc_default_define[ # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ - -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -#endif -]],[ -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0) -#endif -])[ - -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif +]])[ +]b4_yy_location_print_define[ /* YYLEX -- calling `yylex' with the right arguments. */ #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[ diff --git a/data/yacc.c b/data/yacc.c index 77f86ec9..e82264ff 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -766,33 +766,15 @@ do \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 ]b4_locations_if([[ ]b4_yylloc_default_define[ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ - -#ifndef YY_LOCATION_PRINT -# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif]], -[[/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif]])[ - +]])[ +]b4_yy_location_print_define[ /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM diff --git a/tests/actions.at b/tests/actions.at index 2314c1cd..fc70f48a 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -651,29 +651,29 @@ AT_PARSER_CHECK([./input], 1, ]], [[Starting parse Entering state 0 -Reading a token: Next token is token 'a' (1.1-1.1: <> printer for 'a' @ 1) -Shifting token 'a' (1.1-1.1: <> printer for 'a' @ 1) +Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1) +Shifting token 'a' (1.1: <> printer for 'a' @ 1) Entering state 1 -Reading a token: Next token is token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) -Shifting token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) +Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2) +Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2) Entering state 3 -Reading a token: Next token is token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) -Shifting token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) +Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3) +Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3) Entering state 5 -Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4) -Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4) +Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4) +Shifting token 'd' (1.4: <> printer for 'd' @ 4) Entering state 6 Reading a token: Now at end of input. 1.5: syntax error, unexpected $end, expecting 'e' -Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4) +Error: popping token 'd' (1.4: <> printer for 'd' @ 4) Stack now 0 1 3 5 -Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3) +Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3) Stack now 0 1 3 -Error: popping token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2) +Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2) Stack now 0 1 -Error: popping token 'a' (1.1-1.1: <> printer for 'a' @ 1) +Error: popping token 'a' (1.1: <> printer for 'a' @ 1) Stack now 0 -Cleanup: discarding lookahead token $end (1.5-1.5: ) +Cleanup: discarding lookahead token $end (1.5: ) Stack now 0 ]]) @@ -895,15 +895,15 @@ AT_PARSER_CHECK([./input$1], 0, [[Starting parse Entering state 0 Reducing stack by rule 1 (line 46): --> $$ = nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1) +-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1) Stack now 0 Entering state 1 Reading a token: Now at end of input. -Shifting token END (1.1-1.1: <]]kind[[> for 'E' @ 1) +Shifting token END (1.1: <]]kind[[> for 'E' @ 1) Entering state 2 Stack now 0 1 2 -Cleanup: popping token END (1.1-1.1: <]]kind[[> for 'E' @ 1) -Cleanup: popping nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1) +Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1) +Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1) ]]) m4_popdef([kind]) diff --git a/tests/local.at b/tests/local.at index 2af7971b..73680c73 100644 --- a/tests/local.at +++ b/tests/local.at @@ -386,14 +386,7 @@ static [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [ YYUSE(\1);])dnl AT_YYERROR_SEES_LOC_IF([[ - fprintf (stderr, "%d.%d", - ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[); - if (]AT_LOC_FIRST_LINE[ < ]AT_LOC_LAST_LINE[) - fprintf (stderr, "-%d.%d", - ]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1); - else if (]AT_LOC_FIRST_COLUMN[ < ]AT_LOC_LAST_COLUMN[ - 1) - fprintf (stderr, "-%d", - ]AT_LOC_LAST_COLUMN[ - 1); + YY_LOCATION_PRINT (stderr, ]AT_LOC[); fprintf (stderr, ": ");]])[ fprintf (stderr, "%s\n", msg); }]], From a1d1ab50a00a4d28d6ba7b227ddc6628d5734ce3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 6 Nov 2012 15:34:51 +0100 Subject: [PATCH 19/24] glr.cc, yacc.c: initialize yylloc properly There are several issues to address here. One is that yylloc should be initialized when possible. Another is that the push parser needs to update yypushed_loc when the user modified it. And if the parser starts by a reduction of an empty, it uses the first location on the stack, which, therefore, must also be initialized to this initial location. This is getting complex, especially since because initializing a global (impure interface) is different from initializing a local variable. To simplify, the local yylloc is not initialized during its definition. * data/c.m4 (b4_yyloc_default_define): Replace by... (b4_yyloc_default): this. Adjust dependencies. * data/glr.cc: Initialize yylloc. * data/yacc.c (b4_declare_scanner_communication_variables): Initialize yylloc during its definition. Don't define yyloc_default. (yypush_parse): The location formal is not const, as we might initialize it. (yyparse): Define yyloc_default. Use it before running the user initial action. Possibly update the first location on the stack, and the pushed location after the user initial action. * tests/actions.at (Initial locations): Check that the initial location is correct. --- NEWS | 3 +++ data/c.m4 | 14 +++++----- data/glr.c | 4 +-- data/glr.cc | 9 +++++-- data/yacc.c | 21 ++++++++------- tests/actions.at | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index 37b8e2c0..3d21470a 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,9 @@ GNU Bison NEWS Nul characters are correctly displayed in error messages. + When possible, yylloc is correctly initialized before calling yylex. It + is no longer necessary to initialize it in the %initial-action. + * Noteworthy changes in release 2.6.4 (2012-10-23) [stable] Bison 2.6.3's --version was incorrect. This release fixes this issue. diff --git a/data/c.m4 b/data/c.m4 index a1013ccc..8bd96b85 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -673,12 +673,11 @@ m4_define([b4_yy_location_print_define], #endif]]) ]) -# b4_yyloc_default_define -# ----------------------- -# Define yyloc_default, which can be used to initialize location -# variables. -m4_define([b4_yyloc_default_define], -[[static YYLTYPE yyloc_default +# b4_yyloc_default +# ---------------- +# Expand to a possible default value for yylloc. +m4_define([b4_yyloc_default], +[[ # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL = { ]m4_join([, ], m4_defn([b4_location_initial_line]), @@ -686,5 +685,4 @@ m4_define([b4_yyloc_default_define], m4_defn([b4_location_initial_line]), m4_defn([b4_location_initial_column]))[ } # endif - ;]dnl -]) +]]) diff --git a/data/glr.c b/data/glr.c index a2992e08..9bd95228 100644 --- a/data/glr.c +++ b/data/glr.c @@ -226,8 +226,8 @@ b4_percent_code_get([[top]])[ right-hand sides. Unlike the standard yacc.c template, here we set the default value of $$ to a zeroed-out value. Since the default value is undefined, this behavior is technically correct. */ -static YYSTYPE yyval_default;]b4_locations_if([ -b4_yyloc_default_define])[ +static YYSTYPE yyval_default;]b4_locations_if([[ +static YYLTYPE yyloc_default][]b4_yyloc_default;])[ /* Copy the second part of user declarations. */ ]b4_user_post_prologue diff --git a/data/glr.cc b/data/glr.cc index 826bc80e..104bf785 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -87,12 +87,17 @@ m4_define([b4_yy_symbol_print_generate], ]b4_parse_param_use[]dnl [ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[); } -]]) +]])[ +# Hijack the initial action to initialize the locations. +]b4_locations_if([b4_percent_define_ifdef([[location_type]], [], +[m4_define([b4_initial_action], +[yylloc.initialize ();]m4_ifdef([b4_initial_action], [ +m4_defn([b4_initial_action])]))])])[ # Hijack the post prologue to insert early definition of YYLLOC_DEFAULT # and declaration of yyerror. -m4_append([b4_post_prologue], +]m4_append([b4_post_prologue], [b4_syncline([@oline@], [@ofile@])[ ]b4_yylloc_default_define[ #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) diff --git a/data/yacc.c b/data/yacc.c index e82264ff..b9a4fb18 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -181,8 +181,7 @@ int yychar; #else /* Default value used for initialization, for pacifying older GCCs or non-GCC compilers. */ -static YYSTYPE yyval_default;]b4_locations_if([ -b4_yyloc_default_define])[ +static YYSTYPE yyval_default; # define YY_INITIAL_VALUE(Value) = Value #endif]])[ #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN @@ -197,7 +196,8 @@ b4_yyloc_default_define])[ YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);]b4_locations_if([[ /* Location data for the lookahead symbol. */ -YYLTYPE yylloc YY_INITIAL_VALUE(yyloc_default);]])b4_pure_if([], [[ +YYLTYPE yylloc][]b4_yyloc_default[; +]])b4_pure_if([], [[ /* Number of syntax errors so far. */ int yynerrs;]])]) @@ -265,7 +265,7 @@ typedef struct ]b4_prefix[pstate ]b4_prefix[pstate; [[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([, [[[int pushed_char]], [[pushed_char]]], [[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([, - [[b4_api_PREFIX[LTYPE const *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [, + [[b4_api_PREFIX[LTYPE *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [, b4_parse_param])) b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]], [[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [, @@ -1409,7 +1409,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ yypstate *yyps_local;]b4_pure_if([[ int yychar; YYSTYPE yylval;]b4_locations_if([[ - YYLTYPE yylloc;]])])[ + YYLTYPE yylloc][]b4_yyloc_default[;]])])[ if (yyps) yyps_local = yyps; else @@ -1489,7 +1489,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ [[[yypstate *yyps]], [[yyps]]]b4_pure_if([, [[[int yypushed_char]], [[yypushed_char]]], [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([, - [[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [, + [[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [, b4_parse_param]))], [[ @@ -1556,16 +1556,17 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ -]m4_ifdef([b4_initial_action],[ +]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], - [m4_define([b4_at_dollar_used])yylloc])dnl + [m4_define([b4_at_dollar_used])dnl +b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl /* User initialization code. */ b4_user_initial_action b4_dollar_popdef[]dnl m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval; -]])dnl -m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc; ]])])dnl +b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])[; +]])dnl [ goto yysetstate; /*------------------------------------------------------------. diff --git a/tests/actions.at b/tests/actions.at index fc70f48a..0e02239f 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -69,6 +69,76 @@ AT_PARSER_CHECK([./input], 0, AT_CLEANUP +## ------------------ ## +## Initial location. ## +## ------------------ ## + +# AT_TEST(SKELETON-NAME, DIRECTIVES) +# ---------------------------------- +# Check the the initial location is correct. +m4_pushdef([AT_TEST], +[AT_SETUP([Initial location: $1 $2]) + +AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2 %parse-param { int x }]) +AT_DATA_GRAMMAR([[input.y]], +[[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */ +%locations +%debug +%skeleton "$1" +$2 +%parse-param { int x } // Useless, but used to force yyerror purity. +%code +{ +# include +# include // getenv +]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ +} +%% +exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]], + [[YY_LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; } +%% +]AT_YYERROR_DEFINE[ + +]AT_YYLEX_PROTOTYPE[ +{]AT_PURE_IF([ + YYUSE(lvalp); + YYUSE(llocp);], [AT_SKEL_CC_IF([ + YYUSE(lvalp); + YYUSE(llocp);])])[ + return 'x'; +} + +int +main (void) +{]AT_SKEL_CC_IF([[ + yy::parser p (0); + p.set_debug_level (!!getenv("YYDEBUG")); + return p.parse ();]], [[ + yydebug = !!getenv("YYDEBUG"); + return !!yyparse (0);]])[ +} +]]) + +AT_FULL_COMPILE([input]) +AT_PARSER_CHECK([./input], 1, [], +[[1.1 +1.1: syntax error +]]) +AT_BISON_OPTION_POPDEFS +AT_CLEANUP +]) + +## FIXME: test Java, and iterate over skeletons. +AT_TEST([yacc.c]) +AT_TEST([yacc.c], [%define api.pure]) +AT_TEST([yacc.c], [%define api.push-pull both]) +AT_TEST([yacc.c], [%define api.push-pull both %define api.pure]) +AT_TEST([glr.c]) +AT_TEST([lalr1.cc]) +AT_TEST([glr.cc]) + +m4_popdef([AT_TEST]) From 63e8426ac652bd10f45d0e0b576bfae41d779158 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 6 Nov 2012 15:34:56 +0100 Subject: [PATCH 20/24] yacc.c: also disable -Wuninitialized. * data/yacc.c (YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN): For some versions of GCC, -Wmaybe-uninitialized alone does not suffice. --- data/yacc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/data/yacc.c b/data/yacc.c index b9a4fb18..2e0ecc25 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -175,6 +175,7 @@ int yychar; /* Suppress an incorrect diagnostic about yylval being uninitialized. */ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") From 8aaa0c2f86244dde4b80c8463e1847279dbc205c Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 6 Nov 2012 15:35:37 +0100 Subject: [PATCH 21/24] tests: check that C and C++ objects can be linked together. * tests/local.at (AT_SKIP_IF_CANNOT_LINK_C_AND_CXX): New. * tests/headers.at (Several parsers): Use it. --- tests/headers.at | 9 ++++++--- tests/local.at | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/headers.at b/tests/headers.at index 8e70a7eb..a60e3153 100644 --- a/tests/headers.at +++ b/tests/headers.at @@ -240,9 +240,6 @@ AT_TEST([x7], [%define api.push-pull both]) AT_TEST([x8], [%define api.pure %define api.push-pull both]) #AT_TEST([x5], [%locations %language "c++" %glr-parser]) -AT_COMPILE_CXX([parser], [[x[1-8].o -DCC_IS_CXX=$CC_IS_CXX main.cc]]) -AT_CHECK([./parser], [0], [[expout]]) - # Check that the headers are self-contained, and protected against # multiple inclusions. While at it, check they are sane for C++. for h in *.h *.hh @@ -256,6 +253,12 @@ EOF AT_COMPILE_CXX([$h.o]) done +# Do this late, so that other checks have been performed. +AT_SKIP_IF_CANNOT_LINK_C_AND_CXX + +AT_COMPILE_CXX([parser], [[x[1-8].o -DCC_IS_CXX=$CC_IS_CXX main.cc]]) +AT_CHECK([./parser], [0], [[expout]]) + m4_popdef([AT_TEST]) AT_CLEANUP diff --git a/tests/local.at b/tests/local.at index 73680c73..88825210 100644 --- a/tests/local.at +++ b/tests/local.at @@ -683,6 +683,44 @@ m4_define([AT_FULL_COMPILE], ]) + +# AT_SKIP_IF_CANNOT_LINK_C_AND_CXX +# -------------------------------- +# Check that we can link together C and C++ objects. +m4_define([AT_SKIP_IF_CANNOT_LINK_C_AND_CXX], +[AT_DATA([c-and-cxx.h], +[[#ifdef __cplusplus +extern "C" +{ +#endif + int fortytwo (void); +#ifdef __cplusplus +} +#endif +]]) +AT_DATA([c-only.c], +[[#include "c-and-cxx.h" +int +main (void) +{ + return fortytwo () == 42 ? 0 : 1; +} +]]) +AT_DATA([cxx-only.cc], +[[#include "c-and-cxx.h" +int fortytwo () +{ + return 42; +} +]]) +AT_COMPILE([c-only.o], [c-only.c]) +AT_COMPILE_CXX([cxx-only.o], [cxx-only.cc]) +AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS $LDFLAGS c-only.o cxx-only.o -o c-and-cxx || + exit 77], [ignore], [ignore]) +AT_CHECK([./c-and-cxx]) +]) + + ## ---------------------------- ## ## Running a generated parser. ## ## ---------------------------- ## From 41a4806a825bebfa73a5a9337672735ba1f753c6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 1 Nov 2012 15:38:25 +0100 Subject: [PATCH 22/24] lalr1.cc: always initialize yylval. * data/lalr1.cc: here. --- data/lalr1.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/lalr1.cc b/data/lalr1.cc index 4eac6351..2fe8d4cb 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -520,7 +520,8 @@ do { \ int yyerrstatus_ = 0; /// Semantic value of the lookahead. - semantic_type yylval; + static semantic_type yyval_default; + semantic_type yylval = yyval_default; /// Location of the lookahead. location_type yylloc; /// The locations where the error started and ended. From d03c0413f0c73f2ab6dde539928eaca8f9f86c9f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 6 Nov 2012 15:42:50 +0100 Subject: [PATCH 23/24] tests: remove useless location initializations * tests/actions.at, tests/calc.at: here. --- tests/actions.at | 17 +---------------- tests/calc.at | 11 ----------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index 0e02239f..01e3e57d 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -894,10 +894,6 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]], [[%error-verbose %debug %locations -%initial-action { - @$.first_line = @$.last_line = 1; - @$.first_column = @$.last_column = 1; -} %{ # include @@ -964,7 +960,7 @@ AT_PARSER_CHECK([./input$1], 0, ]], [[Starting parse Entering state 0 -Reducing stack by rule 1 (line 46): +Reducing stack by rule 1 (line 42): -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1) Stack now 0 Entering state 1 @@ -1360,17 +1356,6 @@ AT_DATA_GRAMMAR([[input.y]], %printer { report (yyo, $$, $$ ); } ; %printer { report (yyo, $$, $$); } <>; -]AT_SKEL_CC_IF([[ -/* The lalr1.cc skeleton, for backward compatibility, defines - a constructor for position that initializes the filename. The - glr.cc skeleton does not (and in fact cannot: location/position - are stored in a union, from which objects with constructors are - excluded in C++). */ -%initial-action { - @$.initialize (); -} -]])[ - %initial-action { $$ = 42; diff --git a/tests/calc.at b/tests/calc.at index 2581a5b0..d912832f 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -284,17 +284,6 @@ static int power (int base, int exponent); ]AT_YYLEX_DECLARE_EXTERN[ } -]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([], [[ -/* The lalr1.cc skeleton, for backward compatibility, defines - a constructor for position that initializes the filename. The - glr.cc skeleton does not (and in fact cannot: location/position - are stored in a union, from which objects with constructors are - excluded in C++). */ -%initial-action { - @$.initialize (); -} -]])])[ - /* Bison Declarations */ %token CALC_EOF 0 "end of input" %token NUM "number" From 3154ff8ef666b601181b5a544c8187de0e836c52 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 6 Nov 2012 16:25:37 +0100 Subject: [PATCH 24/24] tests: calc: modernize the use of locations * tests/calc.at: Don't initialize the location, let the parser do it. Use a $printer. Change some testing input to be easier to distinguish (instead of always "0 0" for instance). --- tests/calc.at | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index d912832f..062bb45b 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -178,18 +178,7 @@ read_signed_integer (]AT_YYLEX_FORMALS[) ]AT_YYLEX_PROTOTYPE[ { - static int init = 1; int c; - - if (init) - { - init = 0; -]AT_LOCATION_IF([ - AT_LOC_LAST_COLUMN = 1; - AT_LOC_LAST_LINE = 1; -])[ - } - /* Skip current token, then white spaces. */ do { @@ -261,6 +250,8 @@ AT_SKEL_CC_IF( { semantic_value ival; }; +%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]], + [[fprintf (yyoutput, "%d", $$)]])[; } ; %code provides { @@ -284,6 +275,13 @@ static int power (int base, int exponent); ]AT_YYLEX_DECLARE_EXTERN[ } +]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([[ +%initial-action +{ + @$.first.l = @$.first.c = 1; + @$.last = @$.first; +}]])])[ + /* Bison Declarations */ %token CALC_EOF 0 "end of input" %token NUM "number" @@ -516,7 +514,7 @@ _AT_CHECK_CALC([$1], [842]) # Some syntax errors. -_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15], +_AT_CHECK_CALC_ERROR([$1], [1], [1 2], [15], [1.3: syntax error, unexpected number]) _AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20], [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!']) @@ -560,10 +558,10 @@ calc: error: 4444 != 1]) # The same, but this time exercising explicitly triggered syntax errors. # POSIX says the lookahead causing the error should not be discarded. -_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102], +_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1], [102], [1.10: syntax error, unexpected number calc: error: 2222 != 1]) -_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113], +_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1], [113], [1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 1.12: syntax error, unexpected number calc: error: 2222 != 1])