]> git.saurik.com Git - bison.git/commitdiff
Still making progress in separating Bison into (i) input, (ii)
authorAkim Demaille <akim@epita.fr>
Sat, 15 Dec 2001 14:35:57 +0000 (14:35 +0000)
committerAkim Demaille <akim@epita.fr>
Sat, 15 Dec 2001 14:35:57 +0000 (14:35 +0000)
process, (iii) output: now we can directly output the parser file
without using table_obstack at all.
* src/files.c, src/files.h (table_obstack): Bye bye.
(parser_file_name): New.
* src/files.c (compute_output_file_names): Compute it.
* src/output.c (actions_output, output_parser)
(output_master_parser): To a file instead of an obstack.

ChangeLog
src/files.c
src/files.h
src/output.c

index b256520eb9399efb4fea950dc22c42466bdd3110..ae9d826f8fb1b6074cab1b346549529a96e8c9d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-12-15  Akim Demaille  <akim@epita.fr>
+
+       Still making progress in separating Bison into (i) input, (ii)
+       process, (iii) output: now we can directly output the parser file
+       without using table_obstack at all.
+
+       * src/files.c, src/files.h (table_obstack): Bye bye.
+       (parser_file_name): New.
+       * src/files.c (compute_output_file_names): Compute it.
+       * src/output.c (actions_output, output_parser)
+       (output_master_parser): To a file instead of an obstack.
+
 2001-12-15  Akim Demaille  <akim@epita.fr>
 
        Attach actions to rules, instead of pre-outputting them to
 2001-12-15  Akim Demaille  <akim@epita.fr>
 
        Attach actions to rules, instead of pre-outputting them to
index fa31b0327fad890827c0d7d4b0c35b5da8253bea..dc6eb1e652bcaf0c6c1e51dba1987dfb02b36065 100644 (file)
@@ -30,7 +30,6 @@ FILE *finput = NULL;
 
 struct obstack action_obstack;
 struct obstack attrs_obstack;
 
 struct obstack action_obstack;
 struct obstack attrs_obstack;
-struct obstack table_obstack;
 struct obstack defines_obstack;
 struct obstack guard_obstack;
 struct obstack output_obstack;
 struct obstack defines_obstack;
 struct obstack guard_obstack;
 struct obstack output_obstack;
@@ -41,6 +40,7 @@ const char *spec_name_prefix = "yy";  /* for -p. */
 char *spec_verbose_file = NULL;   /* for --verbose. */
 char *spec_graph_file = NULL;   /* for -g. */
 char *spec_defines_file = NULL; /* for --defines. */
 char *spec_verbose_file = NULL;   /* for --verbose. */
 char *spec_graph_file = NULL;   /* for -g. */
 char *spec_defines_file = NULL; /* for --defines. */
+char *parser_file_name = NULL;
 
 char *infile = NULL;
 char *attrsfile = NULL;
 
 char *infile = NULL;
 char *attrsfile = NULL;
