]> git.saurik.com Git - bison.git/blobdiff - src/output.c
* src/files.c, src/files.h (guard_obstack): Remove.
[bison.git] / src / output.c
index fd2bf3c47302c987d10c21df0aca692f8beed968..43935f59697851b734b9dd42c39e8215b24f8d7f 100644 (file)
@@ -323,16 +323,14 @@ output_rule_data (void)
 `------------------------------------------------------------------*/
 
 static int
-action_row (int state)
+action_row (state_t *state)
 {
   int i;
-  int m = 0;
-  int n = 0;
   int default_rule = 0;
-  reductions *redp = state_table[state]->reductions;
+  reductions *redp = state->reductions;
   int nreds = redp ? redp->nreds : 0;
-  shifts *shiftp = state_table[state]->shifts;
-  errs *errp = state_table[state]->errs;
+  shifts *shiftp = state->shifts;
+  errs *errp = state->errs;
   /* set nonzero to inhibit having any default reduction */
   int nodefault = 0;
 
@@ -344,17 +342,14 @@ action_row (int state)
       int j;
       /* loop over all the rules available here which require
         lookahead */
-      m = state_table[state]->lookaheadsp;
-      n = state_table[state + 1]->lookaheadsp;
-
-      for (i = n - 1; i >= m; i--)
+      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++)
          /* and record this rule as the rule to use if that
             token follows.  */
-         if (BITISSET (LA (i), j))
-           actrow[j] = -LAruleno[i];
+         if (BITISSET (LA (state->lookaheadsp + i), j))
+           actrow[j] = -LAruleno[state->lookaheadsp + i];
     }
 
   /* Now see which tokens are allowed for shifts in this state.  For
@@ -394,15 +389,15 @@ action_row (int state)
 
   if (nreds >= 1 && !nodefault)
     {
-      if (state_table[state]->consistent)
+      if (state->consistent)
        default_rule = redp->rules[0];
       else
        {
          int max = 0;
-         for (i = m; i < n; i++)
+         for (i = 0; i < state->nlookaheads; i++)
            {
              int count = 0;
-             int rule = -LAruleno[i];
+             int rule = -LAruleno[state->lookaheadsp + i];
              int j;
 
              for (j = 0; j < ntokens; j++)
@@ -492,7 +487,7 @@ token_actions (void)
   actrow = XCALLOC (short, ntokens);
   for (i = 0; i < nstates; ++i)
     {
-      yydefact[i] = action_row (i);
+      yydefact[i] = action_row (state_table[i]);
       save_row (i);
     }
 
@@ -541,6 +536,38 @@ actions_output (FILE *out, size_t *line)
 }
 
 
+/*----------------------------.
+| Output the guards to OOUT.  |
+`----------------------------*/
+
+static void
+guards_output (FILE *out, size_t *line)
+{
+  int rule;
+  for (rule = 1; rule < nrules + 1; ++rule)
+    if (rule_table[rule].action)
+      {
+       fprintf (out, "  case %d:\n", rule);
+
+       if (!no_lines_flag)
+         fprintf (out, muscle_find ("linef"),
+                  rule_table[rule].guard_line,
+                  quotearg_style (c_quoting_style,
+                                  muscle_find ("filename")));
+       fprintf (out, "{ %s; }\n    break;\n\n",
+                rule_table[rule].guard);
+
+       /* We always output 4 '\n' per action.  */
+       *line += 4;
+       /* Plus one if !no_lines_flag.  */
+       if (!no_lines_flag)
+         ++*line;
+       /* Get the number of lines written by the user.  */
+       *line += get_lines_number (rule_table[rule].guard);
+      }
+}
+
+
 static void
 save_column (int symbol, int default_state)
 {
@@ -933,6 +960,8 @@ output_parser (const char *skel_filename, FILE *out)
          muscle_value = muscle_find (muscle_key);
          if (!strcmp (muscle_key, "actions"))
            actions_output (out, &output_line);
+         else if (!strcmp (muscle_key, "guards"))
+           guards_output (out, &output_line);
          else if (!strcmp (muscle_key, "line"))
            fprintf (out, "%d", output_line);
          else if (!strcmp (muscle_key, "skeleton-line"))
@@ -1096,7 +1125,8 @@ output (void)
     header_output ();
 
   free (rule_table + 1);
-  obstack_free (&muscle_obstack, 0);
-  obstack_free (&format_obstack, 0);
-  obstack_free (&action_obstack, 0);
+  obstack_free (&muscle_obstack, NULL);
+  obstack_free (&format_obstack, NULL);
+  obstack_free (&action_obstack, NULL);
+  obstack_free (&attrs_obstack, NULL);
 }