bison-patches
[Top][All Lists]
Advanced

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

11-fyi-more-state-t.patch


From: Akim Demaille
Subject: 11-fyi-more-state-t.patch
Date: Mon, 19 Nov 2001 10:02:32 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/lalr.h (reduction_table, shift_table): Removed arrays, which
        contents is now members of...
        (state_t): this structure.
        * src/output.c, src/lalr.c, src/print_graph.c, src/conflicts.c:
        Adjust.
        
        
Index: src/print_graph.c
--- src/print_graph.c Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/print_graph.c Thu, 15 Nov 2001 22:56:20 +0100 akim
@@ -104,8 +104,8 @@
   static char buff[10];
   edge_t edge;
 
-  shiftp = shift_table[state];
-  redp = reduction_table[state];
+  shiftp = state_table[state].shift_table;
+  redp = state_table[state].reduction_table;
   errp = err_table[state];
 
   if (!shiftp && !redp)
Index: src/conflicts.c
--- src/conflicts.c Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/conflicts.c Thu, 15 Nov 2001 22:56:24 +0100 akim
@@ -60,7 +60,7 @@
   shifts *shiftp;
   int k, i;
 
-  shiftp = shift_table[state];
+  shiftp = state_table[state].shift_table;
 
   if (shiftp)
     {
@@ -197,7 +197,7 @@
   for (i = 0; i < tokensetsize; i++)
     lookaheadset[i] = 0;
 
-  shiftp = shift_table[state];
+  shiftp = state_table[state].shift_table;
   if (shiftp)
     {
       k = shiftp->nshifts;
@@ -288,7 +288,7 @@
 
   int src_count = 0;
 
-  shiftp = shift_table[state];
+  shiftp = state_table[state].shift_table;
   if (!shiftp)
     return 0;
 
@@ -533,7 +533,7 @@
   for (i = 0; i < tokensetsize; i++)
     shiftset[i] = 0;
 
-  shiftp = shift_table[state];
+  shiftp = state_table[state].shift_table;
   if (shiftp)
     {
       k = shiftp->nshifts;
Index: src/lalr.c
--- src/lalr.c Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/lalr.c Thu, 15 Nov 2001 22:57:04 +0100 akim
@@ -43,8 +43,6 @@
 unsigned *LA;
 
 char *consistent;
-shifts **shift_table;
-reductions **reduction_table;
 short *goto_map;
 short *from_state;
 short *to_state;
@@ -148,39 +146,28 @@
 static void
 set_state_table (void)
 {
-  core *sp;
-
   state_table = XCALLOC (state_t, nstates);
 
-  for (sp = first_state; sp; sp = sp->next)
-    {
-      state_table[sp->number].state = sp;
-      state_table[sp->number].accessing_symbol = sp->accessing_symbol;
-    }
-}
-
-
-static void
-set_shift_table (void)
-{
-  shifts *sp;
-
-  shift_table = XCALLOC (shifts *, nstates);
-
-  for (sp = first_shift; sp; sp = sp->next)
-    shift_table[sp->number] = sp;
-}
-
-
-static void
-set_reduction_table (void)
-{
-  reductions *rp;
-
-  reduction_table = XCALLOC (reductions *, nstates);
-
-  for (rp = first_reduction; rp; rp = rp->next)
-    reduction_table[rp->number] = rp;
+  {
+    core *sp;
+    for (sp = first_state; sp; sp = sp->next)
+      {
+       state_table[sp->number].state = sp;
+       state_table[sp->number].accessing_symbol = sp->accessing_symbol;
+      }
+  }
+
+  {
+    shifts *sp;
+    for (sp = first_shift; sp; sp = sp->next)
+      state_table[sp->number].shift_table = sp;
+  }
+
+  {
+    reductions *rp;
+    for (rp = first_reduction; rp; rp = rp->next)
+      state_table[rp->number].reduction_table = rp;
+  }
 }
 
 
@@ -231,8 +218,8 @@
 
       lookaheads[i] = count;
 
-      rp = reduction_table[i];
-      sp = shift_table[i];
+      rp = state_table[i].reduction_table;
+      sp = state_table[i].shift_table;
       if (rp
          && (rp->nreds > 1
              || (sp && !ISVAR (state_table[sp->shifts[0]].accessing_symbol))))
@@ -270,7 +257,7 @@
     {
       if (!consistent[i])
        {
-         if ((rp = reduction_table[i]))
+         if ((rp = state_table[i].reduction_table))
            for (j = 0; j < rp->nreds; j++)
              *np++ = rp->rules[j];
        }
@@ -408,7 +395,7 @@
   for (i = 0; i < ngotos; i++)
     {
       stateno = to_state[i];
-      sp = shift_table[stateno];
+      sp = state_table[stateno].shift_table;
 
       if (sp)
        {
@@ -580,7 +567,7 @@
          for (rp = ritem + rrhs[*rulep]; *rp > 0; rp++)
            {
              symbol2 = *rp;
-             sp = shift_table[stateno];
+             sp = state_table[stateno].shift_table;
              k = sp->nshifts;
 
              for (j = 0; j < k; j++)
@@ -704,8 +691,6 @@
   tokensetsize = WORDSIZE (ntokens);
 
   set_state_table ();
-  set_shift_table ();
-  set_reduction_table ();
   set_maxrhs ();
   initialize_LA ();
   set_goto_map ();
Index: src/lalr.h
--- src/lalr.h Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/lalr.h Thu, 15 Nov 2001 22:54:17 +0100 akim
@@ -82,6 +82,9 @@
 
   /* Its accessing symbol. */
   short accessing_symbol;
+
+  shifts *shift_table;
+  reductions *reduction_table;
 } state_t;
 
 /* All the decorated states, indexed by the state number.  Warning:
@@ -91,8 +94,7 @@
 
 extern int tokensetsize;
 extern short *lookaheads;
-extern shifts **shift_table;
-extern reductions **reduction_table;
+
 
 
 
Index: src/output.c
--- src/output.c Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/output.c Thu, 15 Nov 2001 22:56:24 +0100 akim
@@ -530,7 +530,7 @@
 
   default_rule = 0;
   nreds = 0;
-  redp = reduction_table[state];
+  redp = state_table[state].reduction_table;
 
   if (redp)
     {
@@ -569,7 +569,7 @@
        }
     }
 
-  shiftp = shift_table[state];
+  shiftp = state_table[state].shift_table;
 
   /* Now see which tokens are allowed for shifts in this state.  For
      them, record the shift as the thing to do.  So shift is preferred
@@ -747,8 +747,6 @@
 {
   shifts *sp, *sptmp;  /* JF derefrenced freed ptr */
 
-  XFREE (shift_table);
-
   for (sp = first_shift; sp; sp = sptmp)
     {
       sptmp = sp->next;
@@ -761,8 +759,6 @@
 free_reductions (void)
 {
   reductions *rp, *rptmp;      /* JF fixed freed ptr */
-
-  XFREE (reduction_table);
 
   for (rp = first_reduction; rp; rp = rptmp)
     {
Index: src/print.c
--- src/print.c Thu, 15 Nov 2001 22:48:11 +0100 akim
+++ src/print.c Thu, 15 Nov 2001 22:56:10 +0100 akim
@@ -102,8 +102,8 @@
   reductions *redp;
   int rule;
 
-  shiftp = shift_table[state];
-  redp = reduction_table[state];
+  shiftp = state_table[state].shift_table;
+  redp = state_table[state].reduction_table;
   errp = err_table[state];
 
   if (!shiftp && !redp)



reply via email to

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