mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 01:33:03 +00:00
glr.c: reduce variable scopes.
* data/glr.c: Where appropriate, fuse variable declarations followed by assignments by variable declarations with a value. Where appropriate, introduce new scopes to limit variable spans.
This commit is contained in:
committed by
Akim Demaille
parent
a0cd287e64
commit
aebb55eb92
84
data/glr.c
84
data/glr.c
@@ -868,9 +868,8 @@ static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
|
|||||||
static void
|
static void
|
||||||
yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
|
yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
|
||||||
{
|
{
|
||||||
yyGLRState* s;
|
|
||||||
int i;
|
int i;
|
||||||
s = yyvsp[yylow0].yystate.yypred;
|
yyGLRState *s = yyvsp[yylow0].yystate.yypred;
|
||||||
for (i = yylow0-1; i >= yylow1; i -= 1)
|
for (i = yylow0-1; i >= yylow1; i -= 1)
|
||||||
{
|
{
|
||||||
YYASSERT (s->yyresolved);
|
YYASSERT (s->yyresolved);
|
||||||
@@ -1198,9 +1197,9 @@ yyexpandGLRStack (yyGLRStack* yystackp)
|
|||||||
{
|
{
|
||||||
yyGLRStackItem* yynewItems;
|
yyGLRStackItem* yynewItems;
|
||||||
yyGLRStackItem* yyp0, *yyp1;
|
yyGLRStackItem* yyp0, *yyp1;
|
||||||
size_t yysize, yynewSize;
|
size_t yynewSize;
|
||||||
size_t yyn;
|
size_t yyn;
|
||||||
yysize = yystackp->yynextFree - yystackp->yyitems;
|
size_t yysize = yystackp->yynextFree - yystackp->yyitems;
|
||||||
if (YYMAXDEPTH - YYHEADROOM < yysize)
|
if (YYMAXDEPTH - YYHEADROOM < yysize)
|
||||||
yyMemoryExhausted (yystackp);
|
yyMemoryExhausted (yystackp);
|
||||||
yynewSize = 2*yysize;
|
yynewSize = 2*yysize;
|
||||||
@@ -1223,7 +1222,7 @@ yyexpandGLRStack (yyGLRStack* yystackp)
|
|||||||
YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
|
YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
|
||||||
if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
|
if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
|
||||||
yys1->yysemantics.yyfirstVal =
|
yys1->yysemantics.yyfirstVal =
|
||||||
YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
|
YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1509,8 +1508,8 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
|
|||||||
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
|
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
|
||||||
if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
|
if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
|
||||||
{
|
{
|
||||||
yyGLRState* yyp, *yysplit = yystackp->yysplitPoint;
|
yyGLRState *yysplit = yystackp->yysplitPoint;
|
||||||
yyp = yystackp->yytops.yystates[yyi];
|
yyGLRState *yyp = yystackp->yytops.yystates[yyi];
|
||||||
while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
|
while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
|
||||||
{
|
{
|
||||||
if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
|
if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
|
||||||
@@ -1623,10 +1622,8 @@ yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yySemanticOption** yyz0p;
|
yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
|
||||||
yySemanticOption* yyz1;
|
yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
|
||||||
yyz0p = &yys0->yysemantics.yyfirstVal;
|
|
||||||
yyz1 = yys1->yysemantics.yyfirstVal;
|
|
||||||
while (YYID (yytrue))
|
while (YYID (yytrue))
|
||||||
{
|
{
|
||||||
if (yyz1 == *yyz0p || yyz1 == YY_NULL)
|
if (yyz1 == *yyz0p || yyz1 == YY_NULL)
|
||||||
@@ -1707,14 +1704,9 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
|
|||||||
YYSTYPE* yyvalp]b4_locuser_formals[)
|
YYSTYPE* yyvalp]b4_locuser_formals[)
|
||||||
{
|
{
|
||||||
yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
|
yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
|
||||||
int yynrhs;
|
int yynrhs = yyrhsLength (yyopt->yyrule);
|
||||||
int yychar_current;
|
YYRESULTTAG yyflag =
|
||||||
YYSTYPE yylval_current;]b4_locations_if([
|
yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
|
||||||
YYLTYPE yylloc_current;])[
|
|
||||||
YYRESULTTAG yyflag;
|
|
||||||
|
|
||||||
yynrhs = yyrhsLength (yyopt->yyrule);
|
|
||||||
yyflag = yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
|
|
||||||
if (yyflag != yyok)
|
if (yyflag != yyok)
|
||||||
{
|
{
|
||||||
yyGLRState *yys;
|
yyGLRState *yys;
|
||||||
@@ -1727,18 +1719,20 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
|
|||||||
if (yynrhs == 0)
|
if (yynrhs == 0)
|
||||||
/* Set default location. */
|
/* Set default location. */
|
||||||
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
|
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
|
||||||
yychar_current = yychar;
|
{
|
||||||
yylval_current = yylval;]b4_locations_if([
|
int yychar_current = yychar;
|
||||||
yylloc_current = yylloc;])[
|
YYSTYPE yylval_current = yylval;]b4_locations_if([
|
||||||
yychar = yyopt->yyrawchar;
|
YYLTYPE yylloc_current = yylloc;])[
|
||||||
yylval = yyopt->yyval;]b4_locations_if([
|
yychar = yyopt->yyrawchar;
|
||||||
yylloc = yyopt->yyloc;])[
|
yylval = yyopt->yyval;]b4_locations_if([
|
||||||
yyflag = yyuserAction (yyopt->yyrule, yynrhs,
|
yylloc = yyopt->yyloc;])[
|
||||||
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
|
yyflag = yyuserAction (yyopt->yyrule, yynrhs,
|
||||||
yystackp, yyvalp]b4_locuser_args[);
|
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
|
||||||
yychar = yychar_current;
|
yystackp, yyvalp]b4_locuser_args[);
|
||||||
yylval = yylval_current;]b4_locations_if([
|
yychar = yychar_current;
|
||||||
yylloc = yylloc_current;])[
|
yylval = yylval_current;]b4_locations_if([
|
||||||
|
yylloc = yylloc_current;])[
|
||||||
|
}
|
||||||
return yyflag;
|
return yyflag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1822,13 +1816,9 @@ yyresolveLocations (yyGLRState* yys1, int yyn1,
|
|||||||
yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
|
yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
|
||||||
if (!yys1->yyresolved)
|
if (!yys1->yyresolved)
|
||||||
{
|
{
|
||||||
yySemanticOption *yyoption;
|
|
||||||
yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
|
yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
|
||||||
int yynrhs;
|
int yynrhs;
|
||||||
int yychar_current;
|
yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
|
||||||
YYSTYPE yylval_current;
|
|
||||||
YYLTYPE yylloc_current;
|
|
||||||
yyoption = yys1->yysemantics.yyfirstVal;
|
|
||||||
YYASSERT (yyoption != YY_NULL);
|
YYASSERT (yyoption != YY_NULL);
|
||||||
yynrhs = yyrhsLength (yyoption->yyrule);
|
yynrhs = yyrhsLength (yyoption->yyrule);
|
||||||
if (yynrhs > 0)
|
if (yynrhs > 0)
|
||||||
@@ -1854,16 +1844,18 @@ yyresolveLocations (yyGLRState* yys1, int yyn1,
|
|||||||
yyGLRState *yyprevious = yyoption->yystate;
|
yyGLRState *yyprevious = yyoption->yystate;
|
||||||
yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
|
yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
|
||||||
}
|
}
|
||||||
yychar_current = yychar;
|
{
|
||||||
yylval_current = yylval;
|
int yychar_current = yychar;
|
||||||
yylloc_current = yylloc;
|
YYSTYPE yylval_current = yylval;
|
||||||
yychar = yyoption->yyrawchar;
|
YYLTYPE yylloc_current = yylloc;
|
||||||
yylval = yyoption->yyval;
|
yychar = yyoption->yyrawchar;
|
||||||
yylloc = yyoption->yyloc;
|
yylval = yyoption->yyval;
|
||||||
YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
|
yylloc = yyoption->yyloc;
|
||||||
yychar = yychar_current;
|
YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
|
||||||
yylval = yylval_current;
|
yychar = yychar_current;
|
||||||
yylloc = yylloc_current;
|
yylval = yylval_current;
|
||||||
|
yylloc = yylloc_current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]])[
|
}]])[
|
||||||
|
|||||||
Reference in New Issue
Block a user