bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

m4_location_if


From: Akim Demaille
Subject: m4_location_if
Date: 19 Jun 2002 11:07:38 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

This is the kind of patch where M4 is a pure pleasure.  I expect to be
able to clean up many other parts, e.g., related to %pure-parser.

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * data/bison.simple (m4_location_if): New.
        Use it instead of #ifdef YYLSP_NEEDED.

Index: data/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/data/bison.simple,v
retrieving revision 1.38
diff -u -u -r1.38 bison.simple
--- data/bison.simple 19 Jun 2002 08:22:49 -0000 1.38
+++ data/bison.simple 19 Jun 2002 09:02:49 -0000
@@ -33,6 +33,20 @@
 [yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])])
 
 
+
+## ----------- ##
+## Locations.  ##
+## ----------- ##
+
+# b4_location_if(IF-TRUE, IF-FALSE)
+# ---------------------------------
+# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
+m4_define([b4_location_if],
+[m4_if(b4_locations_flag, [1],
+       [$1],
+       [$2])])
+
+
 # b4_lhs_location()
 # -----------------
 # Expansion of @$.
@@ -48,6 +62,11 @@
 [yylsp@<:@m4_eval([$2 - $1])@:>@])
 
 
+
+## ------------------- ##
+## Output file names.  ##
+## ------------------- ##
+
 m4_define_default([b4_input_suffix], [.y])
 
 m4_define_default([b4_output_parser_suffix],
@@ -171,10 +190,7 @@
 #define yychar  b4_prefix[]char
 #define yydebug b4_prefix[]debug
 #define yynerrs b4_prefix[]nerrs
-#if YYLSP_NEEDED
-# define yylloc b4_prefix[]lloc
-#endif
-])
+b4_location_if([#define yylloc b4_prefix[]lloc])])
 
 /* Copy the first part of user declarations.  */
 b4_pre_prologue
@@ -264,9 +280,8 @@
 {
   short yyss;
   YYSTYPE yyvs;
-# if YYLSP_NEEDED
-  YYLTYPE yyls;
-# endif
+  b4_location_if([  YYLTYPE yyls;
+])dnl
 };
 
 /* The size of the maximum gap between one aligned stack and the next.  */
@@ -274,15 +289,13 @@
 
 /* The size of an array large to enough to hold all stacks, each with
    N elements.  */
-# if YYLSP_NEEDED
-#  define YYSTACK_BYTES(N) \
+b4_location_if(
+[# define YYSTACK_BYTES(N) \
      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))     \
-      + 2 * YYSTACK_GAP_MAX)
-# else
-#  define YYSTACK_BYTES(N) \
+      + 2 * YYSTACK_GAP_MAX)],
+[# define YYSTACK_BYTES(N) \
      ((N) * (sizeof (short) + sizeof (YYSTYPE))                                
\
-      + YYSTACK_GAP_MAX)
-# endif
+      + YYSTACK_GAP_MAX)])
 
 /* Copy COUNT objects from FROM to TO.  The source and destination do
    not overlap.  */
@@ -510,21 +523,13 @@
 /* YYLEX -- calling `yylex' with the right arguments.  */
 
 #if YYPURE
-# if YYLSP_NEEDED
-#  ifdef YYLEX_PARAM
-#   define YYLEX               yylex (&yylval, &yylloc, YYLEX_PARAM)
-#  else
-#   define YYLEX               yylex (&yylval, &yylloc)
-#  endif
-# else /* !YYLSP_NEEDED */
-#  ifdef YYLEX_PARAM
-#   define YYLEX               yylex (&yylval, YYLEX_PARAM)
-#  else
-#   define YYLEX               yylex (&yylval)
-#  endif
-# endif /* !YYLSP_NEEDED */
+# ifdef YYLEX_PARAM
+#  define YYLEX                yylex (&yylval, b4_location_if([&yylloc, 
])YYLEX_PARAM)
+# else
+#  define YYLEX                yylex (&yylval, b4_location_if([&yylloc, ]))
+# endif
 #else /* !YYPURE */
-# define YYLEX                 yylex ()
+# define YYLEX         yylex ()
 #endif /* !YYPURE */
 
 /* Enable debugging if requested.  */
@@ -656,7 +661,7 @@
 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
    variables are global, or local to YYPARSE.  */
 
-#define YY_DECL_NON_LSP_VARIABLES                      \
+#define YY_DECL_VARIABLES                              \
 /* The lookahead symbol.  */                           \
 int yychar;                                            \
                                                        \
@@ -664,18 +669,10 @@
 YYSTYPE yylval;                                                \
                                                        \
 /* Number of parse errors so far.  */                  \
-int yynerrs;
+int yynerrs;b4_location_if([                           \
+/* Location data for the lookahead symbol.  */         \
+YYLTYPE yylloc;])
 
-#if YYLSP_NEEDED
-# define YY_DECL_VARIABLES                     \
-YY_DECL_NON_LSP_VARIABLES                      \
-                                               \
-/* Location data for the lookahead symbol.  */ \
-YYLTYPE yylloc;
-#else
-# define YY_DECL_VARIABLES                     \
-YY_DECL_NON_LSP_VARIABLES
-#endif
 
 /* If nonreentrant, generate the variables here.  */
 
@@ -718,27 +715,20 @@
   YYSTYPE *yyvs = yyvsa;
   register YYSTYPE *yyvsp;
 
