"Use" parse parameters.

* data/c.m4 (b4_parse_param_for, b4_parse_param_use): New.
* data/glr.c, data/glr.cc: Use them.
* data/glr.c (YYUSE): Have a C++ definition that supports
non-pointer types.
This commit is contained in:
Akim Demaille
2005-11-14 15:18:34 +00:00
parent b2741627b1
commit 613d8952e3
4 changed files with 58 additions and 11 deletions

View File

@@ -95,6 +95,27 @@ m4_define_default([b4_parse_param])
m4_define([b4_parse_param],
b4_parse_param))
# b4_parse_param_for(DECL, FORMAL, BODY)
# ---------------------------------------
# Iterate over the user parameters, binding the declaration to DECL,
# the formal name to FORMAL, and evaluating the BODY.
m4_define([b4_parse_param_for],
[m4_foreach([$1_$2], m4_defn([b4_parse_param]),
[m4_pushdef([$1], m4_fst($1_$2))dnl
m4_pushdef([$2], m4_shift($1_$2))dnl
$3[]dnl
m4_popdef([$2])dnl
m4_popdef([$1])dnl
])])
# b4_parse_param_use
# ------------------
# `YYUSE' all the parse-params.
# WARNING: Ends with a dnl, there must be nothing behind it.
m4_define([b4_parse_param_use],
[b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
])dnl
])
## ------------ ##
## Data Types. ##
@@ -348,6 +369,11 @@ m4_define([b4_syncline],
[[#]line $1 $2])])
## -------------- ##
## User actions. ##
## -------------- ##
# b4_symbol_actions(FILENAME, LINENO,
# SYMBOL-TAG, SYMBOL-NUM,
# SYMBOL-ACTION, SYMBOL-TYPENAME)
@@ -386,7 +412,9 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
YYUSE (yyvaluep);
]b4_location_if([ YYUSE (yylocationp);
])[
])dnl
b4_parse_param_use[]dnl
[
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
@@ -422,8 +450,8 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
YYUSE (yyvaluep);
]b4_location_if([ YYUSE (yylocationp);
])dnl
[
if (yytype < YYNTOKENS)
b4_parse_param_use[]dnl
[ if (yytype < YYNTOKENS)
YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
else
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);

View File

@@ -257,7 +257,11 @@ b4_syncline([@oline@], [@ofile@])
#endif
/* Suppress unused-variable warnings by "using" E. */
#define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e))
#if __cplusplus
# define YYUSE(e) (void) (e)
#else
# define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e))
#endif
#ifndef YYFREE
# define YYFREE free
@@ -868,8 +872,8 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
yybool yynormal __attribute__ ((__unused__)) =
(yystack->yysplitPoint == NULL);
int yylow;
# undef yyerrok
]b4_parse_param_use[]dnl
[# undef yyerrok
# define yyerrok (yystack->yyerrState = 0)
# undef YYACCEPT
# define YYACCEPT return yyaccept
@@ -1372,7 +1376,10 @@ yy_reduce_print (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
int yylow = 1;
int yyi;
YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
YYUSE (yyvalp);
YYUSE (yylocp);
]b4_parse_param_use[]dnl
[ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
(unsigned long int) yyk, yyrule - 1,
(unsigned long int) yyrline[yyrule]);
/* Print the symbols being reduced, and their result. */

View File

@@ -53,7 +53,9 @@ b4_location_if([,
[yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
(void) yyoutput;
YYUSE (yyoutput);
]b4_parse_param_use[]dnl
[
yyparser.yysymprint_ (yytype, yyvaluep]b4_location_if([, yylocationp])[);
}
]])
@@ -70,6 +72,8 @@ m4_prepend([b4_epilogue],
b4_parse_param,
[[const char* msg], [msg]])[
{
]b4_parse_param_use[]dnl
[
yyparser.error (*yylocationp, msg);
}
@@ -106,11 +110,11 @@ m4_popdef([b4_parse_param])dnl
const semantic_type* yyvaluep, const location_type* yylocationp)
{
/* Pacify ``unused variable'' warnings. */
(void) yyvaluep;
(void) yylocationp;
YYUSE (yyvaluep);
YYUSE (yylocationp);
/* Backward compatibility, but should be removed eventually. */
std::ostream& cdebug_ = *yycdebug_;
(void) cdebug_;
YYUSE (cdebug_);
*yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
<< ' ' << yytname[yytype] << " ("