]> git.saurik.com Git - bison.git/blobdiff - src/print.c
Fix some memory leaks, and fix a bug: state 0 was examined twice.
[bison.git] / src / print.c
index f1dbe12d913157e20707ab87f66d3f3c48cdd83e..7adb51b06016495469461e2b4b49e3a9cf1d894f 100644 (file)
@@ -103,10 +103,10 @@ print_core (FILE *out, state_t *state)
       previous_lhs = rules[rule].lhs;
 
       for (sp = rules[rule].rhs; sp < sp1; sp++)
-       fprintf (out, " %s", symbol_tag_get (symbols[*sp]));
+       fprintf (out, " %s", symbols[*sp]->tag);
       fputs (" .", out);
       for (/* Nothing */; *sp >= 0; ++sp)
-       fprintf (out, " %s", symbol_tag_get (symbols[*sp]));
+       fprintf (out, " %s", symbols[*sp]->tag);
 
       /* Display the lookaheads?  */
       if (report_flag & report_lookaheads)
@@ -123,19 +123,19 @@ print_core (FILE *out, state_t *state)
 `----------------------------------------------------------------*/
 
 static void
-print_transitions (state_t *state, FILE *out, bool display_shifts_p)
+print_transitions (state_t *state, FILE *out, bool display_transitions_p)
 {
-  shifts_t *shiftp = state->shifts;
+  transitions_t *transitions = state->transitions;
   size_t width = 0;
   int i;
 
   /* Compute the width of the lookaheads column.  */
-  for (i = 0; i < shiftp->nshifts; i++)
-    if (!SHIFT_IS_DISABLED (shiftp, i)
-       && SHIFT_IS_SHIFT (shiftp, i) == display_shifts_p)
+  for (i = 0; i < transitions->num; i++)
+    if (!TRANSITION_IS_DISABLED (transitions, i)
+       && TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
       {
-       symbol_t *symbol = symbols[SHIFT_SYMBOL (shiftp, i)];
-       max_length (&width, symbol_tag_get (symbol));
+       symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
+       max_length (&width, symbol->tag);
       }
 
   /* Nothing to report. */
@@ -146,19 +146,19 @@ print_transitions (state_t *state, FILE *out, bool display_shifts_p)
   width += 2;
 
   /* Report lookaheads and shifts.  */
-  for (i = 0; i < shiftp->nshifts; i++)
-    if (!SHIFT_IS_DISABLED (shiftp, i)
-       && SHIFT_IS_SHIFT (shiftp, i) == display_shifts_p)
+  for (i = 0; i < transitions->num; i++)
+    if (!TRANSITION_IS_DISABLED (transitions, i)
+       && TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
       {
-       symbol_t *symbol = symbols[SHIFT_SYMBOL (shiftp, i)];
-       const char *tag = symbol_tag_get (symbol);
-       state_number_t state1 = shiftp->shifts[i];
+       symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
+       const char *tag = symbol->tag;
+       state_number_t state1 = transitions->states[i];
        int j;
 
        fprintf (out, "    %s", tag);
        for (j = width - strlen (tag); j > 0; --j)
          fputc (' ', out);
-       if (display_shifts_p)
+       if (display_transitions_p)
          fprintf (out, _("shift, and go to state %d\n"), state1);
        else
          fprintf (out, _("go to state %d\n"), state1);
@@ -178,9 +178,9 @@ print_errs (FILE *out, state_t *state)
   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, symbols[errp->symbols[i]]->tag);
 
   /* Nothing to report. */
   if (!width)
@@ -190,10 +190,10 @@ print_errs (FILE *out, state_t *state)
   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 = symbols[errp->symbols[i]]->tag;
        int j;
        fprintf (out, "    %s", tag);
        for (j = width - strlen (tag); j > 0; --j)
@@ -224,15 +224,15 @@ state_default_rule (state_t *state)
      we shift (S/R conflicts)...  */
   bitset_zero (shiftset);
   {
-    shifts_t *shiftp = state->shifts;
-    for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
-      if (!SHIFT_IS_DISABLED (shiftp, i))
+    transitions_t *transitions = state->transitions;
+    for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
+      if (!TRANSITION_IS_DISABLED (transitions, i))
        {
          /* If this state has a shift for the error token, don't use a
             default rule.  */
-         if (SHIFT_IS_ERROR (shiftp, i))
+         if (TRANSITION_IS_ERROR (transitions, i))
            return NULL;
-         bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
+         bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
        }
   }
 
@@ -240,9 +240,9 @@ state_default_rule (state_t *state)
      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)
@@ -288,7 +288,7 @@ print_reduction (FILE *out, size_t width,
   if (!enabled)
     fputc ('[', out);
   fprintf (out, _("reduce using rule %d (%s)"),
-          rule->number - 1, symbol_tag_get (rule->lhs));
+          rule->number - 1, rule->lhs->tag);
   if (!enabled)
     fputc (']', out);
   fputc ('\n', out);
@@ -302,21 +302,21 @@ print_reduction (FILE *out, size_t width,
 static void
 print_reductions (FILE *out, state_t *state)
 {
-  shifts_t *shiftp = state->shifts;
+  transitions_t *transitions = state->transitions;
   reductions_t *redp = state->reductions;
   rule_t *default_rule = NULL;
   size_t width = 0;
   int i, j;
 
-  if (redp->nreds == 0)
+  if (redp->num == 0)
     return;
 
   default_rule = state_default_rule (state);
 
   bitset_zero (shiftset);
-  for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
-    if (!SHIFT_IS_DISABLED (shiftp, i))
-      bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
+  for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
+    if (!TRANSITION_IS_DISABLED (transitions, i))
+      bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
 
   /* Compute the width of the lookaheads column.  */
   if (default_rule)
@@ -331,12 +331,12 @@ print_reductions (FILE *out, state_t *state)
            if (count == 0)
              {
                if (state->lookaheads_rule[j] != default_rule)
-                 max_length (&width, symbol_tag_get (symbols[i]));
+                 max_length (&width, symbols[i]->tag);
                count++;
              }
            else
              {
-               max_length (&width, symbol_tag_get (symbols[i]));
+               max_length (&width, symbols[i]->tag);
              }
          }
     }
@@ -361,7 +361,7 @@ print_reductions (FILE *out, state_t *state)
              {
                if (state->lookaheads_rule[j] != default_rule)
                  print_reduction (out, width,
-                                  symbol_tag_get (symbols[i]),
+                                  symbols[i]->tag,
                                   state->lookaheads_rule[j], TRUE);
                else
                  defaulted = 1;
@@ -371,11 +371,11 @@ print_reductions (FILE *out, state_t *state)
              {
                if (defaulted)
                  print_reduction (out, width,
-                                  symbol_tag_get (symbols[i]),
+                                  symbols[i]->tag,
                                   default_rule, TRUE);
                defaulted = 0;
                print_reduction (out, width,
-                                symbol_tag_get (symbols[i]),
+                                symbols[i]->tag,
                                 state->lookaheads_rule[j], FALSE);
              }
          }
@@ -396,9 +396,9 @@ static void
 print_actions (FILE *out, state_t *state)
 {
   reductions_t *redp = state->reductions;
-  shifts_t *shiftp = state->shifts;
+  transitions_t *transitions = state->transitions;
 
-  if (shiftp->nshifts == 0 && redp->nreds == 0)
+  if (transitions->num == 0 && redp->num == 0)
     {
       fputc ('\n', out);
       if (state->number == final_state->number)
@@ -463,7 +463,7 @@ print_grammar (FILE *out)
   for (i = 0; i < max_user_token_number + 1; i++)
     if (token_translations[i] != undeftoken->number)
       {
-       const char *tag = symbol_tag_get (symbols[token_translations[i]]);
+       const char *tag = symbols[token_translations[i]]->tag;
        rule_number_t r;
        item_number_t *rhsp;
 
@@ -491,7 +491,7 @@ print_grammar (FILE *out)
     {
       int left_count = 0, right_count = 0;
       rule_number_t r;
-      const char *tag = symbol_tag_get (symbols[i]);
+      const char *tag = symbols[i]->tag;
 
       for (r = 1; r < nrules + 1; r++)
        {