]> git.saurik.com Git - bison.git/blobdiff - src/lalr.c
* src/lalr.c (F): Now a bitset*.
[bison.git] / src / lalr.c
index c16c6f52dafaea945a222c3f6103f32c6c312cf2..87e91cd5f553e9857ab345cba7c43bb07eae3123 100644 (file)
@@ -24,6 +24,7 @@
    tokens they accept.  */
 
 #include "system.h"
+#include "bitset.h"
 #include "reader.h"
 #include "types.h"
 #include "LR0.h"
 state_t **states = NULL;
 
 int tokensetsize;
-short *LAruleno;
-unsigned *LA;
+short *LAruleno = NULL;
+bitset *LA = NULL;
 size_t nLA;
 
 static int ngotos;
-short *goto_map;
-short *from_state;
-short *to_state;
+short *goto_map = NULL;
+short *from_state = NULL;
+short *to_state = NULL;
 
 /* And for the famous F variable, which name is so descriptive that a
    comment is hardly needed.  <grin>.  */
-static unsigned *F = NULL;
-#define F(Rule)  (F + (Rule) * tokensetsize)
+static bitset *F = NULL;
 
 static short **includes;
 static shorts **lookback;
@@ -74,9 +74,7 @@ static void
 traverse (int i)
 {
   int j;
-  size_t k;
   int height;
-  size_t size = F (i + 1) - F(i);
 
   VERTICES[++top] = i;
   INDEX[i] = height = top;
@@ -90,8 +88,7 @@ traverse (int i)
        if (INDEX[i] > INDEX[R[i][j]])
          INDEX[i] = INDEX[R[i][j]];
 
-       for (k = 0; k < size; ++k)
-         F (i)[k] |= F (R[i][j])[k];
+       bitset_or (F[i], F[i], F[R[i][j]]);
       }
 
   if (INDEX[i] == height)
@@ -103,8 +100,7 @@ traverse (int i)
        if (i == j)
          break;
 
-       for (k = 0; k < size; ++k)
-         F (j)[k] = F (i)[k];
+       bitset_copy (F[j], F[i]);
       }
 }
 
@@ -136,7 +132,7 @@ digraph (short **relation)
 static void
 initialize_LA (void)
 {
-  int i;
+  size_t i;
   int j;
   short *np;
 
@@ -144,7 +140,12 @@ initialize_LA (void)
   if (!nLA)
     nLA = 1;
 
-  LA = XCALLOC (unsigned, nLA * tokensetsize);
+  LA = XCALLOC (bitset, nLA);
+  for (i = 0; i < nLA; ++i)
+    {
+      LA[i] = bitset_create (ntokens, BITSET_FIXED);
+      bitset_zero (LA[i]);
+    }
   LAruleno = XCALLOC (short, nLA);
   lookback = XCALLOC (shorts *, nLA);
 
@@ -159,7 +160,8 @@ initialize_LA (void)
 static void
 set_goto_map (void)
 {
-  int state, i;
+  size_t state;
+  int i;
   short *temp_map;
 
   goto_map = XCALLOC (short, nvars + 1) - ntokens;
@@ -255,7 +257,12 @@ initialize_F (void)
 
   int i;
 
-  F = XCALLOC (unsigned, ngotos * tokensetsize);
+  F = XCALLOC (bitset, ngotos);
+  for (i = 0; i < ngotos; ++i)
+    {
+      F[i] = bitset_create (ntokens, BITSET_FIXED);
+      bitset_zero (F[i]);
+    }
 
   for (i = 0; i < ngotos; i++)
     {
@@ -264,7 +271,7 @@ initialize_F (void)
 
       int j;
       for (j = 0; j < sp->nshifts && SHIFT_IS_SHIFT (sp, j); j++)
-       SETBIT (F (i), SHIFT_SYMBOL (sp, j));
+       bitset_set (F[i], SHIFT_SYMBOL (sp, j));
 
       for (; j < sp->nshifts; j++)
        {
@@ -493,18 +500,15 @@ compute_lookaheads (void)
 
   for (i = 0; i < nLA; i++)
     for (sp = lookback[i]; sp; sp = sp->next)
-      {
-       int size = LA (i + 1) - LA (i);
-       int j;
-       for (j = 0; j < size; ++j)
-         LA (i)[j] |= F (sp->value)[j];
-      }
+      bitset_or (LA[i], LA[i], F[sp->value]);
 
   /* Free LOOKBACK. */
   for (i = 0; i < nLA; i++)
     LIST_FREE (shorts, lookback[i]);
 
   XFREE (lookback);
+  for (i = 0; i < (unsigned) ngotos; ++i)
+    bitset_free (F[i]);
   XFREE (F);
 }
 
@@ -516,7 +520,7 @@ compute_lookaheads (void)
 static void
 initialize_lookaheads (void)
 {
-  int i;
+  size_t i;
   nLA = 0;
   for (i = 0; i < nstates; i++)
     {
@@ -556,7 +560,8 @@ initialize_lookaheads (void)
 static void
 lookaheads_print (FILE *out)
 {
-  int i, j, k;
+  size_t i;
+  int j, k;
   fprintf (out, "Lookaheads: BEGIN\n");
   for (i = 0; i < nstates; ++i)
     {
@@ -565,7 +570,7 @@ lookaheads_print (FILE *out)
 
       for (j = 0; j < states[i]->nlookaheads; ++j)
        for (k = 0; k < ntokens; ++k)
-         if (BITISSET (LA (states[i]->lookaheadsp + j), j))
+         if (bitset_test (LA[states[i]->lookaheadsp + j], j))
            fprintf (out, "   on %d (%s) -> rule %d\n",
                     k, symbols[k]->tag,
                     -LAruleno[states[i]->lookaheadsp + j] - 1);