glr2.cc: use YYCDEBUG, not YY_DEBUG_STREAM

* data/skeletons/glr2.cc (YY_DEBUG_STREAM): Rename as...
(YYCDEBUG): this, as in lalr1.cc.
This commit is contained in:
Akim Demaille
2020-12-26 09:44:09 +01:00
parent b9a533d63e
commit 9466c734c5
2 changed files with 38 additions and 39 deletions

1
TODO
View File

@@ -200,7 +200,6 @@ not yyGLRStack.
*** yydebug *** yydebug
It should be a member of the parser object, see lalr1.cc. Let the parser It should be a member of the parser object, see lalr1.cc. Let the parser
object decide what the debug stream is, rather than open coding std::cerr. object decide what the debug stream is, rather than open coding std::cerr.
And use YYCDEBUG rather than YY_DEBUG_STREAM.
*** Avoid pointers *** Avoid pointers
There are many places where pointers should be replaced with references. There are many places where pointers should be replaced with references.

View File

@@ -618,7 +618,7 @@ enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
]b4_yy_location_print_define[ ]b4_yy_location_print_define[
#define YY_DEBUG_STREAM if (!yydebug) {} else std::cerr #define YYCDEBUG if (!yydebug) {} else std::cerr
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
do { \ do { \
@@ -642,7 +642,7 @@ static void yypdumpstack (glr_stack* yystackp)
#else /* !]b4_api_PREFIX[DEBUG */ #else /* !]b4_api_PREFIX[DEBUG */
# define YY_DEBUG_STREAM if (true) {} else std::cerr # define YYCDEBUG if (true) {} else std::cerr
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
#endif /* !]b4_api_PREFIX[DEBUG */ #endif /* !]b4_api_PREFIX[DEBUG */
@@ -996,7 +996,7 @@ public:
if (yylastDeleted == YY_NULLPTR || !yystates.empty ()) if (yylastDeleted == YY_NULLPTR || !yystates.empty ())
return; return;
yystates.push_back (yylastDeleted); yystates.push_back (yylastDeleted);
YY_DEBUG_STREAM << "Restoring last deleted stack as stack #0.\n"; YYCDEBUG << "Restoring last deleted stack as stack #0.\n";
clearLastDeleted (); clearLastDeleted ();
} }
@@ -1013,7 +1013,7 @@ public:
{ {
if (i == j) if (i == j)
{ {
YY_DEBUG_STREAM << "Removing dead stacks.\n"; YYCDEBUG << "Removing dead stacks.\n";
} }
newsize -= 1; newsize -= 1;
} }
@@ -1028,7 +1028,7 @@ public:
yylookaheadNeeds[j] = yylookaheadNeeds[i]; yylookaheadNeeds[j] = yylookaheadNeeds[i];
if (j != i) if (j != i)
{ {
YY_DEBUG_STREAM << "Rename stack " << i << " -> " << j << ".\n"; YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n";
} }
j += 1; j += 1;
} }
@@ -2201,7 +2201,7 @@ public:
while (yystateStack.topAt(yyk) != YY_NULLPTR) while (yystateStack.topAt(yyk) != YY_NULLPTR)
{ {
const state_num yystate = topState(yyk)->yylrState; const state_num yystate = topState(yyk)->yylrState;
YY_DEBUG_STREAM << "Stack " << yyk.get() YYCDEBUG << "Stack " << yyk.get()
<< " Entering state " << yystate << '\n'; << " Entering state " << yystate << '\n';
YYASSERT (yystate != YYFINAL); YYASSERT (yystate != YYFINAL);
@@ -2211,7 +2211,7 @@ public:
const rule_num yyrule = yydefaultAction (yystate); const rule_num yyrule = yydefaultAction (yystate);
if (yyrule == 0) if (yyrule == 0)
{ {
YY_DEBUG_STREAM << "Stack " << yyk.get() << " dies.\n"; YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
yystateStack.yytops.yymarkStackDeleted (yyk); yystateStack.yytops.yymarkStackDeleted (yyk);
return yyok; return yyok;
} }
@@ -2219,7 +2219,7 @@ public:
= yyglrReduce (yyk, yyrule, yyimmediate[yyrule]); = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]);
if (yyflag == yyerr) if (yyflag == yyerr)
{ {
YY_DEBUG_STREAM << "Stack " << yyk.get() << " dies " YYCDEBUG << "Stack " << yyk.get() << " dies"
" (predicate failure or explicit user error).\n"; " (predicate failure or explicit user error).\n";
yystateStack.yytops.yymarkStackDeleted (yyk); yystateStack.yytops.yymarkStackDeleted (yyk);
return yyok; return yyok;
@@ -2237,7 +2237,7 @@ public:
for (; *yyconflicts != 0; ++yyconflicts) for (; *yyconflicts != 0; ++yyconflicts)
{ {
state_set_index yynewStack = yystateStack.yysplitStack (yyk); state_set_index yynewStack = yystateStack.yysplitStack (yyk);
YY_DEBUG_STREAM << "Splitting off stack " << yynewStack.get() YYCDEBUG << "Splitting off stack " << yynewStack.get()
<< " from " << yyk.get() << ".\n"; << " from " << yyk.get() << ".\n";
YYRESULTTAG yyflag = YYRESULTTAG yyflag =
yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]); yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]);
@@ -2246,7 +2246,7 @@ public:
yyposn]b4_locations_if([, yylocp])[)); yyposn]b4_locations_if([, yylocp])[));
else if (yyflag == yyerr) else if (yyflag == yyerr)
{ {
YY_DEBUG_STREAM << "Stack " << yynewStack.get() << " dies.\n"; YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n";
yystateStack.yytops.yymarkStackDeleted (yynewStack); yystateStack.yytops.yymarkStackDeleted (yynewStack);
} }
else else
@@ -2257,7 +2257,7 @@ public:
break; break;
else if (yyisErrorAction (yyaction)) else if (yyisErrorAction (yyaction))
{ {
YY_DEBUG_STREAM << "Stack " << yyk.get() << " dies\n"; YYCDEBUG << "Stack " << yyk.get() << " dies.\n";
yystateStack.yytops.yymarkStackDeleted (yyk); yystateStack.yytops.yymarkStackDeleted (yyk);
break; break;
} }
@@ -2267,7 +2267,7 @@ public:
= yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]); = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]);
if (yyflag == yyerr) if (yyflag == yyerr)
{ {
YY_DEBUG_STREAM << "Stack " << yyk.get() << " dies " YYCDEBUG << "Stack " << yyk.get() << " dies"
" (predicate failure or explicit user error).\n"; " (predicate failure or explicit user error).\n";
yystateStack.yytops.yymarkStackDeleted (yyk); yystateStack.yytops.yymarkStackDeleted (yyk);
break; break;
@@ -2333,7 +2333,7 @@ public:
} }
catch (const syntax_error& yyexc) catch (const syntax_error& yyexc)
{ {
YY_DEBUG_STREAM << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([
*yylocp = yyexc.location;])[ *yylocp = yyexc.location;])[
yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ()); yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ());
YYERROR; YYERROR;
@@ -2433,7 +2433,7 @@ public:
YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &yysval]b4_locations_if([, &loc])[); YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &yysval]b4_locations_if([, &loc])[);
if (yyflag == yyerr && yystateStack.isSplit()) if (yyflag == yyerr && yystateStack.isSplit())
{]b4_parse_trace_if([[ {]b4_parse_trace_if([[
YY_DEBUG_STREAM << "Parse on stack " << yyk.get() YYCDEBUG << "Parse on stack " << yyk.get ()
<< " rejected by rule " << yyrule - 1 << " rejected by rule " << yyrule - 1
<< " (line " << int (yyrline[yyrule]) << ").\n"; << " (line " << int (yyrline[yyrule]) << ").\n";
]])[} ]])[}
@@ -2456,7 +2456,7 @@ public:
} }
yystateStack.yyupdateSplit (*yys); yystateStack.yyupdateSplit (*yys);
state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[ state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[
YY_DEBUG_STREAM << "Reduced stack " << yyk.get() YYCDEBUG << "Reduced stack " << yyk.get ()
<< " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule]) << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule])
<< "); action deferred. Now in state " << yynewLRState << "); action deferred. Now in state " << yynewLRState
<< ".\n";]])[ << ".\n";]])[
@@ -2473,7 +2473,7 @@ public:
{ {
yyaddDeferredAction (yyk, yyp, yys0, yyrule); yyaddDeferredAction (yyk, yyp, yys0, yyrule);
yystateStack.yytops.yymarkStackDeleted (yyk); yystateStack.yytops.yymarkStackDeleted (yyk);
YY_DEBUG_STREAM << "Merging stack " << yyk.get() YYCDEBUG << "Merging stack " << yyk.get ()
<< " into stack " << yyi.get () << ".\n"; << " into stack " << yyi.get () << ".\n";
return yyok; return yyok;
} }
@@ -2781,7 +2781,7 @@ yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_s
]b4_parse_param_use()dnl ]b4_parse_param_use()dnl
[ if (yycharp == ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[) [ if (yycharp == ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[)
{ {
YY_DEBUG_STREAM << "Reading a token\n"; YYCDEBUG << "Reading a token\n";
#if YY_EXCEPTIONS #if YY_EXCEPTIONS
try try
{ {
@@ -2791,7 +2791,7 @@ yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_s
} }
catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc) catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
{ {
YY_DEBUG_STREAM << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
yylloc = yyexc.location;])[ yylloc = yyexc.location;])[
yyparser.error (]b4_locations_if([yylloc, ])[yyexc.what ()); yyparser.error (]b4_locations_if([yylloc, ])[yyexc.what ());
// Map errors caught in the scanner to the error token, so that error // Map errors caught in the scanner to the error token, so that error
@@ -2804,7 +2804,7 @@ yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_s
{ {
yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[; yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[;
yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(eof, kind)[; yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(eof, kind)[;
YY_DEBUG_STREAM << "Now at end of input.\n"; YYCDEBUG << "Now at end of input.\n";
} }
else else
{ {
@@ -2963,7 +2963,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
glr_stack* const yystackp = &yystack; glr_stack* const yystackp = &yystack;
size_t yyposn; size_t yyposn;
YY_DEBUG_STREAM << "Starting parse\n"; YYCDEBUG << "Starting parse\n";
yychar = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[; yychar = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[;
yylval = yyval_default;]b4_locations_if([ yylval = yyval_default;]b4_locations_if([
@@ -2992,7 +2992,7 @@ b4_dollar_popdef])[]dnl
while (true) while (true)
{ {
const state_num yystate = yystack.firstTopState()->yylrState; const state_num yystate = yystack.firstTopState()->yylrState;
YY_DEBUG_STREAM << "Entering state " << yystate << '\n'; YYCDEBUG << "Entering state " << yystate << '\n';
if (yystate == YYFINAL) if (yystate == YYFINAL)
goto yyacceptlab; goto yyacceptlab;
if (yyisDefaultedState (yystate)) if (yyisDefaultedState (yystate))
@@ -3069,7 +3069,7 @@ b4_dollar_popdef])[]dnl
if (yystack.yystateStack.yytops.size() == 0) if (yystack.yystateStack.yytops.size() == 0)
yystack.yyFail (]b4_locations_if([&yylloc, ])[YY_("syntax error")); yystack.yyFail (]b4_locations_if([&yylloc, ])[YY_("syntax error"));
YYCHK1 (yystack.yyresolveStack ()); YYCHK1 (yystack.yyresolveStack ());
YY_DEBUG_STREAM << "Returning to deterministic operation.\n";]b4_locations_if([[ YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
yystack.yyerror_range[1].getState().yyloc = yylloc;]])[ yystack.yyerror_range[1].getState().yyloc = yylloc;]])[
yystack.yyreportSyntaxError (); yystack.yyreportSyntaxError ();
goto yyuser_error; goto yyuser_error;
@@ -3090,18 +3090,18 @@ b4_dollar_popdef])[]dnl
const int yyaction = yygetLRActions (yystate, yytoken_to_shift, const int yyaction = yygetLRActions (yystate, yytoken_to_shift,
yyconflicts); yyconflicts);
/* Note that yyconflicts were handled by yyprocessOneStack. */ /* Note that yyconflicts were handled by yyprocessOneStack. */
YY_DEBUG_STREAM << "On stack " << yys.get() << ", "; YYCDEBUG << "On stack " << yys.get() << ", ";
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
yystack.yyglrShift (yys, yyaction, yyposn, yystack.yyglrShift (yys, yyaction, yyposn,
yylval]b4_locations_if([, &yylloc])[); yylval]b4_locations_if([, &yylloc])[);
YY_DEBUG_STREAM << "Stack " << yys.get() << " now in state #" YYCDEBUG << "Stack " << yys.get() << " now in state #"
<< yystack.topState(yys)->yylrState << '\n'; << yystack.topState(yys)->yylrState << '\n';
} }
if (yystack.yystateStack.yytops.size() == 1) if (yystack.yystateStack.yytops.size() == 1)
{ {
YYCHK1 (yystack.yyresolveStack ()); YYCHK1 (yystack.yyresolveStack ());
YY_DEBUG_STREAM << "Returning to deterministic operation.\n"; YYCDEBUG << "Returning to deterministic operation.\n";
yystack.yystateStack.yycompressStack (); yystack.yystateStack.yycompressStack ();
break; break;
} }