From 56ca3d8fce0c9db2f2829d7a7a07a9ad06cdf6a8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 15 Jun 2012 15:19:16 +0200 Subject: [PATCH] glr.c, yacc.c: declare yydebug in the header. * data/c.m4 (b4_declare_yydebug): New. * data/glr.c, data/yacc.c (b4_shared_declarations): Use it. Remove the corresponding code from the parser body. * NEWS: Doc this. --- NEWS | 18 +++++++++++++++++- data/c.m4 | 12 ++++++++++++ data/glr.c | 8 ++------ data/yacc.c | 8 ++------ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 118aae38..ae8b297c 100644 --- a/NEWS +++ b/NEWS @@ -14,7 +14,9 @@ GNU Bison NEWS YYSTYPE, yyltype etc.), the generated parser now includes it, as was already the case for GLR or C++ parsers. -** Header guards (yacc.c, glr.c, glr.cc) +** Headers (yacc.c, glr.c, glr.cc) + +*** Guards The generated headers are now guarded, as is already the case for C++ parsers (lalr1.cc). For intance, with --defines=foo.h: @@ -24,6 +26,20 @@ GNU Bison NEWS ... #endif /* !YY_FOO_H */ +*** New declarations + + The generated header now declares yydebug and yyparse. Both honor + --name-prefix=bar_, and yield + + int bar_parse (void); + + rather than + + #define yyparse bar_parse + int yyparse (void); + + in order to facilitate the inclusion of several parser headers inside a + single compilation unit. * Noteworthy changes in release 2.5.1 (2012-06-05) [stable] diff --git a/data/c.m4 b/data/c.m4 index 64f68fec..78b12325 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -567,3 +567,15 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif]]) ]) + +# b4_declare_yydebug +# ------------------ +m4_define([b4_declare_yydebug], +[[/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG ]b4_debug_flag[ +#endif +#if YYDEBUG +extern int ]b4_prefix[debug; +#endif][]dnl +]) diff --git a/data/glr.c b/data/glr.c index d1d61fe6..9bbf9a72 100644 --- a/data/glr.c +++ b/data/glr.c @@ -163,7 +163,8 @@ m4_define([b4_rhs_location], # Declaration that might either go into the header (if --defines) # or open coded in the parser body. m4_define([b4_shared_declarations], -[b4_percent_code_get([[requires]])[ +[b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ ]b4_token_enums(b4_tokens)[ ]b4_declare_yylstype[ ]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[ @@ -206,11 +207,6 @@ m4_if(b4_prefix, [yy], [], ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], [b4_shared_declarations])[ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ -#endif - /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE diff --git a/data/yacc.c b/data/yacc.c index 7f73c26d..30c5f672 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -272,7 +272,8 @@ m4_define([b4_declare_yyparse], # Declaration that might either go into the header (if --defines) # or open coded in the parser body. m4_define([b4_shared_declarations], -[b4_percent_code_get([[requires]])[ +[b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ ]b4_token_enums_defines(b4_tokens)[ ]b4_declare_yylstype[ ]b4_declare_yyparse[ @@ -323,11 +324,6 @@ m4_if(b4_prefix, [yy], [], ]b4_null_define[ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ -#endif - /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE -- 2.45.2