From 5f108727a13ff887f889948b2484724f14c125e9 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 2 Jul 2012 14:56:22 +0200 Subject: api.prefix: also rename YYDEBUG. The testsuite in master has shown weird errors for the "Mulitple Parsers" tests: the caller of p5.parse() received some apparently random value, while tracing p5.parse() showed that the function was consistently returning 0. It happens when mixing several parser headers, some generated without %debug, others with. In particular the C++ parser was generated with %debug, i.e., with: #ifndef YYDEBUG # define YYDEBUG 1 #endif and compiled separatedly. Yet, its header was included after the one of another parser, this time without %debug, i.e., with #ifndef YYDEBUG # define YYDEBUG 0 #endif in its header. As a result, the parser was compiled with YYDEBUG set, but its header was used without. Since the layout of the objects are then completely different, boom. Therefore, do not change the value of YYDEBUG. Rather, use it as a default value for DEBUG. * data/c.m4 (b4_YYDEBUG_define): New. (b4_declare_yydebug): Rename as... (b4_yydebug_declare): this, for consistency. * data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it. * NEWS: Document it. --- data/yacc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'data/yacc.c') diff --git a/data/yacc.c b/data/yacc.c index 8c595f9a..3a679141 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -589,7 +589,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = ]b4_translate[ }; -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const ]b4_int_type_for([b4_prhs])[ yyprhs[] = @@ -610,7 +610,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ +#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -803,7 +803,7 @@ while (YYID (0)) #endif /* Enable debugging if requested. */ -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ @@ -890,12 +890,12 @@ do { \ /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; -#else /* !YYDEBUG */ +#else /* !]b4_api_PREFIX[DEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ +#endif /* !]b4_api_PREFIX[DEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ @@ -926,7 +926,7 @@ int yydebug; required. Return 1 if memory is exhausted. */ static int yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG char const *yydebug_prefix, char const *yydebug_suffix, #endif @@ -1032,7 +1032,7 @@ do { \ the parser stacks to try to find a new initial context in which the current lookahead is syntactically acceptable. If it fails to find such a context, it discards the lookahead. */ -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG # define YY_LAC_DISCARD(Event) \ do { \ if (yy_lac_established) \ @@ -1135,7 +1135,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, else { if (yy_lac_stack_realloc (yyes_capacity, 1, -#if YYDEBUG +#if ]b4_api_PREFIX[DEBUG " (", ")", #endif yyes, yyesa, &yyesp, yyes_prev)) @@ -1342,7 +1342,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yysize = yysize1; } }]b4_lac_if([[ -# if YYDEBUG +# if ]b4_api_PREFIX[DEBUG else if (yydebug) YYFPRINTF (stderr, "No expected tokens.\n"); # endif]])[ -- cgit v1.2.1 From 9104636b039b322fe29f64cc1546ecd94812ef46 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 4 Jul 2012 11:04:52 +0200 Subject: api.prefix: do not use #define to handle YYSTYPE_IS_TRIVIAL etc. The following mixture is insane: #define YYSTYPE_IS_TRIVIAL PREFIX_STYPE_IS_TRIVIAL #if (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL) since, of course YYSTYPE_IS_TRIVIAL is defined. Instead we could define YYSTYPE_IS_TRIVIAL as PREFIX_STYPE_IS_TRIVIAL only when the later is defined, but let's avoid stacking CPP on top of M4: rather, use #if (defined PREFIX_STYPE_IS_TRIVIAL && PREFIX_STYPE_IS_TRIVIAL) * data/glr.c, data/yacc.c: Use YYSTYPE_IS_TRIVIAL, YYSTYPE_IS_DECLARED, YYLTYPE_IS_TRIVIAL and YYLTYPE_IS_DECLARED under their api.prefix-renamed name. --- data/yacc.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'data/yacc.c') diff --git a/data/yacc.c b/data/yacc.c index 3a679141..8623847e 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -309,12 +309,8 @@ b4_copyright([Bison implementation for Yacc-like parsers in C], b4_percent_code_get([[top]])[]dnl m4_if(b4_api_prefix, [yy], [], [[/* Substitute the type names. */ -#define YYSTYPE ]b4_api_PREFIX[STYPE -#define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL -#define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[ -#define YYLTYPE ]b4_api_PREFIX[LTYPE -#define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL -#define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[ +#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ +#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ ]m4_if(b4_prefix, [yy], [], [[/* Substitute the variable and function names. */]b4_pull_if([[ #define yyparse ]b4_prefix[parse]])b4_push_if([[ @@ -498,8 +494,8 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ - && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \ + && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -776,7 +772,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# 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, \ @@ -1585,7 +1581,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ yyvsp = yyvs;]b4_locations_if([[ yylsp = yyls; -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +#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[; -- cgit v1.2.1 From 426903aa75c4c92c6953f1304ee24c16c600210e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 4 Jul 2012 11:41:06 +0200 Subject: YYLLOC_DEFAULT: factor, and don't export it in headers. * data/c++.m4, data/c.m4 (b4_yylloc_default_define): New. * data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it. * data/glr.cc: Do not define YYLLOC_DEFAULT in the header file, but in the implementation one. --- data/yacc.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'data/yacc.c') diff --git a/data/yacc.c b/data/yacc.c index 8623847e..2e46a1e2 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -740,31 +740,9 @@ while (YYID (0)) #define YYTERROR 1 #define YYERRCODE 256 - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - +]b4_yylloc_default_define[ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif]b4_locations_if([[ +]b4_locations_if([[ /* YY_LOCATION_PRINT -- Print the location on the stream. -- cgit v1.2.1