]> git.saurik.com Git - bison.git/blobdiff - src/output.c
Fix some memory leaks, and fix a bug: state 0 was examined twice.
[bison.git] / src / output.c
index 30b29fea8ec97c013bd9f4a51a6a482aed6ea1cd..4a7a72653a7e97c1bd0226ef9f05f2a076b64a63 100644 (file)
@@ -249,7 +249,7 @@ prepare_tokens (void)
           SYMBOL_TAG_GET uses slot 0.  */
        const char *cp =
          quotearg_n_style (1, c_quoting_style,
-                           symbol_tag_get (symbols[i]));
+                           symbols[i]->tag);
        /* Width of the next token, including the two quotes, the coma
           and the space.  */
        int strsize = strlen (cp) + 2;
@@ -430,7 +430,7 @@ action_row (state_t *state)
   int i;
   rule_number_t default_rule = 0;
   reductions_t *redp = state->reductions;
-  shifts_t *shiftp = state->shifts;
+  transitions_t *transitions = state->transitions;
   errs_t *errp = state->errs;
   /* set nonzero to inhibit having any default reduction */
   int nodefault = 0;
@@ -439,62 +439,56 @@ action_row (state_t *state)
   for (i = 0; i < ntokens; i++)
     actrow[i] = conflrow[i] = 0;
 
-  if (redp->nreds >= 1)
+  if (redp->num >= 1)
     {
       int j;
+      bitset_iterator biter;
       /* loop over all the rules available here which require
         lookahead */
       for (i = state->nlookaheads - 1; i >= 0; --i)
        /* and find each token which the rule finds acceptable
           to come next */
-       for (j = 0; j < ntokens; j++)
+       BITSET_FOR_EACH (biter, state->lookaheads[i], j, 0)
+       {
          /* and record this rule as the rule to use if that
             token follows.  */
-         if (bitset_test (state->lookaheads[i], j))
-           {
-             if (actrow[j] != 0)
-               conflicted = conflrow[j] = 1;
-             actrow[j] = -state->lookaheads_rule[i]->number;
-           }
+         if (actrow[j] != 0)
+           conflicted = conflrow[j] = 1;
+         actrow[j] = -state->lookaheads_rule[i]->number;
+       }
     }
 
   /* 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
      to reduce.  */
-  for (i = 0; i < shiftp->nshifts; i++)
-    {
-      symbol_number_t symbol;
-      state_number_t shift_state = shiftp->shifts[i];
-      if (!shift_state)
-       continue;
-
-      symbol = states[shift_state]->accessing_symbol;
-
-      if (ISVAR (symbol))
-       break;
+  for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
+    if (!TRANSITION_IS_DISABLED (transitions, i))
+      {
+       symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i);
+       state_number_t shift_state = transitions->states[i];
 
-      if (actrow[symbol] != 0)
-       conflicted = conflrow[symbol] = 1;
-      actrow[symbol] = state_number_as_int (shift_state);
+       if (actrow[symbol] != 0)
+         conflicted = conflrow[symbol] = 1;
+       actrow[symbol] = state_number_as_int (shift_state);
 
-      /* Do not use any default reduction if there is a shift for
-        error */
-      if (symbol == errtoken->number)
-       nodefault = 1;
-    }
+       /* Do not use any default reduction if there is a shift for
+          error */
+       if (symbol == errtoken->number)
+         nodefault = 1;
+      }
 
   /* 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];
@@ -504,11 +498,11 @@ action_row (state_t *state)
          for (i = 0; i < state->nlookaheads; i++)
            {
              int count = 0;
-             rule_number_t rule = -state->lookaheads_rule[i]->number;
+             rule_number_t rule = state->lookaheads_rule[i]->number;
              symbol_number_t j;
 
              for (j = 0; j < ntokens; j++)
-               if (actrow[j] == rule)
+               if (actrow[j] == -rule)
                  count++;
 
              if (count > max)
@@ -528,10 +522,10 @@ action_row (state_t *state)
            {
              int j;
              for (j = 0; j < ntokens; j++)
-               if (actrow[j] == default_rule && ! (glr_parser && conflrow[j]))
+               if (actrow[j] == -default_rule
+                   && ! (glr_parser && conflrow[j]))
                  actrow[j] = 0;
            }
-         default_rule = -default_rule;
        }
     }
 
@@ -752,7 +746,7 @@ symbol_destructors_output (FILE *out)
        fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
                 first ? "" : ",\n",
                 infile, symbol->destructor_location.first_line,
-                symbol_tag_get (symbol),
+                symbol->tag,
                 symbol->number,
                 symbol->destructor,
                 symbol->type_name);
@@ -785,7 +779,7 @@ symbol_printers_output (FILE *out)
        fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
                 first ? "" : ",\n",
                 infile, symbol->printer_location.first_line,
-                symbol_tag_get (symbol),
+                symbol->tag,
                 symbol->number,
                 symbol->printer,
                 symbol->type_name);
@@ -1203,9 +1197,9 @@ m4_invoke (const char *definitions)
   if (!skel_in)
     error (EXIT_FAILURE, errno, "cannot run m4");
   skel_lex ();
-
 }
 
+
 /*---------------------------.
 | Call the skeleton parser.  |
 `---------------------------*/