lalr1.cc: check (and fix) %printer exception safety

* tests/c++.at (Exception safety): Let the parser support the --debug
option.
On 'p', throw an exception from the %printer.
* data/lalr1.cc (yyparse): Do not display the values we discard, as it
uses %printer, which might have thrown the exception.
This commit is contained in:
Akim Demaille
2012-09-25 11:41:22 +02:00
parent a26424642b
commit 25a6ad2f10
2 changed files with 44 additions and 17 deletions

View File

@@ -227,6 +227,7 @@ b4_user_stype
/// \brief Reclaim the memory associated to a symbol.
/// \param yymsg Why this token is reclaimed.
/// If null, do not display the symbol, just free it.
/// \param yytype The symbol type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
@@ -446,7 +447,8 @@ do { \
YYUSE (yymsg);
YYUSE (yyvaluep);
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
if (yymsg)
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
@@ -841,20 +843,22 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
}
catch (...)
{
YYCDEBUG << "Exception caught" << std::endl;
YYCDEBUG << "Exception caught: cleaning lookahead and stack"
<< std::endl;
// Do not try to display the values of the reclaimed symbols,
// as their printer might throw an exception.
if (yychar != yyempty_)
{
/* Make sure we have latest lookahead translation. See
comments at user semantic actions for why this is
necessary. */
yytoken = yytranslate_ (yychar);
yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
&yylloc);
yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc);
}
while (1 < yystate_stack_.height ())
{
yydestruct_ ("Cleanup: popping",
yydestruct_ (YY_NULL,
yystos_[yystate_stack_[0]],
&yysemantic_stack_[0],
&yylocation_stack_[0]);