[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/14] glr2.cc: move glr_stack and glr_state into the parser clas
From: |
Akim Demaille |
Subject: |
[PATCH 05/14] glr2.cc: move glr_stack and glr_state into the parser class |
Date: |
Sun, 12 Sep 2021 14:07:38 +0200 |
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.
---
data/skeletons/glr2.cc | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 573de259..b7d33a14 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -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,7 +804,9 @@ yyrhsLength (rule_num yyrule)
return yyr2[yyrule];
}
-class glr_state
+namespace ]b4_namespace_ref[
+{
+ class ]b4_parser_class[::glr_state
{
public:
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
@@ -1014,6 +1016,8 @@ public:
enum { MAGIC = 713705 };
unsigned int magic_;]])[
};
+} // namespace ]b4_namespace_ref[
+
/** A stack of GLRState representing the different heads during
* nondeterministic evaluation. */
@@ -2073,7 +2077,9 @@ public:
#undef YYFILL
#define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
-class glr_stack
+namespace ]b4_namespace_ref[
+{
+ class ]b4_parser_class[::glr_stack
{
public:
typedef ]b4_namespace_ref[::]b4_parser_class[ parser_type;
@@ -3216,8 +3222,8 @@ private:
}
]b4_parse_param_vars[
-
-};
+ }; // class ]b4_parser_class[::glr_stack
+} // namespace ]b4_namespace_ref[
/* DEBUGGING ONLY */
--
2.32.0
- [PATCH 00/14] glr2.cc: fix linking conflicts, Akim Demaille, 2021/09/12
- [PATCH 01/14] glr2.cc: don't publish YY_EXCEPTIONS, Akim Demaille, 2021/09/12
- [PATCH 02/14] glr2.cc: put semantic_option into an unnamed namespace, Akim Demaille, 2021/09/12
- [PATCH 03/14] glr2.cc: prefer unnamed namespace to 'static', Akim Demaille, 2021/09/12
- [PATCH 04/14] glr2.cc: put create_state_set_index in unnamed namespace, Akim Demaille, 2021/09/12
- [PATCH 05/14] glr2.cc: move glr_stack and glr_state into the parser class,
Akim Demaille <=
- [PATCH 06/14] glr2.cc: style: clarify control flow, Akim Demaille, 2021/09/12
- [PATCH 07/14] glr2.cc: move state_stack into the unnamed namespace, Akim Demaille, 2021/09/12
- [PATCH 08/14] glr2.cc: put glr_state_set and glr_stack_item in unnamed namespace, Akim Demaille, 2021/09/12
- [PATCH 09/14] glr2.cc: prefer using, and remove useless type aliases, Akim Demaille, 2021/09/12
- [PATCH 10/14] glr2.cc: use only symbol_kind_type, not yysymbol_kind_t, Akim Demaille, 2021/09/12
- [PATCH 11/14] glr2.cc: move strong_index_alias into the unnamed namespace, Akim Demaille, 2021/09/12
- [PATCH 12/14] glr2.cc: check linking conflicts, Akim Demaille, 2021/09/12
- [PATCH 13/14] glr2.cc: kill trailing white spaces, Akim Demaille, 2021/09/12
- [PATCH 14/14] glr2.cc: don't pass %parse-param to destroy, Akim Demaille, 2021/09/12
- Re: [PATCH 00/14] glr2.cc: fix linking conflicts, Tom Shields, 2021/09/12