glr2.cc: also run all the calculator tests

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
Having looked at calc.at for Adela's report, I noticed that glr2.cc
does not run all the calc tests.  They uncovered a few issues.  The
good news is: fixing them simplifies the skeleton even further.

Cheers!

commit d58de95569cdde9cb677494ca087eb653c55b176
Author: Akim Demaille <[email protected]>
Date:   Sun Sep 20 17:20:50 2020 +0200

    glr2.cc: also run all the calculator tests
    
    This revealed issues with yy_symbol_print and yy_reduce_print.
    
    * tests/calc.at (AT_CHECK_CALC_GLR_CC): Also check glr2.cc.
    * data/skeletons/glr2.cc: Don't pass the user arguments to
    yy_symbol_print and yy_reduce_print, since they have it in the parser
    object.

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 01576fa6..2a7d2d6c 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -715,7 +715,7 @@ enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
     if (yydebug)                                                        \
       {                                                                 \
         std::cerr << Title << ' ';                                      \
-        yyparser.yy_symbol_print_ (Type, Value]b4_locuser_args([Location])[);\
+        yyparser.yy_symbol_print_ (Type, Value]b4_locations_if([, Location])[); \
         std::cerr << '\n';                                              \
       }                                                                 \
   } while (0)
@@ -1634,7 +1634,7 @@ class state_stack {
 
   inline void
   yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk,
-                   rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& yyparser]b4_user_formals[)
+                   rule_num yyrule, ]b4_namespace_ref[::]b4_parser_class[& yyparser)
   {
     int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
     int yylow = 1;])[
@@ -1648,9 +1648,8 @@ class state_stack {
         std::cerr << "   $" << yyi + 1 << " = ";
         yyparser.yy_symbol_print_
           (static_cast<yysymbol_kind_t>(yystos[yyvsp[yyi - yynrhs + 1].getState().yylrState]),
-           &yyvsp[yyi - yynrhs + 1].getState().semanticVal()]b4_locations_if([,
-           &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
-           b4_user_args[);
+           &yyvsp[yyi - yynrhs + 1].getState().semanticVal()]b4_locations_if([[,
+           &]b4_rhs_location(yynrhs, yyi + 1)])[);
         if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
           std::cerr <<  " (unresolved)";
         std::cerr <<  '\n';
@@ -1816,13 +1815,12 @@ class glr_stack
 {
 public:
 
-  glr_stack(size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
-    : yyerrState(0)
-    , yystateStack(yysize)
-    , yyerrcnt(0)
-    , yyrawchar(0)
-    , yyparser(yyparser_yyarg)]m4_ifset([b4_parse_param], [
-    , b4_parse_param_cons])[
+  glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
+    : yyerrState (0)
+    , yystateStack (yysize)
+    , yyerrcnt (0)
+    , yyrawchar (0)
+    , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
   {}
 
   ~glr_stack ()
@@ -2274,7 +2272,7 @@ public:
         /* Standard special case: single stack.  */
         YYASSERT (yyk.get() == 0);
         glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
-        YY_REDUCE_PRINT ((true, yyrhs, yyk, yyrule, yyparser]b4_user_args[));
+        YY_REDUCE_PRINT ((true, yyrhs, yyk, yyrule, yyparser));
         YYRESULTTAG res =  yyuserAction (yyrule, yynrhs, yyrhs,
                              yyvalp]b4_locations_if([, yylocp])[);
         yystateStack.pop_back(static_cast<size_t>(yynrhs));
@@ -2296,7 +2294,7 @@ public:
           }
         yystateStack.yyupdateSplit (*yys);
         yystateStack.setTopAt(yyk, yys);
-        YY_REDUCE_PRINT ((false, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule, yyparser]b4_user_args[));
+        YY_REDUCE_PRINT ((false, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule, yyparser));
         return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
                              yyvalp]b4_locations_if([, yylocp])[);
       }
diff --git a/tests/calc.at b/tests/calc.at
index 7da61af4..f1033517 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -1239,7 +1239,9 @@ AT_CHECK_CALC([%skeleton "glr.cc"])
 AT_CHECK_CALC([%skeleton "glr2.cc"])
 
 m4_define([AT_CHECK_CALC_GLR_CC],
-[AT_CHECK_CALC([%language "C++" %glr-parser] $@)])
+[AT_CHECK_CALC([%language "C++" %glr-parser] $@) # glr.cc
+AT_CHECK_CALC([%skeleton "glr2.cc"] $@)
+])
 
 AT_CHECK_CALC_GLR_CC([])
 AT_CHECK_CALC_GLR_CC([%locations])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.