]> git.saurik.com Git - bison.git/commitdiff
tables: scope reduction
authorAkim Demaille <akim@lrde.epita.fr>
Wed, 26 Dec 2012 17:16:55 +0000 (18:16 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Wed, 26 Dec 2012 17:17:21 +0000 (18:17 +0100)
* src/tables.c (matching_state): here.

src/tables.c

index f99f07b234f0fd487245403fc337f9fe9e8b5f87..c6233013374d78bfaa4f0780b1802e47ab665d6d 100644 (file)
@@ -620,47 +620,43 @@ static state_number
 matching_state (vector_number vector)
 {
   vector_number i = order[vector];
-  size_t t;
-  int w;
-  int prev;
-
   /* If VECTOR is a nterm, return -1.  */
-  if (nstates <= i)
-    return -1;
-
-  t = tally[i];
-  w = width[i];
-
-  /* If VECTOR has GLR conflicts, return -1 */
-  if (conflict_tos[i] != NULL)
+  if (i < nstates)
     {
-      int j;
-      for (j = 0; j < t; j += 1)
-        if (conflict_tos[i][j] != 0)
-          return -1;
-    }
+      size_t t = tally[i];
+      int w = width[i];
+      int prev;
 
-  for (prev = vector - 1; prev >= 0; prev--)
-    {
-      vector_number j = order[prev];
-      int k;
-      int match = 1;
-
-      /* Given how ORDER was computed, if the WIDTH or TALLY is
-         different, there cannot be a matching state.  */
-      if (width[j] != w || tally[j] != t)
-        return -1;
-
-      for (k = 0; match && k < t; k++)
-        if (tos[j][k] != tos[i][k]
-            || froms[j][k] != froms[i][k]
-            || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
-          match = 0;
-
-      if (match)
-        return j;
-    }
+      /* If VECTOR has GLR conflicts, return -1 */
+      if (conflict_tos[i] != NULL)
+        {
+          int j;
+          for (j = 0; j < t; j += 1)
+            if (conflict_tos[i][j] != 0)
+              return -1;
+        }
 
+      for (prev = vector - 1; 0 <= prev; prev--)
+        {
+          vector_number j = order[prev];
+          /* Given how ORDER was computed, if the WIDTH or TALLY is
+             different, there cannot be a matching state.  */
+          if (width[j] != w || tally[j] != t)
+            return -1;
+          else
+            {
+              bool match = true;
+              int k;
+              for (k = 0; match && k < t; k++)
+                if (tos[j][k] != tos[i][k]
+                    || froms[j][k] != froms[i][k]
+                    || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
+                  match = false;
+              if (match)
+                return j;
+            }
+        }
+    }
   return -1;
 }