bison-patches
[Top][All Lists]
Advanced

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

20-reds-and-errs.patch


From: Akim Demaille
Subject: 20-reds-and-errs.patch
Date: Sun, 30 Jun 2002 19:34:30 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/state.h (reductions_t): Rename member `nreds' as num.
        (errs_t): Rename members `nerrs' and `errs' as `num' and `symbols'.
        * src/state.c (ERRS_ALLOC, REDUCTIONS_ALLOC): Use the correct types.
        
        
Index: src/conflicts.c
--- src/conflicts.c Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/conflicts.c Sun, 30 Jun 2002 15:14:32 +0200 akim
@@ -58,7 +58,7 @@
 `----------------------------------------------------------------*/
 
 static inline void
-log_resolution (rule_t *rule, int token,
+log_resolution (rule_t *rule, symbol_number_t token,
                enum conflict_resolution_e resolution)
 {
   if (report_flag & report_solved_conflicts)
@@ -144,7 +144,8 @@
 
   bitset_reset (lookaheadset, token);
   for (i = 0; i < transitions->num; i++)
-    if (!TRANSITION_IS_DISABLED (transitions, i) && TRANSITION_SYMBOL 
(transitions, i) == token)
+    if (!TRANSITION_IS_DISABLED (transitions, i)
+       && TRANSITION_SYMBOL (transitions, i) == token)
       TRANSITION_DISABLE (transitions, i);
 }
 
@@ -174,13 +175,13 @@
 static void
 resolve_sr_conflict (state_t *state, int lookahead)
 {
-  int i;
+  symbol_number_t i;
   /* Find the rule to reduce by to get precedence of reduction.  */
   rule_t *redrule = state->lookaheads_rule[lookahead];
   int redprec = redrule->prec->prec;
   bitset lookaheads = state->lookaheads[lookahead];
   errs_t *errp = errs_new (ntokens + 1);
-  errp->nerrs = 0;
+  errp->num = 0;
 
   for (i = 0; i < ntokens; i++)
     if (bitset_test (lookaheads, i)
@@ -223,7 +224,7 @@
              flush_shift (state, i);
              flush_reduce (lookaheads, i);
              /* Record an explicit error for this token.  */
-             errp->errs[errp->nerrs++] = i;
+             errp->symbols[errp->num++] = i;
              break;
 
            case undef_assoc:
Index: src/lalr.c
--- src/lalr.c Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/lalr.c Sun, 30 Jun 2002 15:16:07 +0200 akim
@@ -77,7 +77,7 @@
   np = LArule;
   for (i = 0; i < nstates; i++)
     if (!states[i]->consistent)
-      for (j = 0; j < states[i]->reductions->nreds; j++)
+      for (j = 0; j < states[i]->reductions->num; j++)
        *np++ = &rules[states[i]->reductions->rules[j]];
 }
 
@@ -366,9 +366,9 @@
         reductions (i.e., there are two or more), or to distinguish a
         reduction from a shift.  Otherwise, it is straightforward,
         and the state is `consistent'.  */
-      if (rp->nreds > 1
-         || (rp->nreds == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)))
-       nlookaheads += rp->nreds;
+      if (rp->num > 1
+         || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)))
+       nlookaheads += rp->num;
       else
        states[i]->consistent = 1;
 
Index: src/output.c
--- src/output.c Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/output.c Sun, 30 Jun 2002 15:16:07 +0200 akim
@@ -439,7 +439,7 @@
   for (i = 0; i < ntokens; i++)
     actrow[i] = conflrow[i] = 0;
 
