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 <API.PREFIX>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.
# define BAR_FOO_H # define BAR_FOO_H
/* Enabling traces. */ /* Enabling traces. */
# define BAR_FOO_H # define BAR_FOO_H
/* Enabling traces. */ /* Enabling traces. */
- # ifndef YYDEBUG # ifndef YYDEBUG
- # define YYDEBUG 0 # define YYDEBUG 0
- # endif # endif
- # if YYDEBUG # if YYDEBUG
+ # ifndef YYDEBUG | # ifndef BAR_DEBUG
+ > # if defined YYDEBUG
+ > # if YYDEBUG
+ > # define BAR_DEBUG 1
+ > # else
+ > # define BAR_DEBUG 0
+ > # endif
+ > # else
+ # define YYDEBUG 0 | # define BAR_DEBUG 0
+ > # endif
+ # endif | # endif
+
+ # if YYDEBUG | # if BAR_DEBUG
extern int bar_debug; extern int bar_debug;
# endif # endif
extern int bar_debug; extern int bar_debug;
# endif # endif
]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
])
]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
])
-m4_define([b4_declare_yydebug],
+m4_define([b4_YYDEBUG_define],
+]m4_if(b4_api_prefix, [yy],
+[[#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
# define YYDEBUG ]b4_debug_flag[
+#endif]],
+[[#ifndef ]b4_api_PREFIX[DEBUG
+# if defined YYDEBUG
+# if YYDEBUG
+# define ]b4_api_PREFIX[DEBUG 1
+# else
+# define ]b4_api_PREFIX[DEBUG 0
+# endif
+# else /* ! defined YYDEBUG */
+# define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[
+# endif /* ! defined ]b4_api_PREFIX[DEBUG */
+#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
+])
+
+# b4_declare_yydebug
+# ------------------
+m4_define([b4_declare_yydebug],
+[b4_YYDEBUG_define[
+#if ]b4_api_PREFIX[DEBUG
extern int ]b4_prefix[debug;
#endif][]dnl
])
extern int ]b4_prefix[debug;
#endif][]dnl
])
+#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[] =
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
-#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[] =
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
while (YYID (0))
do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
while (YYID (0))
+#if ]b4_api_PREFIX[DEBUG
# ifndef YYFPRINTF
# define YYFPRINTF fprintf
# ifndef YYFPRINTF
# define YYFPRINTF fprintf
multiple parsers can coexist. */
int yydebug;
multiple parsers can coexist. */
int yydebug;
+#else /* !]b4_api_PREFIX[DEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+#endif /* !]b4_api_PREFIX[DEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
YYLONGJMP (yystackp->yyexception_buffer, 2);
}
YYLONGJMP (yystackp->yyexception_buffer, 2);
}
-#if YYDEBUG || YYERROR_VERBOSE
+#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
/** A printable representation of TOKEN. */
static inline const char*
yytokenName (yySymbol yytoken)
/** A printable representation of TOKEN. */
static inline const char*
yytokenName (yySymbol yytoken)
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
else
{
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
else
{
+#if ]b4_api_PREFIX[DEBUG
if (yydebug)
{
if (yys->yysemantics.yyfirstVal)
if (yydebug)
{
if (yys->yysemantics.yyfirstVal)
+#if !]b4_api_PREFIX[DEBUG
# define YY_REDUCE_PRINT(Args)
#else
# define YY_REDUCE_PRINT(Args) \
# define YY_REDUCE_PRINT(Args)
#else
# define YY_REDUCE_PRINT(Args) \
+#if ]b4_api_PREFIX[DEBUG
static void
yyreportTree (yySemanticOption* yyx, int yyindent)
{
static void
yyreportTree (yySemanticOption* yyx, int yyindent)
{
YYUSE (yyx0);
YYUSE (yyx1);
YYUSE (yyx0);
YYUSE (yyx1);
+#if ]b4_api_PREFIX[DEBUG
YYFPRINTF (stderr, "Ambiguity detected.\n");
YYFPRINTF (stderr, "Option 1,\n");
yyreportTree (yyx0, 2);
YYFPRINTF (stderr, "Ambiguity detected.\n");
YYFPRINTF (stderr, "Option 1,\n");
yyreportTree (yyx0, 2);
+#if ]b4_api_PREFIX[DEBUG
static void yypstack (yyGLRStack* yystackp, size_t yyk)
__attribute__ ((__unused__));
static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
static void yypstack (yyGLRStack* yystackp, size_t yyk)
__attribute__ ((__unused__));
static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
[ /// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
[ /// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
+#if ]b4_api_PREFIX[DEBUG
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
return ::yyparse (*this]b4_user_args[);
}
return ::yyparse (*this]b4_user_args[);
}
+#if ]b4_api_PREFIX[DEBUG
/*--------------------.
| Print this symbol. |
`--------------------*/
/*--------------------.
| Print this symbol. |
`--------------------*/
]b4_percent_define_ifdef([[location_type]], [],
[[#include "location.hh"]])[
]b4_percent_define_ifdef([[location_type]], [],
[[#include "location.hh"]])[
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG ]b4_debug_flag[
-#endif
/* 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
/* 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
virtual void error (const location_type& loc, const std::string& msg);
private:
virtual void error (const location_type& loc, const std::string& msg);
private:
+# if ]b4_api_PREFIX[DEBUG
public:
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
public:
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG ]b4_debug_flag[
-#endif
/// \returns 0 iff parsing succeeded.
virtual int parse ();
/// \returns 0 iff parsing succeeded.
virtual int parse ();
+#if ]b4_api_PREFIX[DEBUG
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);
+#if ]b4_api_PREFIX[DEBUG
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *n);])[
/// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *n);])[
-]b4_token_table_if([], [[#if YYDEBUG]])[
+]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
/// For a symbol, its name in clear.
static const char* const yytname_[];
/// For a symbol, its name in clear.
static const char* const yytname_[];
-]b4_token_table_if([[#if YYDEBUG]])[
+]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
/// A type to store symbol numbers and -1.
typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
/// A type to store symbol numbers and -1.
typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
#define YYUSE(e) ((void) (e))
/* Enable debugging if requested. */
#define YYUSE(e) ((void) (e))
/* Enable debugging if requested. */
+#if ]b4_api_PREFIX[DEBUG
/* A pseudo ostream that takes yydebug_ into account. */
# define YYCDEBUG if (yydebug_) (*yycdebug_)
/* A pseudo ostream that takes yydebug_ into account. */
# define YYCDEBUG if (yydebug_) (*yycdebug_)
yystack_print_ (); \
} while (false)
yystack_print_ (); \
} while (false)
+#else /* !]b4_api_PREFIX[DEBUG */
# define YYCDEBUG if (false) std::cerr
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_REDUCE_PRINT(Rule)
# define YY_STACK_PRINT()
# define YYCDEBUG if (false) std::cerr
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_REDUCE_PRINT(Rule)
# define YY_STACK_PRINT()
+#endif /* !]b4_api_PREFIX[DEBUG */
#define yyerrok (yyerrstatus_ = 0)
#define yyclearin (yychar = yyempty_)
#define yyerrok (yyerrstatus_ = 0)
#define yyclearin (yychar = yyempty_)
/// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
/// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
+#if ]b4_api_PREFIX[DEBUG
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
+#if ]b4_api_PREFIX[DEBUG
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
yylocation_stack_.pop (n);
}
yylocation_stack_.pop (n);
}
+#if ]b4_api_PREFIX[DEBUG
std::ostream&
]b4_parser_class_name[::debug_stream () const
{
std::ostream&
]b4_parser_class_name[::debug_stream () const
{
+#if ]b4_api_PREFIX[DEBUG
/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
to YYLEX-NUM. */
const ]b4_int_type_for([b4_toknum])[
/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
to YYLEX-NUM. */
const ]b4_int_type_for([b4_toknum])[
-]b4_token_table_if([], [[#if YYDEBUG]])[
+]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
const char*
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
const char*
-]b4_token_table_if([[#if YYDEBUG]])[
+]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
const ]b4_parser_class_name[::rhs_number_type
]b4_parser_class_name[::yyrhs_[] =
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
const ]b4_parser_class_name[::rhs_number_type
]b4_parser_class_name[::yyrhs_[] =
&]b4_rhs_value(yynrhs, yyi + 1)[,
&]b4_rhs_location(yynrhs, yyi + 1)[);
}
&]b4_rhs_value(yynrhs, yyi + 1)[,
&]b4_rhs_location(yynrhs, yyi + 1)[);
}
+#endif // ]b4_api_PREFIX[DEBUG
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
]b4_parser_class_name[::token_number_type
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
]b4_parser_class_name[::token_number_type
+#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[] =
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
-#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[] =
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
#endif
/* Enable debugging if requested. */
#endif
/* Enable debugging if requested. */
+#if ]b4_api_PREFIX[DEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int 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)
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
+#endif /* !]b4_api_PREFIX[DEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
/* YYINITDEPTH -- initial size of the parser's stacks. */
required. Return 1 if memory is exhausted. */
static int
yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
required. Return 1 if memory is exhausted. */
static int
yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
+#if ]b4_api_PREFIX[DEBUG
char const *yydebug_prefix,
char const *yydebug_suffix,
#endif
char const *yydebug_prefix,
char const *yydebug_suffix,
#endif
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. */
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 ]b4_api_PREFIX[DEBUG
# define YY_LAC_DISCARD(Event) \
do { \
if (yy_lac_established) \
# define YY_LAC_DISCARD(Event) \
do { \
if (yy_lac_established) \
else
{
if (yy_lac_stack_realloc (yyes_capacity, 1,
else
{
if (yy_lac_stack_realloc (yyes_capacity, 1,
+#if ]b4_api_PREFIX[DEBUG
" (", ")",
#endif
yyes, yyesa, &yyesp, yyes_prev))
" (", ")",
#endif
yyes, yyesa, &yyesp, yyes_prev))
yysize = yysize1;
}
}]b4_lac_if([[
yysize = yysize1;
}
}]b4_lac_if([[
+# if ]b4_api_PREFIX[DEBUG
else if (yydebug)
YYFPRINTF (stderr, "No expected tokens.\n");
# endif]])[
else if (yydebug)
YYFPRINTF (stderr, "No expected tokens.\n");
# endif]])[