Let yyerror always receive the msg as last argument, so that

yyerror can be variadic.
* data/yacc.c (b4_yyerror_args): New.
Use it when calling yyerror.
* data/glr.c (b4_yyerror_args, b4_lyyerror_args): New.
Use it when calling yyerror.
* doc/bison.texinfo (Error Reporting): Adjust.
* tests/calc.at (_AT_DATA_CALC_Y): Adjust.
* tests/cxx-type.at (_AT_TEST_GLR_CALC): Adjust.
This commit is contained in:
Akim Demaille
2002-11-07 12:52:19 +00:00
parent 0e25cad542
commit 93724f139a
6 changed files with 74 additions and 33 deletions

View File

@@ -54,9 +54,25 @@ m4_define([b4_user_formals],
[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
# b4_yyerror_args
# ---------------
# Arguments passed to yyerror: user args plus yylloc.
m4_define([b4_yyerror_args],
[b4_pure_if([b4_location_if([yylocp, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
# b4_lyyerror_args
# ----------------
# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
m4_define([b4_lyyerror_args],
[b4_pure_if([b4_location_if([yyllocp, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
# b4_pure_args
# ------------
# Arguments passed to yyerror: user args plus yylloc.
# Arguments needed by yyerror: user args plus yylloc.
m4_define([b4_pure_args],
[b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
@@ -581,7 +597,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...)
va_start (yyap, yyformat);
yystack->yyerrflag = 1;
vsprintf (yymsg, yyformat, yyap);
yyerror (yymsg]b4_pure_args[);
yyerror (]b4_yyerror_args[yymsg);
}
longjmp (yystack->yyexception_buffer, 1);
}
@@ -636,7 +652,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
# undef YYBACKUP
# define YYBACKUP(Token, Value) \
do { \
yyerror ("syntax error: cannot back up"]b4_pure_args[); \
yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
YYERROR; \
} while (0)
@@ -1591,12 +1607,12 @@ yyreportParseError (yyGLRStack* yystack,
yyprefix = " or ";
}
}
yyerror (yymsg]b4_lpure_args[);
yyerror (]b4_lyyerror_args[yymsg);
free (yymsg);
}
else
#endif
yyerror ("parse error"]b4_lpure_args[);
yyerror (]b4_lyyerror_args["parse error");
yynerrs += 1;
}
}

View File

@@ -48,11 +48,12 @@ m4_define([b4_Pure_if],
[$2])])
# b4_pure_args
# ------------
# b4_yyerror_args
# ---------------
# Arguments passed to yyerror: user args plus yylloc.
m4_define([b4_pure_args],
[b4_Pure_if([b4_location_if([, &yylloc])])[]b4_user_args])
m4_define([b4_yyerror_args],
[b4_Pure_if([b4_location_if([&yylloc, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
# b4_lex_param
@@ -529,7 +530,7 @@ do \
} \
else \
{ \
yyerror ("syntax error: cannot back up"b4_pure_args); \
yyerror (b4_yyerror_args"syntax error: cannot back up"); \
YYERROR; \
} \
while (0)
@@ -1135,15 +1136,15 @@ yyerrlab:
yycount++;
}
}
yyerror (yymsg]b4_pure_args[);
yyerror (]b4_yyerror_args[yymsg);
YYSTACK_FREE (yymsg);
}
else
yyerror ("parse error; also virtual memory exhausted"]b4_pure_args[);
yyerror (]b4_yyerror_args["parse error; also virtual memory exhausted");
}
else
#endif /* YYERROR_VERBOSE */
yyerror ("parse error"]b4_pure_args[);
yyerror (]b4_yyerror_args["parse error");
}
goto yyerrlab1;
@@ -1258,7 +1259,7 @@ yyabortlab:
| yyoverflowlab -- parser overflow comes here. |
`----------------------------------------------*/
yyoverflowlab:
yyerror ("parser stack overflow"]b4_pure_args[);
yyerror (]b4_yyerror_args["parser stack overflow");
yyresult = 2;
/* Fall through. */
#endif