-  if (redp->nreds >= 1)
+  if (redp->num >= 1)
     {
       int j;
       /* loop over all the rules available here which require
@@ -478,16 +478,16 @@
 
   /* See which tokens are an explicit error in this state (due to
      %nonassoc).  For them, record SHRT_MIN as the action.  */
-  for (i = 0; i < errp->nerrs; i++)
+  for (i = 0; i < errp->num; i++)
     {
-      int symbol = errp->errs[i];
+      symbol_number_t symbol = errp->symbols[i];
       actrow[symbol] = SHRT_MIN;
     }
 
   /* Now find the most common reduction and make it the default action
      for this state.  */
 
-  if (redp->nreds >= 1 && !nodefault)
+  if (redp->num >= 1 && !nodefault)
     {
       if (state->consistent)
        default_rule = redp->rules[0];
Index: src/print.c
--- src/print.c Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/print.c Sun, 30 Jun 2002 15:16:07 +0200 akim
@@ -178,9 +178,9 @@
   int i;
 
   /* Compute the width of the lookaheads column.  */
-  for (i = 0; i < errp->nerrs; ++i)
-    if (errp->errs[i])
-      max_length (&width, symbol_tag_get (symbols[errp->errs[i]]));
+  for (i = 0; i < errp->num; ++i)
+    if (errp->symbols[i])
+      max_length (&width, symbol_tag_get (symbols[errp->symbols[i]]));
 
   /* Nothing to report. */
   if (!width)
@@ -190,10 +190,10 @@
   width += 2;
 
   /* Report lookaheads and errors.  */
-  for (i = 0; i < errp->nerrs; ++i)
-    if (errp->errs[i])
+  for (i = 0; i < errp->num; ++i)
+    if (errp->symbols[i])
       {
-       const char *tag = symbol_tag_get (symbols[errp->errs[i]]);
+       const char *tag = symbol_tag_get (symbols[errp->symbols[i]]);
        int j;
        fprintf (out, "    %s", tag);
        for (j = width - strlen (tag); j > 0; --j)
@@ -240,9 +240,9 @@
      we raise an error (due to %nonassoc).  */
   {
     errs_t *errp = state->errs;
-    for (i = 0; i < errp->nerrs; i++)
-      if (errp->errs[i])
-       bitset_set (shiftset, errp->errs[i]);
+    for (i = 0; i < errp->num; i++)
+      if (errp->symbols[i])
+       bitset_set (shiftset, errp->symbols[i]);
   }
 
   for (i = 0; i < state->nlookaheads; ++i)
@@ -308,7 +308,7 @@
   size_t width = 0;
   int i, j;
 
-  if (redp->nreds == 0)
+  if (redp->num == 0)
     return;
 
   default_rule = state_default_rule (state);
@@ -398,7 +398,7 @@
   reductions_t *redp = state->reductions;
   transitions_t *transitions = state->shifts;
 
-  if (transitions->num == 0 && redp->nreds == 0)
+  if (transitions->num == 0 && redp->num == 0)
     {
       fputc ('\n', out);
       if (state->number == final_state->number)
Index: src/state.c
--- src/state.c Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/state.c Sun, 30 Jun 2002 15:16:04 +0200 akim
@@ -76,14 +76,14 @@
 
 #define ERRS_ALLOC(Nerrs)                                              \
   (errs_t *) xcalloc ((unsigned) (sizeof (errs_t)                      \
-                                  + (Nerrs - 1) * sizeof (short)), 1)
+                                  + (Nerrs - 1) * sizeof (symbol_number_t)), 1)
 
 
 errs_t *
 errs_new (int n)
 {
   errs_t *res = ERRS_ALLOC (n);
-  res->nerrs = n;
+  res->num = n;
   return res;
 }
 
@@ -91,8 +91,8 @@
 errs_t *
 errs_dup (errs_t *src)
 {
-  errs_t *res = errs_new (src->nerrs);
-  memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0]));
+  errs_t *res = errs_new (src->num);
+  memcpy (res->symbols, src->symbols, src->num * sizeof (src->symbols[0]));
   return res;
 }
 
@@ -110,13 +110,13 @@
 
 #define REDUCTIONS_ALLOC(Nreductions)                                  \
   (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t)          \
-                                  + (Nreductions - 1) * sizeof (short)), 1)
+                                  + (Nreductions - 1) * sizeof 
(rule_number_t)), 1)
 
 static reductions_t *
 reductions_new (int nreductions, short *reductions)
 {
   reductions_t *res = REDUCTIONS_ALLOC (nreductions);
-  res->nreds = nreductions;
+  res->num = nreductions;
   memcpy (res->rules, reductions, nreductions * sizeof (reductions[0]));
   return res;
 }
Index: src/state.h
--- src/state.h Sun, 30 Jun 2002 15:07:58 +0200 akim
+++ src/state.h Sun, 30 Jun 2002 15:11:58 +0200 akim
@@ -152,8 +152,8 @@
 
 typedef struct errs_s
 {
-  short nerrs;
-  short errs[1];
+  short num;
+  symbol_number_t symbols[1];
 } errs_t;
 
 errs_t *errs_new PARAMS ((int n));
@@ -166,8 +166,8 @@
 
 typedef struct reductions_s
 {
-  short nreds;
-  short rules[1];
+  short num;
+  rule_number_t rules[1];
 } reductions_t;
 
 



reply via email to

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