glr2.cc: minor clean up

* data/skeletons/glr2.cc (YYUNDEFTOK): Now useless.
Formatting/coding style changes.
This commit is contained in:
Akim Demaille
2021-01-01 12:21:59 +01:00
parent 1283dc7243
commit 630448ba6b

View File

@@ -504,10 +504,6 @@ static ]b4_namespace_ref[::]b4_parser_class[::location_type yyloc_default][]b4_y
accessed by $0, $-1, etc., in any rule. */ accessed by $0, $-1, etc., in any rule. */
#define YYMAXLEFT ]b4_max_left_semantic_context[ #define YYMAXLEFT ]b4_max_left_semantic_context[
/* YYUNDEFTOK -- Symbol number (for yytoken) that denotes an unknown
token. */
#define YYUNDEFTOK ]b4_undef_token_number[
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */ as returned by yylex, with out-of-bounds checking. */
]b4_api_token_raw_if(dnl ]b4_api_token_raw_if(dnl
@@ -590,7 +586,7 @@ enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
YYRESULTTAG yychk_flag = YYE; \ YYRESULTTAG yychk_flag = YYE; \
if (yychk_flag != yyok) \ if (yychk_flag != yyok) \
return yychk_flag; \ return yychk_flag; \
} while (0) } while (false)
#if ]b4_api_PREFIX[DEBUG #if ]b4_api_PREFIX[DEBUG
@@ -606,7 +602,7 @@ enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr };
yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \ yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \
std::cerr << '\n'; \ std::cerr << '\n'; \
} \ } \
} while (0) } while (false)
/* Nonzero means print parse trace. It is left uninitialized so that /* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */ multiple parsers can coexist. */
@@ -666,7 +662,8 @@ class glr_stack;
typedef ]b4_namespace_ref[::strong_index_alias<struct glr_state_set_tag> state_set_index; typedef ]b4_namespace_ref[::strong_index_alias<struct glr_state_set_tag> state_set_index;
state_set_index create_state_set_index(std::ptrdiff_t value) { state_set_index create_state_set_index(std::ptrdiff_t value)
{
return state_set_index::create(value); return state_set_index::create(value);
} }
@@ -892,7 +889,7 @@ private:
union { union {
/** First in a chain of alternative reductions producing the /** First in a chain of alternative reductions producing the
* nonterminal corresponding to this state, threaded through * nonterminal corresponding to this state, threaded through
* yyfirstVal. */ * yyfirstVal. Value "0" means empty. */
std::ptrdiff_t yyfirstVal; std::ptrdiff_t yyfirstVal;
/** Semantic value for this state. */ /** Semantic value for this state. */
value_type yyval; value_type yyval;
@@ -1118,9 +1115,7 @@ public:
glr_state *yys1 = yyy1.state(); glr_state *yys1 = yyy1.state();
for (int yyn = yyrhsLength (this->yyrule); for (int yyn = yyrhsLength (this->yyrule);
yyn > 0; yyn > 0;
yyn -= 1, yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ())
yys0 = yys0->pred(),
yys1 = yys1->pred())
{ {
if (yys0 == yys1) if (yys0 == yys1)
break; break;
@@ -1145,21 +1140,19 @@ public:
break; break;
else if (yyz0 == YY_NULLPTR) else if (yyz0 == YY_NULLPTR)
{ {
if (yyz0prev != YY_NULLPTR) { if (yyz0prev != YY_NULLPTR)
yyz0prev->setNext(yyz1); yyz0prev->setNext (yyz1);
} else { else
yys0->setFirstVal(yyz1); yys0->setFirstVal (yyz1);
}
break; break;
} }
else if (yyz0 < yyz1) else if (yyz0 < yyz1)
{ {
semantic_option* yyz = yyz0; semantic_option* yyz = yyz0;
if (yyz0prev != YY_NULLPTR) { if (yyz0prev != YY_NULLPTR)
yyz0prev->setNext(yyz1); yyz0prev->setNext(yyz1);
} else { else
yys0->setFirstVal(yyz1); yys0->setFirstVal(yyz1);
}
yyz1 = yyz1->next(); yyz1 = yyz1->next();
yyz0->setNext(yyz); yyz0->setNext(yyz);
} }
@@ -1228,11 +1221,13 @@ public:
private: private:
template <typename T> template <typename T>
static const glr_stack_item* asItem(const T* state) { static const glr_stack_item* asItem(const T* state)
{
return reinterpret_cast<const glr_stack_item*>(state); return reinterpret_cast<const glr_stack_item*>(state);
} }
template <typename T> template <typename T>
static glr_stack_item* asItem(T* state) { static glr_stack_item* asItem(T* state)
{
return reinterpret_cast<glr_stack_item*>(state); return reinterpret_cast<glr_stack_item*>(state);
} }
/** The last RHS state in the list of states to be reduced. */ /** The last RHS state in the list of states to be reduced. */
@@ -1465,7 +1460,7 @@ 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"), YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"),
@@ -1473,8 +1468,8 @@ void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class
if (firstVal() != YY_NULLPTR) if (firstVal() != YY_NULLPTR)
{ {
semantic_option& yyoption = *firstVal(); semantic_option& yyoption = *firstVal ();
glr_state *yyrh = yyoption.state(); glr_state *yyrh = yyoption.state ();
for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1) for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1)
{ {
yyrh->destroy (yymsg, yyparser]b4_user_args[); yyrh->destroy (yymsg, yyparser]b4_user_args[);
@@ -1599,18 +1594,18 @@ public:
// This const_cast is okay, since anyway we have access to the mutable // This const_cast is okay, since anyway we have access to the mutable
// yyitems into which yysplitPoint points. // yyitems into which yysplitPoint points.
glr_stack_item* nextFreeItem = glr_stack_item* nextFreeItem
const_cast<glr_state*>(yysplitPoint)->asItem() + 1; = const_cast<glr_state*> (yysplitPoint)->asItem () + 1;
yysplitPoint = YY_NULLPTR; yysplitPoint = YY_NULLPTR;
yytops.clearLastDeleted(); yytops.clearLastDeleted ();
while (yyr != YY_NULLPTR) while (yyr != YY_NULLPTR)
{ {
nextFreeItem->setState(*yyr); nextFreeItem->setState (*yyr);
glr_state& nextFreeState = nextFreeItem->getState(); glr_state& nextFreeState = nextFreeItem->getState();
yyr = yyr->pred(); yyr = yyr->pred();
nextFreeState.setPred(&(nextFreeItem - 1)->getState()); nextFreeState.setPred(&(nextFreeItem - 1)->getState());
setFirstTop(&nextFreeState); setFirstTop (&nextFreeState);
++nextFreeItem; ++nextFreeItem;
} }
yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data())); yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data()));
@@ -1711,10 +1706,11 @@ public:
/** Return a fresh SemanticOption. /** Return a fresh SemanticOption.
* Callers should call yyreserveStack afterwards to make sure there is * Callers should call yyreserveStack afterwards to make sure there is
* sufficient headroom. */ * sufficient headroom. */
semantic_option& yynewSemanticOption(semantic_option newOption) { semantic_option& yynewSemanticOption (semantic_option newOption)
semantic_option& option = yyitems[yynewGLRStackItem(false)].getOption(); {
semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption ();
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
option = std::move(newOption); option = std::move (newOption);
#else #else
option = newOption; option = newOption;
#endif #endif
@@ -1920,7 +1916,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_ ();
} }
@@ -2116,7 +2112,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])[); yytoken, &yylval]b4_locations_if([, &yylloc])[);
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)[;
} }
yysymbol_kind_t yytoken = yygetToken (this->yychar, yyparser, *this]b4_user_args[); yysymbol_kind_t yytoken = yygetToken (this->yychar, yyparser, *this]b4_user_args[);
@@ -2267,7 +2263,7 @@ public:
value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) value_type* yyvalp]b4_locations_if([, location_type* yylocp])[)
{ {
bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit(); bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit();
int yylow; int yylow = 1;
]b4_parse_param_use([yyvalp], [yylocp])dnl ]b4_parse_param_use([yyvalp], [yylocp])dnl
[ YYUSE (yyrhslen); [ YYUSE (yyrhslen);
# undef yyerrok # undef yyerrok
@@ -2289,7 +2285,6 @@ public:
return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \ return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \
yyerrok, yyerr yyerrok, yyerr
yylow = 1;
if (yyrhslen == 0) if (yyrhslen == 0)
*yyvalp = yyval_default; *yyvalp = yyval_default;
else else
@@ -2580,7 +2575,6 @@ private:
semantic_option* yybest = yys.firstVal(); semantic_option* yybest = yys.firstVal();
YYASSERT(yybest != YY_NULLPTR); YYASSERT(yybest != YY_NULLPTR);
bool yymerge = false; bool yymerge = false;
value_type val;
YYRESULTTAG yyflag;]b4_locations_if([ YYRESULTTAG yyflag;]b4_locations_if([
location_type *yylocp = &yys.yyloc;])[ location_type *yylocp = &yys.yyloc;])[
@@ -2622,6 +2616,7 @@ private:
} }
} }
value_type val;
if (yymerge) if (yymerge)
{ {
int yyprec = yydprec[yybest->yyrule]; int yyprec = yydprec[yybest->yyrule];
@@ -2639,7 +2634,7 @@ private:
if (yyflag != yyok) if (yyflag != yyok)
{ {
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;
} }
@@ -2894,7 +2889,7 @@ yypreference (const semantic_option& y0, const semantic_option& y1)
default: \ default: \
goto yybuglab; \ goto yybuglab; \
} \ } \
} while (0) } while (false)
/* DEBUGGING ONLY */ /* DEBUGGING ONLY */
@@ -3066,8 +3061,8 @@ b4_dollar_popdef])[]dnl
{ {
const state_num yystate = yystack.topState(yys)->yylrState; const state_num yystate = yystack.topState(yys)->yylrState;
const short* yyconflicts; const short* yyconflicts;
const int yyaction = yygetLRActions (yystate, yytoken_to_shift, const int yyaction
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);
@@ -3209,7 +3204,7 @@ b4_dollar_popdef])[]dnl
YYUSE (yylocationp);]])[ YYUSE (yylocationp);]])[
if (!yymsg) if (!yymsg)
yymsg = "Deleting"; yymsg = "Deleting";
]b4_namespace_ref::b4_parser_class[& yyparser = *this; ]b4_parser_class[& yyparser = *this;
YYUSE (yyparser); YYUSE (yyparser);
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
@@ -3242,7 +3237,7 @@ b4_dollar_popdef])[]dnl
const location_type* yylocationp]])[) const const location_type* yylocationp]])[) const
{ {
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << ]b4_namespace_ref::b4_parser_class[::symbol_name (yykind) << " ("]b4_locations_if([[ << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[
<< *yylocationp << ": "]])[; << *yylocationp << ": "]])[;
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[); yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
*yycdebug_ << ')'; *yycdebug_ << ')';