-#if YYLSP_NEEDED
-  /* The location stack.  */
+]b4_location_if(
+[[  /* The location stack.  */
   YYLTYPE yylsa[YYINITDEPTH];
   YYLTYPE *yyls = yylsa;
-  YYLTYPE *yylsp;
-#endif
+  YYLTYPE *yylsp;]])[
 
-#if YYLSP_NEEDED
-# define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
-#else
-# define YYPOPSTACK   (yyvsp--, yyssp--)
-#endif
+#define YYPOPSTACK   (yyvsp--, yyssp--]b4_location_if([, yylsp--])[)
 
   YYSIZE_T yystacksize = YYINITDEPTH;
 
   /* The variables used to return semantic value and location from the
      action routines.  */
   YYSTYPE yyval;
-#if YYLSP_NEEDED
-  YYLTYPE yyloc;
-#endif
+]b4_location_if([  YYLTYPE yyloc;])[
 
   /* When reducing, the number of symbols on the RHS of the reduced
      rule.  */
@@ -758,9 +748,7 @@
 
   yyssp = yyss;
   yyvsp = yyvs;
-#if YYLSP_NEEDED
-  yylsp = yyls;
-#endif
+]b4_location_if([  yylsp = yyls;])[
   goto yysetstate;
 
 /*------------------------------------------------------------.
@@ -787,25 +775,18 @@
           memory.  */
        YYSTYPE *yyvs1 = yyvs;
        short *yyss1 = yyss;
+]b4_location_if([      YYLTYPE *yyls1 = yyls;])[
 
        /* Each stack pointer address is followed by the size of the
-          data in use in that stack, in bytes.  */
-# if YYLSP_NEEDED
-       YYLTYPE *yyls1 = yyls;
-       /* This used to be a conditional around just the two extra args,
-          but that might be undefined if yyoverflow is a macro.  */
-       yyoverflow ("parser stack overflow",
-                   &yyss1, yysize * sizeof (*yyssp),
-                   &yyvs1, yysize * sizeof (*yyvsp),
-                   &yyls1, yysize * sizeof (*yylsp),
-                   &yystacksize);
-       yyls = yyls1;
-# else
+          data in use in that stack, in bytes.  This used to be a
+          conditional around just the two extra args, but that might
+          be undefined if yyoverflow is a macro.  */
        yyoverflow ("parser stack overflow",
                    &yyss1, yysize * sizeof (*yyssp),
                    &yyvs1, yysize * sizeof (*yyvsp),
+]b4_location_if([                  &yyls1, yysize * sizeof (*yylsp),])[
                    &yystacksize);
-# endif
+]b4_location_if([      yyls = yyls1;])[
        yyss = yyss1;
        yyvs = yyvs1;
       }
@@ -828,9 +809,7 @@
          goto yyoverflowlab;
        YYSTACK_RELOCATE (yyss);
        YYSTACK_RELOCATE (yyvs);
-#  if YYLSP_NEEDED
-       YYSTACK_RELOCATE (yyls);
-#  endif
+]b4_location_if([      YYSTACK_RELOCATE (yyls);])[
 #  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
@@ -840,9 +819,7 @@
 
       yyssp = yyss + yysize - 1;
       yyvsp = yyvs + yysize - 1;
-#if YYLSP_NEEDED
-      yylsp = yyls + yysize - 1;
-#endif
+]b4_location_if([      yylsp = yyls + yysize - 1;])[
 
       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
                  (unsigned long int) yystacksize));
@@ -946,9 +923,7 @@
     yychar = YYEMPTY;
 
   *++yyvsp = yylval;
-#if YYLSP_NEEDED
-  *++yylsp = yylloc;
-#endif
+]b4_location_if([  *++yylsp = yylloc;])[
 
   /* Count tokens shifted since error; after three, turn off error
      status.  */
@@ -986,10 +961,9 @@
      GCC warning that YYVAL may be used uninitialized.  */
   yyval = yyvsp[1-yylen];
 
-#if YYLSP_NEEDED
-  /* Default location. */
-  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
-#endif
+]b4_location_if(
+[  /* Default location. */
+  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[
 
 #if YYDEBUG
   /* We have to keep this `#if YYDEBUG', since we use variables which
@@ -1017,9 +991,7 @@
 
 [  yyvsp -= yylen;
   yyssp -= yylen;
-#if YYLSP_NEEDED
-  yylsp -= yylen;
-#endif
+]b4_location_if([  yylsp -= yylen;])[
 
 #if YYDEBUG
   if (yydebug)
@@ -1033,9 +1005,7 @@
 #endif
 
   *++yyvsp = yyval;
-#if YYLSP_NEEDED
-  *++yylsp = yyloc;
-#endif
+]b4_location_if([  *++yylsp = yyloc;])[
 
   /* Now `shift' the result of the reduction.  Determine what state
      that goes to, based on the state we popped back to and the rule
@@ -1207,9 +1177,7 @@
       yydestructor (yystos[yystate], *yyvsp);
       yyvsp--;
       yystate = *--yyssp;
-#if YYLSP_NEEDED
-      yylsp--;
-#endif
+]b4_location_if([      yylsp--;])[
 
 #if YYDEBUG
       if (yydebug)
@@ -1229,9 +1197,7 @@
   YYDPRINTF ((stderr, "Shifting error token, "));
 
   *++yyvsp = yylval;
-#if YYLSP_NEEDED
-  *++yylsp = yylloc;
-#endif
+]b4_location_if([  *++yylsp = yylloc;])[
 
   yystate = yyn;
   goto yynewstate;
@@ -1321,7 +1287,7 @@
 m4_if(b4_pure, [0],
 [extern YYSTYPE b4_prefix[]lval;])
 
-m4_if(b4_locations_flag, [0], [],
+b4_location_if(
 [#ifndef YYLTYPE
 typedef struct yyltype
 {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]