]> git.saurik.com Git - bison.git/blobdiff - src/LR0.c
* src/output.h: And put its extern declaration here.
[bison.git] / src / LR0.c
index cecc0eae33fa7d5c6913dfbbbb098ba481d20d52..ef5624d434a63f8296d5c2ebf813d637cdf2e734 100644 (file)
--- a/src/LR0.c
+++ b/src/LR0.c
@@ -50,7 +50,7 @@ static short *redset = NULL;
 static short *shiftset = NULL;
 
 static short **kernel_base = NULL;
-static size_t *kernel_size = NULL;
+static int *kernel_size = NULL;
 static short *kernel_items = NULL;
 
 /* hash table for states, to recognize equivalent ones.  */
@@ -94,7 +94,7 @@ allocate_itemsets (void)
     }
 
   shift_symbol = symbol_count;
-  kernel_size = XCALLOC (size_t, nsyms);
+  kernel_size = XCALLOC (int, nsyms);
 }
 
 
@@ -150,7 +150,7 @@ new_itemsets (void)
 
   shiftcount = 0;
 
-  for (i = 0; i < itemsetend - itemset; ++i)
+  for (i = 0; i < itemsetsize; ++i)
     {
       int symbol = ritem[itemset[i]];
       if (symbol > 0)
@@ -213,7 +213,6 @@ static int
 get_state (int symbol)
 {
   int key;
-  short *isp2;
   int i;
   core *sp;
 
@@ -236,7 +235,6 @@ get_state (int symbol)
        {
          if (sp->nitems == kernel_size[symbol])
            {
-             int i;
              found = 1;
              for (i = 0; i < kernel_size[symbol]; ++i)
                if (kernel_base[symbol][i] != sp->items[i])
@@ -313,13 +311,29 @@ new_states (void)
 }
 
 
+/*---------------------------------.
+| Create a new array of N shitfs.  |
+`---------------------------------*/
+
+static shifts *
+shifts_new (int n)
+{
+  shifts *res = SHIFTS_ALLOC (n);
+  res->nshifts = n;
+  return res;
+}
+
+
+/*------------------------------------------------------------.
+| Save the NSHIFTS of SHIFTSET into the current linked list.  |
+`------------------------------------------------------------*/
+
 static void
 save_shifts (void)
 {
-  shifts *p = SHIFTS_ALLOC (nshifts);
+  shifts *p = shifts_new (nshifts);
 
   p->number = this_state->number;
-  p->nshifts = nshifts;
 
   shortcpy (p->shifts, shiftset, nshifts);
 
@@ -350,9 +364,8 @@ insert_start_shift (void)
   last_state = statep;
 
   /* Make a shift from this state to (what will be) the final state.  */
-  sp = SHIFTS_ALLOC (1);
+  sp = shifts_new (1);
   sp->number = nstates++;
-  sp->nshifts = 1;
   sp->shifts[0] = nstates;
 
   last_shift->next = sp;
@@ -407,9 +420,8 @@ augment_automaton (void)
 
              if (sp && sp->number == k)
                {
-                 sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
+                 sp2 = shifts_new (sp->nshifts + 1);
                  sp2->number = k;
-                 sp2->nshifts = sp->nshifts + 1;
                  sp2->shifts[0] = nstates;
                  for (i = sp->nshifts; i > 0; i--)
                    sp2->shifts[i] = sp->shifts[i - 1];
@@ -424,9 +436,8 @@ augment_automaton (void)
                }
              else
                {
-                 sp2 = SHIFTS_ALLOC (1);
+                 sp2 = shifts_new (1);
                  sp2->number = k;
-                 sp2->nshifts = 1;
                  sp2->shifts[0] = nstates;
 
                  /* Patch sp2 into the chain of shifts between sp1 and sp.  */
@@ -443,8 +454,7 @@ augment_automaton (void)
                 going to the next-to-final state (yet to be made).  */
              sp = first_shift;
 
-             sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
-             sp2->nshifts = sp->nshifts + 1;
+             sp2 = shifts_new (sp->nshifts + 1);
 
              /* Stick this shift into the vector at the proper place.  */
              statep = first_state->next;
@@ -476,8 +486,7 @@ augment_automaton (void)
        {
          /* The initial state didn't even have any shifts.
             Give it one shift, to the next-to-final state.  */
-         sp = SHIFTS_ALLOC (1);
-         sp->nshifts = 1;
+         sp = shifts_new (1);
          sp->shifts[0] = nstates;
 
          /* Patch sp into the chain of shifts at the beginning.  */
@@ -494,8 +503,7 @@ augment_automaton (void)
       /* There are no shifts for any state.
          Make one shift, from the initial state to the next-to-final state.  */
 
-      sp = SHIFTS_ALLOC (1);
-      sp->nshifts = 1;
+      sp = shifts_new (1);
       sp->shifts[0] = nstates;
 
       /* Initialize the chain of shifts with sp.  */
@@ -516,9 +524,8 @@ augment_automaton (void)
   last_state = statep;
 
   /* Make the shift from the final state to the termination state.  */
-  sp = SHIFTS_ALLOC (1);
+  sp = shifts_new (1);
   sp->number = nstates++;
-  sp->nshifts = 1;
   sp->shifts[0] = nstates;
   last_shift->next = sp;
   last_shift = sp;
@@ -544,19 +551,15 @@ augment_automaton (void)
 static void
 save_reductions (void)
 {
-  short *isp;
-  int item;
   int count;
-  reductions *p;
-
-  short *rend;
+  int i;
 
   /* Find and count the active items that represent ends of rules. */
 
   count = 0;
-  for (isp = itemset; isp < itemsetend; isp++)
+  for (i = 0; i < itemsetsize; ++i)
     {
-      item = ritem[*isp];
+      int item = ritem[itemset[i]];
       if (item < 0)
        redset[count++] = -item;
     }
@@ -565,7 +568,7 @@ save_reductions (void)
 
   if (count)
     {
-      p = REDUCTIONS_ALLOC (count);
+      reductions *p = REDUCTIONS_ALLOC (count);
 
       p->number = this_state->number;
       p->nreds = count;