bison-patches
[Top][All Lists]
Advanced

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

08-fyi-build-relation.patch


From: Akim Demaille
Subject: 08-fyi-build-relation.patch
Date: Wed, 05 Dec 2001 08:24:42 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/lalr.c (transpose): Free the memory allocated to the
        argument, as it is replaced by the results by the unique caller.
        (build_relations): Merely invoke transpose: it handles the memory
        deallocation.
        Improve variable locality.
        Avoid variables used as mere abbreviations.
        (compute_lookaheads): Use arrays instead of pointers.

Index: src/lalr.c
--- src/lalr.c Sat, 01 Dec 2001 14:32:56 +0100 akim
+++ src/lalr.c Sat, 01 Dec 2001 14:43:15 +0100 akim
@@ -435,6 +435,11 @@
 }


+/*-------------------------------------------------------------------.
+| Return the transpose of R_ARG, of size N.  Destroy R_ARG, as it is |
+| replaced with the result.                                          |
+`-------------------------------------------------------------------*/
+
 static short **
 transpose (short **R_arg, int n)
 {
@@ -479,6 +484,11 @@

   XFREE (temp_R);

+  /* Free the input: it is replaced with the result. */
+  for (i = 0; i < n; i++)
+    XFREE (R_arg[i]);
+  XFREE (R_arg);
+
   return new_R;
 }

@@ -486,44 +496,35 @@
 static void
 build_relations (void)
 {
+  short *edge = XCALLOC (short, ngotos + 1);
+  short *states = XCALLOC (short, maxrhs () + 1);
   int i;
-  int j;
-  short *rulep;
-  short *rp;
-  int nedges;
-  int done;
-  int state1;
-  int stateno;
-  int symbol1;
-  short *edge;
-  short *states;
-  short **new_includes;

   includes = XCALLOC (short *, ngotos);
-  edge = XCALLOC (short, ngotos + 1);
-  states = XCALLOC (short, maxrhs () + 1);

   for (i = 0; i < ngotos; i++)
     {
-      nedges = 0;
-      state1 = from_state[i];
-      symbol1 = state_table[to_state[i]].accessing_symbol;
+      int nedges = 0;
+      int state1 = from_state[i];
+      int symbol1 = state_table[to_state[i]].accessing_symbol;
+      short *rulep;

       for (rulep = derives[symbol1]; *rulep > 0; rulep++)
        {
+         int done;
          int length = 1;
+         int stateno = state1;
+         short *rp;
          states[0] = state1;
-         stateno = state1;

          for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
            {
-             int symbol2 = *rp;
              shifts *sp = state_table[stateno].shift_table;
-
+             int j;
              for (j = 0; j < sp->nshifts; j++)
                {
                  stateno = sp->shifts[j];
-                 if (state_table[stateno].accessing_symbol == symbol2)
+                 if (state_table[stateno].accessing_symbol == *rp)
                    break;
                }

@@ -552,6 +553,7 @@

       if (nedges)
        {
+         int j;
          includes[i] = XCALLOC (short, nedges + 1);
          for (j = 0; j < nedges; j++)
            includes[i][j] = edge[j];
@@ -559,16 +561,10 @@
        }
     }

-  new_includes = transpose (includes, ngotos);
-
-  for (i = 0; i < ngotos; i++)
-    XFREE (includes[i]);
-  XFREE (includes);
-
-  includes = new_includes;
-
   XFREE (edge);
   XFREE (states);
+
+  includes = transpose (includes, ngotos);
 }


@@ -596,10 +592,10 @@
   for (i = 0; i < state_table[nstates].lookaheads; i++)
     for (sp = lookback[i]; sp; sp = sp->next)
       {
-       unsigned *fp1 = LA (i);
-       unsigned *fp2 = F (sp->value);
-       while (fp1 < LA (i + 1))
-         *fp1++ |= *fp2++;
+       int size = LA (i + 1) - LA (i);
+       int j;
+       for (j = 0; j < size; ++j)
+         LA (i)[j] |= F (sp->value)[j];
       }

   /* Free LOOKBACK. */



reply via email to

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