bison-patches
[Top][All Lists]
Advanced

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

15-fyi-all-errs.patch


From: Akim Demaille
Subject: 15-fyi-all-errs.patch
Date: Thu, 27 Dec 2001 19:01:59 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/state.h, src/state.c (errs_new, errs_dup): New.
        * src/LR0.c (set_state_table): Let all the states have an errs,
        even if reduced to 0.
        * src/print.c (print_errs, print_reductions): Adjust.
        * src/output.c (output_actions, action_row): Adjust.
        * src/conflicts.c (resolve_sr_conflict): Adjust.
        
        
Index: src/LR0.c
--- src/LR0.c Wed, 26 Dec 2001 18:13:52 +0100 akim
+++ src/LR0.c Thu, 27 Dec 2001 10:38:54 +0100 akim
@@ -541,22 +541,20 @@
 static void
 set_state_table (void)
 {
+  state_t *sp;
   state_table = XCALLOC (state_t *, nstates);
 
-  {
-    state_t *sp;
-    for (sp = first_state; sp; sp = sp->next)
-      state_table[sp->number] = sp;
-  }
+  for (sp = first_state; sp; sp = sp->next)
+    {
+      /* Pessimization, but simplification of the code: make sure all
+        the states have a shifts and errs, even if reduced to 0.  */
+      if (!sp->shifts)
+       sp->shifts = shifts_new (0);
+      if (!sp->errs)
+       sp->errs = errs_new (0);
 
-  /* Pessimization, but simplification of the code: make sure all the
-     states have a shifts, even if reduced to 0 shifts.  */
-  {
-    int i;
-    for (i = 0; i < nstates; i++)
-      if (!state_table[i]->shifts)
-       state_table[i]->shifts = shifts_new (0);
-  }
+      state_table[sp->number] = sp;
+    }
 }
 
 /*-------------------------------------------------------------------.
Index: src/conflicts.c
--- src/conflicts.c Wed, 26 Dec 2001 23:00:34 +0100 akim
+++ src/conflicts.c Thu, 27 Dec 2001 10:47:25 +0100 akim
@@ -93,8 +93,8 @@
   int i;
   /* find the rule to reduce by to get precedence of reduction  */
   int redprec = rule_table[LAruleno[lookahead]].prec;
-  errs *errp = ERRS_ALLOC (ntokens + 1);
-  short *errtokens = errp->errs;
+  errs *errp = errs_new (ntokens + 1);
+  errp->nerrs = 0;
 
   for (i = 0; i < ntokens; i++)
     if (BITISSET (LA (lookahead), i)
@@ -137,17 +137,14 @@
              flush_shift (state, i);
              flush_reduce (lookahead, i);
              /* Record an explicit error for this token.  */
-             *errtokens++ = i;
+             errp->errs[errp->nerrs++] = i;
              break;
            }
       }
 
-  errp->nerrs = errtokens - errp->errs;
   /* Some tokens have been explicitly made errors.  Allocate a
      permanent errs structure for this state, to record them.  */
-  i = (char *) errtokens - (char *) errp;
-  state->errs = ERRS_ALLOC (i + 1);
-  memcpy (state->errs, errp, i);
+  state->errs = errs_dup (errp);
   free (errp);
 }
 
Index: src/output.c
--- src/output.c Wed, 26 Dec 2001 20:33:04 +0100 akim
+++ src/output.c Thu, 27 Dec 2001 10:49:30 +0100 akim
@@ -375,12 +375,11 @@
 
   /* See which tokens are an explicit error in this state (due to
      %nonassoc).  For them, record MINSHORT as the action.  */
-  if (errp)
-    for (i = 0; i < errp->nerrs; i++)
-      {
-       int symbol = errp->errs[i];
-       actrow[symbol] = MINSHORT;
-      }
+  for (i = 0; i < errp->nerrs; i++)
+    {
+      int symbol = errp->errs[i];
+      actrow[symbol] = MINSHORT;
+    }
 
   /* Now find the most common reduction and make it the default action
      for this state.  */
