* data/yacc.cc, data/glr.cc (yydestruct): Accept an additional

argument, an informative message.
Call YY_SYMBOL_PRINT.
Adjust all callers: integrate the associated YY_SYMBOL_PRINT.
* data/lalr1.cc (destruct_): Likewise.
In addition, no longer depend on b4_yysymprint_generate and
b4_yydestruct_generate to generate these functions, do it "by
hand".
This commit is contained in:
Akim Demaille
2004-09-06 10:29:52 +00:00
parent e757bb10bc
commit a0e68930d8
5 changed files with 81 additions and 79 deletions

View File

@@ -352,6 +352,7 @@ m4_define([b4_yydestruct_generate],
]$1([yydestruct],
[static void],
[[const char *yymsg], [yymsg]],
[[int yytype], [yytype]],
[[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([,
[[YYLTYPE *yylocationp], [yylocationp]]]))[
@@ -360,6 +361,10 @@ m4_define([b4_yydestruct_generate],
(void) yyvaluep;
]b4_location_if([ (void) yylocationp;
])[
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[

View File

@@ -1698,10 +1698,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
while (yystack->yytops.yystates[0] != NULL)
{
yyGLRState *yys = yystack->yytops.yystates[0];
YY_SYMBOL_PRINT ("Error: popping",
yystos[yys->yylrState],
&yys->yysemantics.yysval, &yys->yyloc);
yydestruct (yystos[yys->yylrState],
yydestruct ("Error: popping",
yystos[yys->yylrState],
&yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
@@ -1710,10 +1708,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
yyFail (yystack][]b4_lpure_args[, NULL);
}
if (*yytokenp != YYEMPTY)
{
YY_SYMBOL_PRINT ("Error: discarding", *yytokenp, yylvalp, yyllocp);
yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[);
}
yydestruct ("Error: discarding",
*yytokenp, yylvalp]b4_location_if([, yyllocp])[);
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar);
@@ -1760,10 +1756,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
break;
}
}
YY_SYMBOL_PRINT ("Error: popping",
yystos[yys->yylrState],
&yys->yysemantics.yysval, &yys->yyloc);
yydestruct (yystos[yys->yylrState],
yydestruct ("Error: popping",
yystos[yys->yylrState],
&yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
@@ -1918,11 +1912,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
yyDone:
/* On YYABORT, free the lookahead. */
if (yystack.yyerrflag == 1 && yytoken != YYEMPTY)
{
YY_SYMBOL_PRINT ("Error: discarding lookahead",
yytoken, yylvalp, yyllocp);
yydestruct (yytoken, yylvalp]b4_location_if([, yyllocp])[);
}
yydestruct ("Error: discarding lookahead",
yytoken, yylvalp]b4_location_if([, yyllocp])[);
yyfreeGLRStack (&yystack);
return yystack.yyerrflag;

View File

@@ -115,42 +115,6 @@ m4_define([b4_cc_var_decl],
[ $1;])
# b4_yysymprint_generate(FUNCTION-DECLARATOR)
# -------------------------------------------
# Generate the "symprint_" member function.
m4_define([b4_yysymprint_generate],
[[/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
]void
yy::b4_parser_class_name::symprint_ (int yytype, const SemanticType *yyvaluep, const LocationType *yylocationp)[
{
/* Pacify ``unused variable'' warnings. */
(void) yyvaluep;
(void) yylocationp;
cdebug_ << (yytype < ntokens_ ? "token" : "nterm")
<< ' ' << name_[yytype] << " (";
switch (yytype)
{
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
[ default:
break;
}
cdebug_ << ')';
}
]])
# b4_cxx_destruct_def(IGNORED-ARGUMENTS)
# --------------------------------------
# Declare the destruct_ method.
m4_define([b4_cxx_destruct_def],
[void
yy::b4_parser_class_name::destruct_ (int yytype, SemanticType *yyvaluep, LocationType *yylocationp)[]dnl
])
# We do want M4 expansion after # for CPP macros.
m4_changecom()
@@ -316,8 +280,9 @@ namespace yy
/* Even more tables. */
inline TokenNumberType translate_ (int token);
inline void destruct_ (int yytype, SemanticType *yyvaluep,
LocationType *yylocationp);
inline void destruct_ (const char *yymsg,
int yytype,
SemanticType *yyvaluep, LocationType *yylocationp);
/* Constants. */
static const int eof_;
@@ -419,9 +384,49 @@ do { \
#define YYERROR goto yyerrorlab
#if YYDEBUG
]b4_yysymprint_generate([b4_cxx_symprint_def])[
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
void
yy::]b4_parser_class_name[::symprint_ (int yytype,
const SemanticType *yyvaluep, const LocationType *yylocationp)
{
/* Pacify ``unused variable'' warnings. */
(void) yyvaluep;
(void) yylocationp;
cdebug_ << (yytype < ntokens_ ? "token" : "nterm")
<< ' ' << name_[yytype] << " (";
switch (yytype)
{
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
[ default:
break;
}
cdebug_ << ')';
}
#endif /* ! YYDEBUG */
]b4_yydestruct_generate([b4_cxx_destruct_def])[
void
yy::]b4_parser_class_name[::destruct_ (const char *yymsg,
int yytype, SemanticType *yyvaluep, LocationType *yylocationp)
{
/* Pacify ``unused variable'' warnings. */
(void) yyvaluep;
(void) yylocationp;
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
default:
break;
}
}
int
yy::]b4_parser_class_name[::parse ()
@@ -614,19 +619,15 @@ yyerrlab:
location_stack_.pop ();
if (state_stack_.height () == 1)
YYABORT;
YY_SYMBOL_PRINT ("Error: popping",
stos_[state_stack_[0]],
&semantic_stack_[0],
&location_stack_[0]);
destruct_ (stos_[state_stack_[0]],
destruct_ ("Error: popping",
stos_[state_stack_[0]],
&semantic_stack_[0],
&location_stack_[0]);
}
}
else
{
YY_SYMBOL_PRINT ("Error: discarding", ilooka_, &value, &location);
destruct_ (ilooka_, &value, &location);
destruct_ ("Error: discarding", ilooka_, &value, &location);
looka_ = empty_;
}
}
@@ -679,10 +680,8 @@ yyerrlab1:
if (state_stack_.height () == 1)
YYABORT;
YY_SYMBOL_PRINT ("Error: popping",
stos_[state_],
&semantic_stack_[0], &location_stack_[0]);
destruct_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]);
destruct_ ("Error: popping",
stos_[state_], &semantic_stack_[0], &location_stack_[0]);
error_start_ = location_stack_[0].begin;
state_stack_.pop ();
@@ -715,8 +714,7 @@ yyacceptlab:
/* Abort. */
yyabortlab:
/* Free the lookahead. */
YY_SYMBOL_PRINT ("Error: discarding lookahead", ilooka_, &value, &location);
destruct_ (ilooka_, &value, &location);
destruct_ ("Error: discarding lookahead", ilooka_, &value, &location);
looka_ = empty_;
return 1;
}

View File

@@ -1114,15 +1114,13 @@ yyerrlab:
YYPOPSTACK;
if (yyssp == yyss)
YYABORT;
YY_SYMBOL_PRINT ("Error: popping",
yystos[*yyssp], yyvsp, yylsp);
yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
yydestruct ("Error: popping",
yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
}
}
else
{
YY_SYMBOL_PRINT ("Error: discarding", yytoken, &yylval, &yylloc);
yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
yydestruct ("Error: discarding", yytoken, &yylval]b4_location_if([, &yylloc])[);
yychar = YYEMPTY;
]b4_location_if([ *++yylerrsp = yylloc;])[
}
@@ -1178,8 +1176,7 @@ yyerrlab1:
if (yyssp == yyss)
YYABORT;
YY_SYMBOL_PRINT ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[);
yydestruct ("Error: popping", yystos[yystate], yyvsp]b4_location_if([, yylsp])[);
YYPOPSTACK;
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@@ -1209,8 +1206,8 @@ yyacceptlab:
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
YY_SYMBOL_PRINT ("Error: discarding lookahead", yytoken, &yylval, &yylloc);
yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
yydestruct ("Error: discarding lookahead",
yytoken, &yylval]b4_location_if([, &yylloc])[);
yychar = YYEMPTY;
yyresult = 1;
goto yyreturn;