mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-28 05:33:03 +00:00
glr2.cc: move glr_stack and glr_state into the parser class
In order to be able to link several glr2.cc parser together, we cannot have glr_stack and glr_state be in no namespace. Putting them in the unnamed namespace is not doable, since we need to fwd declare them in the parser. Putting them in the specified namespace is not enough either, since some users would like to be able to put several parsers in the same name, only differing by the class name. * data/skeletons/glr2.cc (glr_state, glr_stack): Move into yy::parser.
This commit is contained in:
@@ -224,9 +224,6 @@ m4_define([b4_shared_declarations],
|
||||
|
||||
]b4_YYDEBUG_define[
|
||||
|
||||
class glr_stack;
|
||||
class glr_state;
|
||||
|
||||
]b4_namespace_open[
|
||||
|
||||
]b4_bison_locations_if([m4_ifndef([b4_location_file],
|
||||
@@ -239,6 +236,10 @@ class glr_state;
|
||||
]b4_public_types_declare[
|
||||
]b4_symbol_type_define[
|
||||
|
||||
// FIXME: should be private eventually.
|
||||
class glr_stack;
|
||||
class glr_state;
|
||||
|
||||
/// Build a parser object.
|
||||
]b4_parser_class[ (]b4_parse_param_decl[);
|
||||
~]b4_parser_class[ ();
|
||||
@@ -373,10 +374,8 @@ class glr_state;
|
||||
location_type& yyloc]])[);
|
||||
|
||||
]b4_parse_param_vars[
|
||||
// Needs access to report_syntax_error, etc.
|
||||
// Needs access to yy_destroy_, report_syntax_error, etc.
|
||||
friend glr_stack;
|
||||
// Needs access to yy_destroy_.
|
||||
friend glr_state;
|
||||
};
|
||||
|
||||
]b4_token_ctor_if([b4_yytranslate_define([$1])[
|
||||
@@ -635,6 +634,9 @@ int yydebug;
|
||||
|
||||
namespace
|
||||
{
|
||||
using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack;
|
||||
using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state;
|
||||
|
||||
void yypstack (const glr_stack& yystack, size_t yyk)
|
||||
YY_ATTRIBUTE_UNUSED;
|
||||
void yypdumpstack (const glr_stack& yystack)
|
||||
@@ -775,13 +777,11 @@ typedef int state_num;
|
||||
typedef int rule_num;
|
||||
|
||||
// Forward declarations.
|
||||
class glr_state;
|
||||
namespace
|
||||
{
|
||||
class semantic_option;
|
||||
}
|
||||
class glr_stack_item;
|
||||
class glr_stack;
|
||||
|
||||
/** Accessing symbol of state YYSTATE. */
|
||||
static inline yysymbol_kind_t
|
||||
@@ -804,9 +804,11 @@ yyrhsLength (rule_num yyrule)
|
||||
return yyr2[yyrule];
|
||||
}
|
||||
|
||||
class glr_state
|
||||
namespace ]b4_namespace_ref[
|
||||
{
|
||||
public:
|
||||
class ]b4_parser_class[::glr_state
|
||||
{
|
||||
public:
|
||||
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
|
||||
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
|
||||
typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
|
||||
@@ -939,7 +941,7 @@ public:
|
||||
destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[);
|
||||
|
||||
/* DEBUGGING ONLY */
|
||||
#if ]b4_api_PREFIX[DEBUG
|
||||
#if ]b4_api_PREFIX[DEBUG
|
||||
void yy_yypstack () const
|
||||
{]b4_parse_assert_if([[
|
||||
check_ ();]])[
|
||||
@@ -950,7 +952,7 @@ public:
|
||||
}
|
||||
std::cerr << yylrState << "@@" << yyposn;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::ptrdiff_t indexIn (const glr_stack_item* array) const;
|
||||
|
||||
@@ -966,7 +968,7 @@ public:
|
||||
return asItem (this);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
template <typename T>
|
||||
static const glr_stack_item* asItem (const T* state)
|
||||
{
|
||||
@@ -1000,8 +1002,8 @@ private:
|
||||
/** Source location for this state. */
|
||||
location_type yyloc;]])[
|
||||
|
||||
]b4_parse_assert_if([[
|
||||
public:
|
||||
]b4_parse_assert_if([[
|
||||
public:
|
||||
// Check invariants.
|
||||
void check_ () const
|
||||
{
|
||||
@@ -1013,7 +1015,9 @@ public:
|
||||
// A magic number to check our pointer arithmetic is sane.
|
||||
enum { MAGIC = 713705 };
|
||||
unsigned int magic_;]])[
|
||||
};
|
||||
};
|
||||
} // namespace ]b4_namespace_ref[
|
||||
|
||||
|
||||
/** A stack of GLRState representing the different heads during
|
||||
* nondeterministic evaluation. */
|
||||
@@ -2073,9 +2077,11 @@ public:
|
||||
#undef YYFILL
|
||||
#define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
|
||||
|
||||
class glr_stack
|
||||
namespace ]b4_namespace_ref[
|
||||
{
|
||||
public:
|
||||
class ]b4_parser_class[::glr_stack
|
||||
{
|
||||
public:
|
||||
typedef ]b4_namespace_ref[::]b4_parser_class[ parser_type;
|
||||
typedef parser_type::symbol_kind symbol_kind;
|
||||
typedef parser_type::symbol_kind_type symbol_kind_type;
|
||||
@@ -2083,11 +2089,11 @@ public:
|
||||
typedef parser_type::value_type value_type;]b4_locations_if([[
|
||||
typedef parser_type::location_type location_type;]])[
|
||||
|
||||
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
||||
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
||||
typedef parser_type::context context;
|
||||
// Needs access to yypact_value_is_default, etc.
|
||||
friend context;
|
||||
]])[
|
||||
]])[
|
||||
|
||||
glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
|
||||
: yyerrState (0)
|
||||
@@ -2106,7 +2112,7 @@ public:
|
||||
}
|
||||
|
||||
int yyerrState;
|
||||
]b4_locations_if([[ /* To compute the location of the error token. */
|
||||
]b4_locations_if([[ /* To compute the location of the error token. */
|
||||
glr_stack_item yyerror_range[3];]])[
|
||||
state_stack yystateStack;
|
||||
int yyerrcnt;
|
||||
@@ -2114,7 +2120,7 @@ public:
|
||||
YYJMP_BUF yyexception_buffer;
|
||||
]b4_namespace_ref[::]b4_parser_class[& yyparser;
|
||||
|
||||
#define YYCHK1(YYE) \
|
||||
#define YYCHK1(YYE) \
|
||||
do { \
|
||||
switch (YYE) { \
|
||||
case yyok: \
|
||||
@@ -2139,11 +2145,11 @@ public:
|
||||
YYCDEBUG << "Starting parse\n";
|
||||
|
||||
this->yyla.clear ();
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef])[]dnl
|
||||
[
|
||||
b4_dollar_popdef])[]dnl
|
||||
[
|
||||
switch (YYSETJMP (this->yyexception_buffer))
|
||||
{
|
||||
case 0: break;
|
||||
@@ -2267,7 +2273,7 @@ b4_dollar_popdef])[]dnl
|
||||
YYCDEBUG << "Stack " << yys.get() << " now in state "
|
||||
<< this->topState(yys)->yylrState << '\n';
|
||||
}
|
||||
]b4_variant_if([[
|
||||
]b4_variant_if([[
|
||||
// FIXME: User destructors.
|
||||
// Value type destructor.
|
||||
]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[
|
||||
@@ -2306,7 +2312,7 @@ b4_dollar_popdef])[]dnl
|
||||
yyreturn:
|
||||
return yyresult;
|
||||
}
|
||||
#undef YYCHK1
|
||||
#undef YYCHK1
|
||||
|
||||
void yyreserveGlrStack ()
|
||||
{
|
||||
@@ -2356,26 +2362,26 @@ b4_dollar_popdef])[]dnl
|
||||
yyreserveGlrStack ();
|
||||
}
|
||||
|
||||
#if ]b4_api_PREFIX[DEBUG
|
||||
#if ]b4_api_PREFIX[DEBUG
|
||||
void yypdumpstack () const
|
||||
{
|
||||
yystateStack.dumpStack();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void
|
||||
yyreportSyntaxError ()
|
||||
{
|
||||
if (yyerrState != 0)
|
||||
return;
|
||||
]b4_parse_error_case(
|
||||
[simple], [[
|
||||
]b4_parse_error_case(
|
||||
[simple], [[
|
||||
std::string msg = YY_("syntax error");
|
||||
yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]],
|
||||
[custom], [[
|
||||
[custom], [[
|
||||
context yyctx (*this, yyla);
|
||||
yyparser.report_syntax_error (yyctx);]],
|
||||
[[
|
||||
[[
|
||||
context yyctx (*this, yyla);
|
||||
std::string msg = yyparser.yysyntax_error_ (yyctx);
|
||||
yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[
|
||||
@@ -2580,7 +2586,7 @@ b4_dollar_popdef])[]dnl
|
||||
return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
|
||||
yyerrok, yyerr
|
||||
|
||||
]b4_variant_if([[
|
||||
]b4_variant_if([[
|
||||
/* Variants are always initialized to an empty instance of the
|
||||
correct type. The default '$$ = $1' action is NOT applied
|
||||
when using variants. */
|
||||
@@ -2595,7 +2601,7 @@ b4_dollar_popdef])[]dnl
|
||||
/* Default location. */
|
||||
YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
|
||||
yyerror_range[1].getState().yyloc = *yylocp;
|
||||
]])[
|
||||
]])[
|
||||
/* If yyk == -1, we are running a deferred action on a temporary
|
||||
stack. In that case, YY_REDUCE_PRINT must not play with YYFILL,
|
||||
so pretend the stack is "normal". */
|
||||
@@ -2818,7 +2824,7 @@ b4_dollar_popdef])[]dnl
|
||||
return yystateStack.firstTop();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
void popall_ ()
|
||||
{
|
||||
@@ -3215,9 +3221,9 @@ private:
|
||||
return 0;
|
||||
}
|
||||
|
||||
]b4_parse_param_vars[
|
||||
|
||||
};
|
||||
]b4_parse_param_vars[
|
||||
}; // class ]b4_parser_class[::glr_stack
|
||||
} // namespace ]b4_namespace_ref[
|
||||
|
||||
|
||||
/* DEBUGGING ONLY */
|
||||
|
||||
Reference in New Issue
Block a user