@@ -433,6 +433,9 @@ compute_output_file_names (void)
 {
   compute_base_names ();
 
 {
   compute_base_names ();
 
+  parser_file_name =
+    spec_outfile ? spec_outfile : stringappend (base_name, src_extension);
+
   /* If not yet done. */
   if (!src_extension)
     src_extension = ".c";
   /* If not yet done. */
   if (!src_extension)
     src_extension = ".c";
@@ -453,7 +456,6 @@ compute_output_file_names (void)
 #ifndef MSDOS
   attrsfile = stringappend (attrsfile, header_extension);
 #endif /* MSDOS */
 #ifndef MSDOS
   attrsfile = stringappend (attrsfile, header_extension);
 #endif /* MSDOS */
-
 }
 
 /*-----------------------------------------------------------------.
 }
 
 /*-----------------------------------------------------------------.
@@ -469,7 +471,6 @@ open_files (void)
   /* Initialize the obstacks. */
   obstack_init (&action_obstack);
   obstack_init (&attrs_obstack);
   /* Initialize the obstacks. */
   obstack_init (&action_obstack);
   obstack_init (&attrs_obstack);
-  obstack_init (&table_obstack);
   obstack_init (&defines_obstack);
   obstack_init (&guard_obstack);
   obstack_init (&output_obstack);
   obstack_init (&defines_obstack);
   obstack_init (&guard_obstack);
   obstack_init (&output_obstack);
@@ -494,13 +495,6 @@ close_files (void)
 void
 output_files (void)
 {
 void
 output_files (void)
 {
-  /* Output the main file.  */
-  if (spec_outfile)
-    obstack_save (&table_obstack, spec_outfile);
-  else
-    obstack_save (&table_obstack, stringappend (base_name, src_extension));
-  obstack_free (&table_obstack, NULL);
-
   /* Output the header file if wanted. */
   if (defines_flag)
     defines_obstack_save (spec_defines_file);
   /* Output the header file if wanted. */
   if (defines_flag)
     defines_obstack_save (spec_defines_file);
index 2ef0a4ad66e3aa261f081a98a56f1ec10da76470..301086355d7eb375bb8e9865130c4d3c9fc53aca 100644 (file)
@@ -1,7 +1,5 @@
-#ifndef FILES_H_
-# define FILES_H_
 /* File names and variables for bison,
 /* File names and variables for bison,
-   Copyright 1984, 1989, 2000 Free Software Foundation, Inc.
+   Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-/* These two should be pathnames for opening the sample parser files.
-   When bison is installed, they should be absolute pathnames.
-   XPFILE1 and XPFILE2 normally come from config.h.  */
+#ifndef FILES_H_
+# define FILES_H_
 
 /* File name specified with -o for the output file, or 0 if no -o.  */
 extern char *spec_outfile;
 
 
 /* File name specified with -o for the output file, or 0 if no -o.  */
 extern char *spec_outfile;
 
+/* File name for the parser (i.e., the one above, or its default.) */
+extern char *parser_file_name;
+
 /* For -a. */
 extern const char *spec_name_prefix;
 
 /* For -a. */
 extern const char *spec_name_prefix;
 
@@ -49,10 +49,6 @@ extern FILE *finput;
 /* Output all the action code; precise form depends on which parser. */
 extern struct obstack action_obstack;
 
 /* Output all the action code; precise form depends on which parser. */
 extern struct obstack action_obstack;
 
-/* Output the tables and the parser and also contains all the %{
-   ... %} definitions.  */
-extern struct obstack table_obstack;
-
 /* optionally output #define's for token numbers. */
 extern struct obstack defines_obstack;
 
 /* optionally output #define's for token numbers. */
 extern struct obstack defines_obstack;
 
index 7c2d0136721a335b2fc56eb116ff92a3453f55d7..b919c6a3263fee34725e95b77a3d4a028804dbb7 100644 (file)
@@ -515,25 +515,25 @@ token_actions (void)
 `-----------------------------*/
 
 static void
 `-----------------------------*/
 
 static void
-actions_output (struct obstack *oout)
+actions_output (FILE *out)
 {
   int rule;
   for (rule = 1; rule < nrules + 1; ++rule)
     if (rule_table[rule].action)
       {
 {
   int rule;
   for (rule = 1; rule < nrules + 1; ++rule)
     if (rule_table[rule].action)
       {
-       obstack_fgrow1 (oout, "  case %d:\n", rule);
+       fprintf (out, "  case %d:\n", rule);
 
        if (!no_lines_flag)
 
        if (!no_lines_flag)
-         obstack_fgrow2 (oout, muscle_find ("linef"),
-                         rule_table[rule].action_line,
-                         quotearg_style (c_quoting_style,
-                                         muscle_find ("filename")));
-       obstack_1grow (oout, '{');
-       obstack_sgrow (oout, rule_table[rule].action);
+         fprintf (out, muscle_find ("linef"),
+                  rule_table[rule].action_line,
+                  quotearg_style (c_quoting_style,
+                                  muscle_find ("filename")));
        /* As a Bison extension, add the ending semicolon.  Since some
           Yacc don't do that, help people using bison as a Yacc
           finding their missing semicolons.  */
        /* As a Bison extension, add the ending semicolon.  Since some
           Yacc don't do that, help people using bison as a Yacc
           finding their missing semicolons.  */
-       obstack_fgrow1 (oout, "%s}\n    break;\n\n", yacc_flag ? ";" : "");
+       fprintf (out, "{ %s%s }\n    break;\n\n",
+                rule_table[rule].action,
+                yacc_flag ? ";" : "");
       }
 }
 
       }
 }
 
@@ -924,7 +924,7 @@ output_actions (void)
 `------------------------------------------------------------*/
 
 static void
 `------------------------------------------------------------*/
 
 static void
-output_parser (const char *skel_filename, struct obstack *oout)
+output_parser (const char *skel_filename, FILE *out)
 {
   int c;
   FILE *fskel;
 {
   int c;
   FILE *fskel;
@@ -941,7 +941,7 @@ output_parser (const char *skel_filename, struct obstack *oout)
        {
          if (c == '\n')
            ++line;
        {
          if (c == '\n')
            ++line;
-         obstack_1grow (oout, c);
+         putc (c, out);
          c = getc (fskel);
        }
       else if ((c = getc (fskel)) == '%')
          c = getc (fskel);
        }
       else if ((c = getc (fskel)) == '%')
@@ -958,19 +958,19 @@ output_parser (const char *skel_filename, struct obstack *oout)
          muscle_key = obstack_finish (&muscle_obstack);
          muscle_value = muscle_find (muscle_key);
          if (!strcmp (muscle_key, "actions"))
          muscle_key = obstack_finish (&muscle_obstack);
          muscle_value = muscle_find (muscle_key);
          if (!strcmp (muscle_key, "actions"))
-           actions_output (oout);
+           actions_output (out);
          else if (!strcmp (muscle_key, "line"))
          else if (!strcmp (muscle_key, "line"))
-           obstack_fgrow1 (oout, "%d", line + 1);
+           fprintf (out, "%d", line + 1);
          else if (muscle_value)
          else if (muscle_value)
-           obstack_sgrow (oout, muscle_value);
+           fputs (muscle_value, out);
          else
            {
          else
            {
-             obstack_sgrow (oout, "%%");
-             obstack_sgrow (oout, muscle_key);
+             fputs ("%%", out);
+             fputs (muscle_key, out);
            }
        }
       else
            }
        }
       else
-       obstack_1grow (oout, '%');
+       putc ('%', out);
     }
 
   /* End.  */
     }
 
   /* End.  */
@@ -984,6 +984,7 @@ output_parser (const char *skel_filename, struct obstack *oout)
 static void
 output_master_parser (void)
 {
 static void
 output_master_parser (void)
 {
+  FILE *parser = xfopen (parser_file_name, "w");
   if (!skeleton)
     {
       if (semantic_parser)
   if (!skeleton)
     {
       if (semantic_parser)
@@ -992,7 +993,9 @@ output_master_parser (void)
        skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
     }
   muscle_insert ("skeleton", skeleton);
        skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
     }
   muscle_insert ("skeleton", skeleton);
-  output_parser (skeleton, &table_obstack);
+
+  output_parser (skeleton, parser);
+  xfclose (parser);
 }
 
 
 }