From: Akim Demaille Date: Mon, 14 Nov 2005 15:18:34 +0000 (+0000) Subject: "Use" parse parameters. X-Git-Tag: v2.3b~573 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/613d8952e3d720e8a4d626de441d87b45548b10b "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. --- diff --git a/ChangeLog b/ChangeLog index 01407529..e801e06f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-11-14 Akim Demaille + + "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. + 2005-11-14 Akim Demaille * data/glr.c (yyexpandGLRStack): Declare only if defined. diff --git a/data/c.m4 b/data/c.m4 index b0221e8e..cef534b2 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -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]); diff --git a/data/glr.c b/data/glr.c index f9792b32..626af41d 100644 --- a/data/glr.c +++ b/data/glr.c @@ -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. */ diff --git a/data/glr.cc b/data/glr.cc index 824ce767..3a636f05 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -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] << " ("