bison-patches
[Top][All Lists]
Advanced

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

[Main] %union can be define in user declaration.


From: Pascal Bart
Subject: [Main] %union can be define in user declaration.
Date: Sun, 13 Jan 2002 01:18:25 +0000 (GMT)

Hello,

        This patch defines YYSTYPE at the same place that %union. It
repairs the example of gettext, and leave user to use their own type in
%union and to have an object of YYSTYPE type in the user declarations.  I
need to make tests for this, but I don't know in which section to put it
and how to name it, should I make a new test section ?

Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.516
diff -u -r1.516 ChangeLog
--- ChangeLog   11 Jan 2002 15:32:06 -0000      1.516
+++ ChangeLog   12 Jan 2002 23:54:47 -0000
@@ -1,3 +1,14 @@
+2002-01-12  Pascal Bart  <address@hidden>
+
+       * src/files.c: New obstack attrs_after_union_obstack.
+       * src/files.h: Declare it.
+       * src/reader.c (copy_definition): Use a tempory obstack
+       user_attrs_obstack, and assign it to attrs_obstack if `%union'
+       was not defined, else assign it to attrs_after_union_obstack.
+       (reader): Initialize attrs_after_union_obstack.
+       * src/output.c (output): Free attrs_after_union_obstack.
+       (output): Copy attrs_after_union_obstack in the `post_prologue' muscle.
+
 2002-01-11  Tim Van Holder  <address@hidden>

        * lib/hash.h, lib/hash.c: Renamed __P to PARAMS and used the
Index: src/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/src/bison.simple,v
retrieving revision 1.102
diff -u -r1.102 bison.simple
--- src/bison.simple    9 Jan 2002 13:03:45 -0000       1.102
+++ src/bison.simple    12 Jan 2002 23:54:49 -0000
@@ -54,10 +54,19 @@
 # define yylloc %%{prefix}lloc
 #endif

-
 /* Copy the user declarations.  */
 %%{prologue}

+#ifndef YYSTYPE
+typedef %%{stype} yystype;
+# define YYSTYPE yystype
+#endif
+
+/* Copy the user declarations, which are introduce after %union
+   declaration.  */
+/* FIXME Rename the muscle.  */
+%%{post_prologue}
+
 /* Enabling traces.  */
 #ifndef YYDEBUG
 # define YYDEBUG %%{debug}
@@ -69,11 +78,6 @@
 # define YYERROR_VERBOSE 1
 #else
 # define YYERROR_VERBOSE %%{error-verbose}
-#endif
-
-#ifndef YYSTYPE
-typedef %%{stype} yystype;
-# define YYSTYPE yystype
 #endif

 #ifndef YYLTYPE
Index: src/files.c
===================================================================
RCS file: /cvsroot/bison/bison/src/files.c,v
retrieving revision 1.67
diff -u -r1.67 files.c
--- src/files.c 9 Jan 2002 13:03:45 -0000       1.67
+++ src/files.c 12 Jan 2002 23:54:50 -0000
@@ -34,6 +34,7 @@

 struct obstack action_obstack;
 struct obstack attrs_obstack;
+struct obstack attrs_after_union_obstack;
 struct obstack output_obstack;

 /* Initializing some values below (such SPEC_NAME_PREFIX to `yy') is
Index: src/files.h
===================================================================
RCS file: /cvsroot/bison/bison/src/files.h,v
retrieving revision 1.27
diff -u -r1.27 files.h
--- src/files.h 9 Jan 2002 13:03:45 -0000       1.27
+++ src/files.h 12 Jan 2002 23:54:50 -0000
@@ -52,6 +52,9 @@
 /* If semantic parser, output a .h file that defines YYSTYPE... */
 extern struct obstack attrs_obstack;

