On Mon, Sep 18, 2006 at 10:34:39AM -0700, Paul Eggert wrote:
> Bob Rossi <[EMAIL PROTECTED]> writes:
> 
> >> Why the #ifdef on YYLTYPE_IS_TRIVIAL?  YYLTYPE_IS_TRIVIAL tells
> >> us whether yyltype is trivial (i.e., does not need attention by
> >> C++ storage managers), not whether it exists.
> >
> > OK, I need to determine if YYLTYPE is exists. What's the best way 
> > to do that?
> 
> b4_locations_if.
> 
> >>        status = yypushparse (ctx, ch, yylval, yylloc);
> > ...
> > I'm not sure that I like passing all the values into yypushparse though.
> > The problem is, not everyone wants to pass all the values in. We would
> > force them to pass values in that they don't care about which could
> > be confusing.
> 
> They always need to pass in ctx, ch, right?  And the ", yylloc"
> will be required if b4_locations_if says you're using locations.
> So the only questionable argument will be yylval.
> 
> One way to address this issue would be to have two entry points:
> 
>        status = yypushparse (ctx, ch, yylloc);
> 
> for tokens that have no semantic value, and
> 
>        status = yypushparseval (ctx, ch, yylval, yylloc);
> 
> for tokens that do.
> 
> Another possibility, which will avoid a copy in some cases if semantic
> values are large, is to pass a pointer:
> 
>        status = yypushparse (ctx, ch, &yylval, yylloc);
> 
> where you pass a NULL pointer if the token has no semantic value.  If
> the copying issue is of concern, it may also make sense to pass yylloc's
> address too:
> 
>        status = yypushparse (ctx, ch, &yylval, &yylloc);
> 
> I don't know whether the copying concern is enough to affect
> performance, though.

I'm not decided on how to modify the yypushparse function parameters.
Have you made up your mind?

Attached is a patch on some changes we both agree on. That is remove the
constant 4 from the user and use YYPUSH_MORE. Also, make yypushparse
return an int, instead of void. This has the benefit of removing the
yyresult_get function.

2006-09-20  Bob Rossi  <[EMAIL PROTECTED]>

        * data/push.c (yyresult_get): Remove function.
        (YYPUSH_MORE): Add #define.
        (yypushparse): Modify return value.

Thanks,
Bob Rossi
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.1
diff -u -r1.1 push.c
--- data/push.c 15 Sep 2006 15:56:26 -0000      1.1
+++ data/push.c 21 Sep 2006 02:11:17 -0000
@@ -162,7 +162,7 @@
 #define yydebug b4_prefix[]debug
 #define yynerrs b4_prefix[]nerrs
 b4_locations_if([#define yylloc b4_prefix[]lloc])
-b4_push_if([#define yyresult_get b4_prefix[]result_get
+b4_push_if([
 #define yychar_set b4_prefix[]char_set
 #define yylval_set b4_prefix[]lval_set
 #define yylloc_set b4_prefix[]lloc_set])])[
@@ -973,14 +973,14 @@
 
 ]b4_push_if([
 struct yypvars;
-]b4_c_function_decl([yyresult_get], [int], [[struct yypvars *YYPVARS], 
[YYPVARS]])[
+#define YYPUSH_MORE 4
 ]b4_c_function_decl([yychar_set], [void], [[struct yypvars *YYPVARS], 
[YYPVARS]], [[int yychar], [yychar]])[
 ]b4_c_function_decl([yylval_set], [void], [[struct yypvars *YYPVARS], 
[YYPVARS]], [[YYSTYPE yylval], [yylval]])[
 #ifdef YYLTYPE_IS_TRIVIAL
 ]b4_c_function_decl([yylloc_set], [void], [[struct yypvars *YYPVARS], 
[YYPVARS]], [[YYLTYPE yylloc], [yylloc]])[
 #endif
 ]b4_c_function_decl([yypvarsinit], [void *], [[void], []])[
-]b4_c_function_decl([yypushparse], [void],
+]b4_c_function_decl([yypushparse], [int],
    [[struct yypvars *YYPVARS], [YYPVARS]])[
 ])[
 
@@ -1103,12 +1103,6 @@
   return (void*) pv;
 }
 
-int
-yyresult_get (struct yypvars *YYPVARS)
-{
-  return YYPVARS->yyresult;
-}
-
 void
 yychar_set (struct yypvars *YYPVARS, int yychar)
 {
@@ -1143,7 +1137,7 @@
 `-------------------------*/
 
 b4_push_if([
-b4_c_function_def([yypushparse], [void], [[struct yypvars *YYPVARS], 
[YYPVARS]])],[
+b4_c_function_def([yypushparse], [int], [[struct yypvars *YYPVARS], 
[YYPVARS]])],[
 #ifdef YYPARSE_PARAM
 b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
 #else /* ! YYPARSE_PARAM */
@@ -1423,7 +1417,7 @@
        pv->yylen             = yylen;
        pv->yyval             = yyval;
        ]b4_locations_if([pv->yyloc = yyloc;])[
-        return;
+        return yyresult;
 gottoken:
         YYDPRINTF((stderr, "Reading a token: "));],[
        YYDPRINTF ((stderr, "Reading a token: "));
@@ -1717,10 +1711,9 @@
   if (yymsg != yymsgbuf_ptr)
     YYSTACK_FREE (yymsg);
 #endif
-  ]b4_push_if([pv->yyresult = YYID (yyresult);],[
+  ]b4_push_if([pv->yyresult = YYID (yyresult);])[
     /* Make sure YYID is used.  */
     return YYID (yyresult);
-  ])[
 ]}
 
 b4_push_if([
@@ -1738,9 +1731,8 @@
 #ifdef YYLTYPE_IS_TRIVIAL
     yylloc_set (ctx, yylloc);
 #endif
-    yypushparse (ctx);
-    status = yyresult_get (ctx);
-  } while (status == 4);
+    status = yypushparse (ctx);
+  } while (status == YYPUSH_MORE);
   free (ctx);
   return status;
 ]}])
@@ -1788,7 +1780,8 @@
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
-]b4_push_if([struct ]b4_prefix[pvars;])[
+]b4_push_if([struct ]b4_prefix[pvars;
+#define YYPUSH_MORE 4])[
 ]b4_pure_if([],
           [extern YYLTYPE b4_prefix[]lloc;])
 )dnl b4_locations_if

Reply via email to