Re: glr2.cc: also run all the calculator tests
Akim Demaille <[email protected]>
| Newsgroups | gmane.comp.parsers.bison.patches |
|---|---|
| Message-ID | <[email protected]> |
> Le 20 sept. 2020 à 17:52, Akim Demaille <[email protected]> a écrit : > > 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. Superseded by the following version, which also garbage collects some now-useless macros. commit 81bf8610fec8ffa2ed25f2a6e0f87c4650679602 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. (b4_user_formals_no_comma, b4_pure_args, b4_lpure_args) (b4_locuser_formals, b4_locuser_args): Remove, useless. diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 01576fa6..504da0ac 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -352,42 +352,7 @@ b4_define_flag_if([pure]) # This is not shared with yacc.c in c.m4 because GLR relies on ISO C # formal argument declarations. m4_define([b4_user_formals], -[m4_ifset([b4_parse_param], [, b4_user_formals_no_comma])]) - -# b4_user_formals_no_comma -# ------------------------ -# The possible parse-params formal arguments. -m4_define([b4_user_formals_no_comma], -[m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)])]) - - -# b4_pure_args -# ------------ -# Optional effective arguments passed to yyerror: user args plus yylloc, and -# a leading comma. -m4_define([b4_pure_args], -[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args]) - - -# b4_lpure_args -# ------------- -# Same as above, but on the lookahead, hence &yylloc instead of yylocp. This is -# used only inside glr_stack, so there's no need to explicitly pass yyparser. -m4_define([b4_lpure_args], -[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) - - -# b4_locuser_formals(LOC = yylocp) -# -------------------------------- -# User formal arguments, possibly preceded by location argument. -m4_define([b4_locuser_formals], -[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) - - -# b4_locuser_args(LOC = yylocp) -# ----------------------------- -m4_define([b4_locuser_args], -[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args]) +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) # b4_symbol_kind(NUM) @@ -715,7 +680,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 +1599,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 +1613,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 +1780,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 +2237,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 +2259,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])