bison-patches
[Top][All Lists]
Advanced

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

glr2.cc: factor the computation of the accessing symbol


From: Akim Demaille
Subject: glr2.cc: factor the computation of the accessing symbol
Date: Sun, 20 Dec 2020 08:27:05 +0100

commit 061aa57cf86a9da760098630a456755135da5543
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun Dec 20 07:52:05 2020 +0100

    glr2.cc: factor the computation of the accessing symbol
    
    * data/skeletons/glr2.cc (yy_accessing_symbol): New, as in glr.c.
    Use it.

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 209c976f..93c6e52b 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -1190,6 +1190,13 @@ class semantic_option {
   YYLTYPE yyloc;]])[
 };
 
+/** Accessing symbol of state YYSTATE.  */
+static inline yysymbol_kind_t
+yy_accessing_symbol (state_num yystate)
+{
+  return YY_CAST (yysymbol_kind_t, yystos[yystate]);
+}
+
 /** Type of the items in the GLR stack.
  *  It can be either a glr_state or a semantic_option. The is_state_ field
  *  indicates which item of the union is valid.  */
@@ -1394,12 +1401,12 @@ void glr_state::destroy (char const* yymsg, 
]b4_namespace_ref[::]b4_parser_class
 {]b4_parse_assert_if([[
   check_ ();]])[
   if (yyresolved)
-    yyparser.yy_destroy_ (yymsg, 
static_cast<yysymbol_kind_t>(yystos[yylrState]),
+    yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
                 &semanticVal()]b4_locations_if([, &yyloc])[);
   else
     {
       YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"),
-                       static_cast<yysymbol_kind_t>(yystos[yylrState]), 
YY_NULLPTR, &yyloc);
+                       yy_accessing_symbol(yylrState), YY_NULLPTR, &yyloc);
 
       if (firstVal() != YY_NULLPTR)
         {
@@ -1421,7 +1428,6 @@ yypreference (const semantic_option& y0, const 
semantic_option& y1);
 static void
 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1);
 
-
 /** Left-hand-side symbol for rule #YYRULE.  */
 static inline yysymbol_kind_t
 yylhsNonterm (rule_num yyrule)
@@ -1698,7 +1704,7 @@ class state_stack {
       {
         std::cerr << "   $" << yyi + 1 << " = ";
         yyparser.yy_symbol_print_
-          (static_cast<yysymbol_kind_t>(yystos[yyvsp[yyi - yynrhs + 
1].getState().yylrState]),
+          (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
            &yyvsp[yyi - yynrhs + 
1].getState().semanticVal()]b4_locations_if([[,
            &]b4_rhs_location(yynrhs, yyi + 1)])[);
         if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
@@ -1835,7 +1841,7 @@ class state_stack {
       {
         if (yystates[yyi]->yyresolved)
           {
-            std::string yysym = 
]b4_namespace_ref::b4_parser_class[::symbol_name 
(static_cast<yysymbol_kind_t>(yystos[yystates[yyi]->yylrState]));
+            std::string yysym = 
]b4_namespace_ref::b4_parser_class[::symbol_name (yy_accessing_symbol 
(yystates[yyi]->yylrState));
             if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
               std::cerr << std::string(yyindent + 2, ' ') << yysym
                         << " <empty>\n";
@@ -2113,7 +2119,7 @@ public:
                 YYLTYPE yyerrloc;
                 yyerror_range[2].getState().yyloc = yylloc;
                 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
-                YY_SYMBOL_PRINT ("Shifting", 
static_cast<yysymbol_kind_t>(yystos[yytable[yyj]]),
+                YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol(yytable[yyj]),
                                  &yylval, &yyerrloc);
                 yyglrShift (create_state_set_index(0), yytable[yyj],
                             yys->yyposn, yylval]b4_locations_if([, 
&yyerrloc])[);
@@ -2587,7 +2593,7 @@ public:
                   if (yyflag != yyok)
                     {
                       yyparser.yy_destroy_ ("Cleanup: discarding incompletely 
merged value for",
-                                  
static_cast<yysymbol_kind_t>(yystos[yys.yylrState]),
+                                  yy_accessing_symbol(yys.yylrState),
                                   &yysval]b4_locations_if([, yylocp])[);
                       break;
                     }




reply via email to

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