]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
(yyfillin): Renamed from the old yyfill. Mark
[bison.git] / data / glr.c
index c2b678bf157f2355f2f0c74524909a22830bf6ea..2c3b550c3799cdd3b4e36549482d1d83d1a7dc29 100644 (file)
@@ -510,7 +510,8 @@ int yydebug;
 
 #if (! defined (YYSTACKEXPANDABLE) \
      && (! defined (__cplusplus) \
-        || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
+        || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
+            && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
 #define YYSTACKEXPANDABLE 1
 #else
 #define YYSTACKEXPANDABLE 0
@@ -613,14 +614,15 @@ yytokenName (yySymbol yytoken)
 
 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
  *  at YYVSP[YYLOW0].yystate.yypred.  Leaves YYVSP[YYLOW1].yystate.yypred
- *  containing the pointer to the next state in the chain. Assumes 
- *  YYLOW1 < YYLOW0.  For convenience, returns YYLOW1. */
-static int
-yyfill (yyGLRStackItem* yyvsp, int yylow0, int yylow1) 
+ *  containing the pointer to the next state in the chain. Assumes
+ *  YYLOW1 < YYLOW0.  */
+static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED;
+static void
+yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
 {
   yyGLRState* s;
   int i;
-  s = yyvsp[yylow0].yystate.yypred; 
+  s = yyvsp[yylow0].yystate.yypred;
   for (i = yylow0-1; i >= yylow1; i -= 1)
     {
       if (! s->yyresolved)
@@ -630,6 +632,21 @@ yyfill (yyGLRStackItem* yyvsp, int yylow0, int yylow1)
       yyvsp[i].yystate.yyloc = s->yyloc;
       s = yyvsp[i].yystate.yypred = s->yypred;
     }
+}
+
+/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1.  Otherwise, fill in
+   YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
+   For convenience, always return YYLOW1.  */
+static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
+     ATTRIBUTE_UNUSED;
+static inline int
+yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
+{
+  if (!yynormal && yylow1 < *yylow)
+    {
+      yyfillin (yyvsp, *yylow, yylow1);
+      *yylow = yylow1;
+    }
   return yylow1;
 }
 
@@ -643,7 +660,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
              YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack
               ]b4_user_formals[)
 {
-  int yynormal = (yystack->yysplitPoint == NULL);
+  yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL);
   int yylow;
 
   if (yyrhslen == 0)
@@ -669,8 +686,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
 # undef yyclearin
 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
 # undef YYFILL
-# define YYFILL(N)                                                          \
-  ((yynormal || yylow <= (N)) ? (N) : (yylow = yyfill (yyvsp, yylow, N)))
+# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
 # undef YYBACKUP
 # define YYBACKUP(Token, Value)                                                     \
   do {                                                                      \
@@ -926,7 +942,7 @@ yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[)
 
 #else
 
-  yyFail (yystack][]b4_lpure_args[, "parser stack overflow");
+  yyFail (yystack][]b4_pure_args[, "parser stack overflow");
 #endif
 }
 
@@ -1022,7 +1038,7 @@ yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,
 }
 
 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
- *  state YYLRSTATE, at input position YYPOSN, with the (unresolved) 
+ *  state YYLRSTATE, at input position YYPOSN, with the (unresolved)
  *  semantic value of YYRHS under the action for YYRULE. */
 static inline void
 yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
@@ -1123,9 +1139,9 @@ static inline void
 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
 {
   int yyi;
-  unsigned int yylineno = yyrline[yyrule];
+  unsigned int yylno = yyrline[yyrule];
   YYFPRINTF (stderr, "Reducing stack %d by rule %d (line %u), ",
-            yyk, yyrule - 1, yylineno);
+            yyk, yyrule - 1, yylno);
   /* Print the symbols being reduced, and their result.  */
   for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
     YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
@@ -1597,29 +1613,28 @@ yyreportSyntaxError (yyGLRStack* yystack,
 #if YYERROR_VERBOSE
       yySymbol* const yytokenp = yystack->yytokenp;
       int yyn;
-      const char* yyprefix;
       yyn = yypact[yystack->yytops.yystates[0]->yylrState];
       if (YYPACT_NINF < yyn && yyn < YYLAST)
        {
          size_t yysize = 0;
+         const char* yyprefix;
          char* yymsg;
          int yyx;
 
          /* Start YYX at -YYN if negative to avoid negative indexes in
             YYCHECK.  */
-         int yyxbase = yyn < 0 ? -yyn : 0;
+         int yyxbegin = yyn < 0 ? -yyn : 0;
 
          /* Stay within bounds of both yycheck and yytname.  */
          int yychecklim = YYLAST - yyn;
-         int yynsyms = sizeof (yytname) / sizeof (yytname[0]);
-         int yyxlim = yychecklim < yynsyms ? yychecklim : yynsyms;
+         int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
          int yycount = 0;
 
          yyprefix = ", expecting ";
-         for (yyx = yyxbase; yyx < yyxlim && yycount < 5; yyx += 1)
+         for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
              {
-               yysize += strlen (yytokenName (yyx)) + strlen (yyprefix);
+               yysize += strlen (yyprefix) + strlen (yytokenName (yyx));
                yycount += 1;
                if (yycount == 5)
                  {
@@ -1640,7 +1655,7 @@ yyreportSyntaxError (yyGLRStack* yystack,
              if (yycount < 5)
                {
                  yyprefix = ", expecting ";
-                 for (yyx = yyxbase; yyx < yyxlim; yyx += 1)
+                 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
                    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
                      {
                        sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));