mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
glr2.cc: use references to print symbols
* data/skeletons/glr2.cc (b4_symbol_action): New, so that we use `yyval` and `yyloc` rather than the `yyvaluep` and `yylocationp` pointers. (yy_symbol_value_print_, yy_symbol_print_, yy_destroy_): Use references rather than pointers. Drop support for the undocumented, obsolete, `yyoutput` variable. Adjust callers. (glr_state::destroy): Don't use yy_symbol_print_ when we don't have a symbol. Rather, write dedicated code.
This commit is contained in:
@@ -126,6 +126,26 @@ m4_define([b4_rhs_location],
|
|||||||
[(b4_rhs_data([$1], [$2]).yyloc)])
|
[(b4_rhs_data([$1], [$2]).yyloc)])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_action(SYMBOL-NUM, KIND)
|
||||||
|
# ----------------------------------
|
||||||
|
# Run the action KIND (destructor or printer) for SYMBOL-NUM.
|
||||||
|
# Same as in C, but using references instead of pointers.
|
||||||
|
m4_define([b4_symbol_action],
|
||||||
|
[b4_symbol_if([$1], [has_$2],
|
||||||
|
[b4_dollar_pushdef([yyval],
|
||||||
|
[$1],
|
||||||
|
[],
|
||||||
|
[yyloc])dnl
|
||||||
|
_b4_symbol_case([$1])[]dnl
|
||||||
|
b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
|
||||||
|
b4_symbol([$1], [$2])
|
||||||
|
b4_syncline([@oline@], [@ofile@])dnl
|
||||||
|
break;
|
||||||
|
|
||||||
|
b4_dollar_popdef[]dnl
|
||||||
|
])])
|
||||||
|
|
||||||
|
|
||||||
# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
|
# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
m4_define([b4_call_merger],
|
m4_define([b4_call_merger],
|
||||||
@@ -316,18 +336,18 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
|
|||||||
public:
|
public:
|
||||||
/// \brief Report a symbol value on the debug stream.
|
/// \brief Report a symbol value on the debug stream.
|
||||||
/// \param yykind The symbol kind.
|
/// \param yykind The symbol kind.
|
||||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
/// \param yyval Its semantic value.]b4_locations_if([[
|
||||||
/// \param yylocationp Its location.]])[
|
/// \param yyloc Its location.]])[
|
||||||
virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
|
virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
const value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[) const;
|
const location_type& yyloc]])[) const;
|
||||||
/// \brief Report a symbol on the debug stream.
|
/// \brief Report a symbol on the debug stream.
|
||||||
/// \param yykind The symbol kind.
|
/// \param yykind The symbol kind.
|
||||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
/// \param yyval Its semantic value.]b4_locations_if([[
|
||||||
/// \param yylocationp Its location.]])[
|
/// \param yyloc Its location.]])[
|
||||||
virtual void yy_symbol_print_ (symbol_kind_type yykind,
|
virtual void yy_symbol_print_ (symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
const value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[) const;
|
const location_type& yyloc]])[) const;
|
||||||
private:
|
private:
|
||||||
/// Debug stream.
|
/// Debug stream.
|
||||||
std::ostream* yycdebug_;
|
std::ostream* yycdebug_;
|
||||||
@@ -354,8 +374,8 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
|
|||||||
/// If null, print nothing.
|
/// If null, print nothing.
|
||||||
/// \param yykind The symbol kind.
|
/// \param yykind The symbol kind.
|
||||||
void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
|
void yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[);
|
location_type& yyloc]])[);
|
||||||
|
|
||||||
]b4_parse_param_vars[
|
]b4_parse_param_vars[
|
||||||
};
|
};
|
||||||
@@ -1555,12 +1575,18 @@ void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class
|
|||||||
check_ ();]])[
|
check_ ();]])[
|
||||||
if (yyresolved)
|
if (yyresolved)
|
||||||
yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
|
yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
|
||||||
&value ()]b4_locations_if([, &yyloc])[);
|
value ()]b4_locations_if([, yyloc])[);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"),
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
yy_accessing_symbol(yylrState), YY_NULLPTR, &yyloc);
|
YYCDEBUG << yymsg
|
||||||
|
<< (firstVal() ? " unresolved " : " incomplete ")
|
||||||
|
<< (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm")
|
||||||
|
<< ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
|
||||||
|
<< " ("]b4_locations_if([[
|
||||||
|
<< yyloc << ": "]])[
|
||||||
|
<< ")\n";
|
||||||
|
#endif
|
||||||
if (firstVal() != YY_NULLPTR)
|
if (firstVal() != YY_NULLPTR)
|
||||||
{
|
{
|
||||||
semantic_option& yyoption = *firstVal ();
|
semantic_option& yyoption = *firstVal ();
|
||||||
@@ -1882,8 +1908,8 @@ public:
|
|||||||
std::cerr << " $" << yyi + 1 << " = ";
|
std::cerr << " $" << yyi + 1 << " = ";
|
||||||
yyparser.yy_symbol_print_
|
yyparser.yy_symbol_print_
|
||||||
(yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
|
(yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
|
||||||
&yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
|
yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
|
||||||
&]b4_rhs_location(yynrhs, yyi + 1)])[);
|
]b4_rhs_location(yynrhs, yyi + 1)])[);
|
||||||
if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
|
if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
|
||||||
std::cerr << " (unresolved)";
|
std::cerr << " (unresolved)";
|
||||||
std::cerr << '\n';
|
std::cerr << '\n';
|
||||||
@@ -2012,7 +2038,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (this->yychar != ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[)
|
if (this->yychar != ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[)
|
||||||
yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
|
yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
|
||||||
YYTRANSLATE (this->yychar), &this->yylval]b4_locations_if([, &this->yylloc])[);
|
YYTRANSLATE (this->yychar), this->yylval]b4_locations_if([, this->yylloc])[);
|
||||||
popall_ ();
|
popall_ ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2210,7 +2236,7 @@ public:
|
|||||||
YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
|
YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
|
||||||
yysymbol_kind_t yytoken = YYTRANSLATE (this->yychar);
|
yysymbol_kind_t yytoken = YYTRANSLATE (this->yychar);
|
||||||
yyparser.yy_destroy_ ("Error: discarding",
|
yyparser.yy_destroy_ ("Error: discarding",
|
||||||
yytoken, &yylval]b4_locations_if([, &yylloc])[);]b4_variant_if([[
|
yytoken, yylval]b4_locations_if([, yylloc])[);]b4_variant_if([[
|
||||||
// Value type destructor.
|
// Value type destructor.
|
||||||
]b4_symbol_variant([[YYTRANSLATE (this->yychar)]], [[yylval]], [[template destroy]])])[
|
]b4_symbol_variant([[YYTRANSLATE (this->yychar)]], [[yylval]], [[template destroy]])])[
|
||||||
this->yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[;
|
this->yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[;
|
||||||
@@ -2249,8 +2275,8 @@ public:
|
|||||||
location_type yyerrloc;
|
location_type yyerrloc;
|
||||||
yyerror_range[2].getState().yyloc = this->yylloc;
|
yyerror_range[2].getState().yyloc = this->yylloc;
|
||||||
YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
|
YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
|
||||||
YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol(yytable[yyj]),
|
YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
|
||||||
&yylval, &yyerrloc);
|
yylval, yyerrloc);
|
||||||
yyglrShift (create_state_set_index(0), yytable[yyj],
|
yyglrShift (create_state_set_index(0), yytable[yyj],
|
||||||
yys->yyposn, yylval]b4_locations_if([, yyerrloc])[);
|
yys->yyposn, yylval]b4_locations_if([, yyerrloc])[);
|
||||||
yys = firstTopState();
|
yys = firstTopState();
|
||||||
@@ -2426,7 +2452,7 @@ public:
|
|||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
#endif // YY_EXCEPTIONS
|
#endif // YY_EXCEPTIONS
|
||||||
YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), yyvalp, yylocp);
|
YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp);
|
||||||
|
|
||||||
return yyok;
|
return yyok;
|
||||||
# undef yyerrok
|
# undef yyerrok
|
||||||
@@ -2751,7 +2777,7 @@ private:
|
|||||||
{
|
{
|
||||||
yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
|
yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
|
||||||
yy_accessing_symbol (yys.yylrState),
|
yy_accessing_symbol (yys.yylrState),
|
||||||
&this->yylval]b4_locations_if([, yylocp])[);
|
this->yylval]b4_locations_if([, *yylocp])[);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
|
yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
|
||||||
@@ -2921,7 +2947,7 @@ yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_s
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
yytoken = YYTRANSLATE (yycharp);
|
yytoken = YYTRANSLATE (yycharp);
|
||||||
YY_SYMBOL_PRINT ("Next token is", yytoken, &yystack.yylval, &yystack.yylloc);
|
YY_SYMBOL_PRINT ("Next token is", yytoken, yystack.yylval, yystack.yylloc);
|
||||||
}
|
}
|
||||||
return yytoken;
|
return yytoken;
|
||||||
}
|
}
|
||||||
@@ -3127,7 +3153,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
break;
|
break;
|
||||||
if (yyisShiftAction (yyaction))
|
if (yyisShiftAction (yyaction))
|
||||||
{
|
{
|
||||||
YY_SYMBOL_PRINT ("Shifting", yytoken, &yystack.yylval, &yystack.yylloc);
|
YY_SYMBOL_PRINT ("Shifting", yytoken, yystack.yylval, yystack.yylloc);
|
||||||
yystack.yychar = token::]b4_symbol(empty, id)[;
|
yystack.yychar = token::]b4_symbol(empty, id)[;
|
||||||
yyposn += 1;
|
yyposn += 1;
|
||||||
// FIXME: we should move yylval.
|
// FIXME: we should move yylval.
|
||||||
@@ -3207,7 +3233,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
= yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
|
= yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
|
||||||
/* Note that yyconflicts were handled by yyprocessOneStack. */
|
/* Note that yyconflicts were handled by yyprocessOneStack. */
|
||||||
YYCDEBUG << "On stack " << yys.get() << ", ";
|
YYCDEBUG << "On stack " << yys.get() << ", ";
|
||||||
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yystack.yylval, &yystack.yylloc);
|
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, yystack.yylval, yystack.yylloc);
|
||||||
yystack.yyglrShift (yys, yyaction, yyposn, yystack.yylval]b4_locations_if([, yystack.yylloc])[);
|
yystack.yyglrShift (yys, yyaction, yyposn, yystack.yylval]b4_locations_if([, yystack.yylloc])[);
|
||||||
YYCDEBUG << "Stack " << yys.get() << " now in state "
|
YYCDEBUG << "Stack " << yys.get() << " now in state "
|
||||||
<< yystack.topState(yys)->yylrState << '\n';
|
<< yystack.topState(yys)->yylrState << '\n';
|
||||||
@@ -3343,16 +3369,16 @@ b4_dollar_popdef])[]dnl
|
|||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
|
]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[)
|
location_type& yyloc]])[)
|
||||||
{
|
{
|
||||||
YY_USE (yyvaluep);]b4_locations_if([[
|
YY_USE (yyval);]b4_locations_if([[
|
||||||
YY_USE (yylocationp);]])[
|
YY_USE (yyloc);]])[
|
||||||
if (!yymsg)
|
if (!yymsg)
|
||||||
yymsg = "Deleting";
|
yymsg = "Deleting";
|
||||||
]b4_parser_class[& yyparser = *this;
|
]b4_parser_class[& yyparser = *this;
|
||||||
YY_USE (yyparser);
|
YY_USE (yyparser);
|
||||||
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
|
YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
|
||||||
|
|
||||||
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
||||||
]b4_symbol_actions([destructor])[
|
]b4_symbol_actions([destructor])[
|
||||||
@@ -3366,26 +3392,25 @@ b4_dollar_popdef])[]dnl
|
|||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
|
]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
const value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[) const
|
const location_type& yyloc]])[) const
|
||||||
{]b4_locations_if([[
|
{]b4_locations_if([[
|
||||||
YY_USE (yylocationp);]])[
|
YY_USE (yyloc);]])[
|
||||||
YY_USE (yyvaluep);
|
YY_USE (yyval);
|
||||||
std::ostream& yyo = debug_stream ();
|
std::ostream& yyo = debug_stream ();
|
||||||
std::ostream& yyoutput = yyo;
|
YY_USE (yyo);
|
||||||
YY_USE (yyoutput);
|
|
||||||
]b4_symbol_actions([printer])[
|
]b4_symbol_actions([printer])[
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
|
]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
|
||||||
const value_type* yyvaluep]b4_locations_if([[,
|
const value_type& yyval]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[) const
|
const location_type& yyloc]])[) const
|
||||||
{
|
{
|
||||||
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
|
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
|
||||||
<< ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
|
<< ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
|
||||||
<< *yylocationp << ": "]])[;
|
<< yyloc << ": "]])[;
|
||||||
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
|
yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[);
|
||||||
*yycdebug_ << ')';
|
*yycdebug_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user