bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 07/14] glr2.cc: move state_stack into the unnamed namespace


From: Akim Demaille
Subject: [PATCH 07/14] glr2.cc: move state_stack into the unnamed namespace
Date: Sun, 12 Sep 2021 14:07:40 +0200

* data/skeletons/glr2.cc: here.
Prefer `using` to `typedef`, this is C++11.
Use the type alias we introduced.
---
 data/skeletons/glr2.cc | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 93549639..dcb00943 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -1660,12 +1660,15 @@ void glr_state::destroy (char const* yymsg, 
]b4_namespace_ref[::]b4_parser_class
 #undef YYFILL
 #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal)
 
+namespace
+{
   class state_stack
   {
   public:
-  typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
-  typedef ]b4_namespace_ref[::]b4_parser_class[::value_type 
value_type;]b4_locations_if([[
-  typedef ]b4_namespace_ref[::]b4_parser_class[::location_type 
location_type;]])[
+    using parser_type = ]b4_namespace_ref[::]b4_parser_class[;
+    using symbol_kind = parser_type::symbol_kind;
+    using value_type = parser_type::value_type;]b4_locations_if([[
+    using location_type = parser_type::location_type;]])[
 
     /** Initialize to a single empty stack, with total maximum
      *  capacity for all stacks of YYSIZE.  */
@@ -1951,7 +1954,7 @@ public:
 
     void
     yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
-                   rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& 
yyparser)
+                     rule_num yyrule, parser_type& yyparser)
     {
       int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
       int yylow = 1;])[
@@ -2015,7 +2018,7 @@ public:
 
     YYRESULTTAG
     yyreportAmbiguity (const semantic_option& yyx0,
-                     const semantic_option& yyx1, 
]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_locations_if([, const 
location_type& yyloc])[)
+                       const semantic_option& yyx1, parser_type& 
yyparser]b4_locations_if([, const location_type& yyloc])[)
     {
       YY_USE (yyx0);
       YY_USE (yyx1);
@@ -2033,7 +2036,6 @@ public:
       return yyabort;
     }
 
-  /* DEBUGGING ONLY */
 #if ]b4_api_PREFIX[DEBUG
     /* Print YYS (possibly NULL) and its predecessors. */
     void
@@ -2067,12 +2069,12 @@ private:
 
 
   public:
-
     std::vector<glr_stack_item> yyitems;
     // Where the stack splits. Anything below this address is deterministic.
     const glr_state* yysplitPoint;
     glr_state_set yytops;
-};
+  }; // class state_stack
+} // namespace
 
 #undef YYFILL
 #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal)
@@ -2095,7 +2097,7 @@ namespace ]b4_namespace_ref[
     friend context;
   ]])[
 
-    glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& 
yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
+    glr_stack (size_t yysize, parser_type& 
yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
       : yyerrState (0)
       , yystateStack (yysize)
       , yyerrcnt (0)
@@ -2118,7 +2120,7 @@ namespace ]b4_namespace_ref[
     int yyerrcnt;
     symbol_type yyla;
     YYJMP_BUF yyexception_buffer;
-    ]b4_namespace_ref[::]b4_parser_class[& yyparser;
+    parser_type& yyparser;
 
   #define YYCHK1(YYE)                                                          
\
     do {                                                                       
\
@@ -2607,7 +2609,7 @@ namespace ]b4_namespace_ref[
        so pretend the stack is "normal". */
     YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, 
yyk, yyrule, yyparser));
     #if YY_EXCEPTIONS
-      typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error;
+      typedef parser_type::syntax_error syntax_error;
       try
       {
     #endif // YY_EXCEPTIONS
@@ -3085,7 +3087,7 @@ namespace ]b4_namespace_ref[
               yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[
             }
 #if YY_EXCEPTIONS
-          catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& 
yyexc)
+          catch (const parser_type::syntax_error& yyexc)
             {
               YYCDEBUG << "Caught exception: " << yyexc.what () << 
'\n';]b4_locations_if([
               this->yyla.location = yyexc.location;])[
-- 
2.32.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]