@@ -903,9 +902,9 @@
 
   for (i = 0; i < nstates; ++i)
     {
-      XFREE (state_table[i]->shifts);
+      free (state_table[i]->shifts);
       XFREE (state_table[i]->reductions);
-      XFREE (state_table[i]->errs);
+      free (state_table[i]->errs);
       free (state_table[i]);
     }
   XFREE (state_table);
Index: src/print.c
--- src/print.c Wed, 26 Dec 2001 23:00:34 +0100 akim
+++ src/print.c Thu, 27 Dec 2001 10:52:03 +0100 akim
@@ -124,16 +124,13 @@
   errs *errp = state->errs;
   int i;
 
-  if (!errp)
-    return;
-
   for (i = 0; i < errp->nerrs; ++i)
     if (errp->errs[i])
       fprintf (out, _("    %-4s\terror (nonassociative)\n"),
               tags[errp->errs[i]]);
 
   if (i > 0)
-       fputc ('\n', out);
+    fputc ('\n', out);
 }
 
 
@@ -192,10 +189,9 @@
        SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));
       }
 
-  if (errp)
-    for (i = 0; i < errp->nerrs; i++)
-      if (errp->errs[i])
-       SETBIT (shiftset, errp->errs[i]);
+  for (i = 0; i < errp->nerrs; i++)
+    if (errp->errs[i])
+      SETBIT (shiftset, errp->errs[i]);
 
   if (state->nlookaheads == 1 && !nodefault)
     {
Index: src/state.c
--- src/state.c Sat, 01 Dec 2001 20:18:59 +0100 akim
+++ src/state.c Thu, 27 Dec 2001 10:47:27 +0100 akim
@@ -26,10 +26,41 @@
 | Create a new array of N shitfs.  |
 `---------------------------------*/
 
+#define SHIFTS_ALLOC(Nshifts)                                          \
+  (shifts *) xcalloc ((unsigned) (sizeof (shifts)                      \
+                                  + (Nshifts - 1) * sizeof (short)), 1)
+
 shifts *
 shifts_new (int n)
 {
   shifts *res = SHIFTS_ALLOC (n);
   res->nshifts = n;
+  return res;
+}
+
+
+/*-------------------------------.
+| Create a new array of N errs.  |
+`-------------------------------*/
+
+#define ERRS_ALLOC(Nerrs)                                              \
+  (errs *) xcalloc ((unsigned) (sizeof (errs)                          \
+                                  + (Nerrs - 1) * sizeof (short)), 1)
+
+
+errs *
+errs_new (int n)
+{
+  errs *res = ERRS_ALLOC (n);
+  res->nerrs = n;
+  return res;
+}
+
+
+errs *
+errs_dup (errs *src)
+{
+  errs *res = errs_new (src->nerrs);
+  memcpy (res->errs, src->errs, src->nerrs);
   return res;
 }
Index: src/state.h
--- src/state.h Sun, 16 Dec 2001 18:26:08 +0100 akim
+++ src/state.h Thu, 27 Dec 2001 10:47:43 +0100 akim
@@ -99,12 +99,7 @@
   short shifts[1];
 } shifts;
 
-
-#define SHIFTS_ALLOC(Nshifts)                                          \
-  (shifts *) xcalloc ((unsigned) (sizeof (shifts)                      \
-                                  + (Nshifts - 1) * sizeof (short)), 1)
-
-shifts * shifts_new PARAMS ((int n));
+shifts *shifts_new PARAMS ((int n));
 
 
 /* What is the symbol which is shifted by SHIFTS->shifts[Shift]?  Can
@@ -149,9 +144,8 @@
   short errs[1];
 } errs;
 
-#define ERRS_ALLOC(Nerrs)                                              \
-  (errs *) xcalloc ((unsigned) (sizeof (errs)                          \
-                                  + (Nerrs - 1) * sizeof (short)), 1)
+errs *errs_new PARAMS ((int n));
+errs *errs_dup PARAMS ((errs *src));
 
 
 /*-------------.



reply via email to

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