+/* Contain user declarations after the `%union' definition. */
+extern struct obstack attrs_after_union_obstack;
+
 /* The verbose output. */
 extern struct obstack output_obstack;

Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.122
diff -u -r1.122 output.c
--- src/output.c        9 Jan 2002 13:03:45 -0000       1.122
+++ src/output.c        12 Jan 2002 23:54:51 -0000
@@ -1093,6 +1093,10 @@
   obstack_1grow (&attrs_obstack, 0);
   muscle_insert ("prologue", obstack_finish (&attrs_obstack));

+  /* Copy definitions in directive, which need YYSTYPE.  */
+  obstack_1grow (&attrs_after_union_obstack, 0);
+  muscle_insert ("post_prologue", obstack_finish (&attrs_after_union_obstack));
+
   /* Process the selected skeleton file.  */
   output_skeleton ();

@@ -1105,4 +1109,5 @@
   obstack_free (&format_obstack, NULL);
   obstack_free (&action_obstack, NULL);
   obstack_free (&attrs_obstack, NULL);
+  obstack_free (&attrs_after_union_obstack, NULL);
 }
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.144
diff -u -r1.144 reader.c
--- src/reader.c        6 Jan 2002 20:50:08 -0000       1.144
+++ src/reader.c        12 Jan 2002 23:54:53 -0000
@@ -435,10 +435,12 @@
   int c;
   /* -1 while reading a character if prev char was %. */
   int after_percent;
+  struct obstack user_attrs_obstack;

+  obstack_init (&user_attrs_obstack);
   if (!no_lines_flag)
     {
-      obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"),
+      obstack_fgrow2 (&user_attrs_obstack, muscle_find ("linef"),
                      lineno, quotearg_style (c_quoting_style,
                                              muscle_find ("filename")));
     }
@@ -452,7 +454,7 @@
       switch (c)
        {
        case '\n':
-         obstack_1grow (&attrs_obstack, c);
+         obstack_1grow (&user_attrs_obstack, c);
          lineno++;
          break;

@@ -462,18 +464,18 @@

        case '\'':
        case '"':
-         copy_string (finput, &attrs_obstack, c);
+         copy_string (finput, &user_attrs_obstack, c);
          break;

        case '/':
-         copy_comment (finput, &attrs_obstack);
+         copy_comment (finput, &user_attrs_obstack);
          break;

        case EOF:
          fatal ("%s", _("unterminated `%{' definition"));

        default:
-         obstack_1grow (&attrs_obstack, c);
+         obstack_1grow (&user_attrs_obstack, c);
        }

       c = getc (finput);
@@ -481,11 +483,26 @@
       if (after_percent)
        {
          if (c == '}')
-           return;
-         obstack_1grow (&attrs_obstack, '%');
+           break;
+         obstack_1grow (&user_attrs_obstack, '%');
        }
       after_percent = 0;
     }
+
+  obstack_1grow (&user_attrs_obstack, 0);
+  if ( typed == 0 )
+    {
+      /* If %union is not ever define.  */
+      char *obstack = obstack_finish (&user_attrs_obstack);
+      obstack_sgrow (&attrs_obstack, obstack);
+    }
+  else
+    {
+      /* %union was defined before this user declarations.  */
+      char *obstack = obstack_finish (&user_attrs_obstack);
+      obstack_sgrow (&attrs_after_union_obstack, obstack);
+    }
+  obstack_free (&user_attrs_obstack, NULL);
 }


@@ -513,7 +530,7 @@
       /* `%' (for instance from `%token', or from `%%' etc.) is the
         only valid means to end this declaration.  */
       if (tmp_char == '%')
-       return;
+       break;
       if (tmp_char == EOF)
        fatal (_("Premature EOF after %s"), token_buffer);

@@ -1784,6 +1801,7 @@
   /* Initialize the obstacks. */
   obstack_init (&action_obstack);
   obstack_init (&attrs_obstack);
+  obstack_init (&attrs_after_union_obstack);
   obstack_init (&output_obstack);

   finput = xfopen (infile, "r");

Pascal Bart (address@hidden)




reply via email to

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