bison-patches
[Top][All Lists]
Advanced

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

Re: proposal: simplify prologue alternatives into %code


From: Joel E. Denny
Subject: Re: proposal: simplify prologue alternatives into %code
Date: Tue, 9 Jan 2007 00:24:18 -0500 (EST)

On Thu, 4 Jan 2007, Paolo Bonzini wrote:

> %union had an apparently useless mess to add the braces in parse-gram.y rather
> than in the skeletons, and I got rid of it.

I agree.  I took several parts of your proposed patch, and I committed the 
following.  Thanks.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1655
diff -p -u -r1.1655 ChangeLog
--- ChangeLog   9 Jan 2007 01:17:50 -0000       1.1655
+++ ChangeLog   9 Jan 2007 05:15:10 -0000
@@ -1,3 +1,35 @@
+2007-01-09  Paolo Bonzini  <address@hidden>
+       and Joel E. Denny  <address@hidden>
+
+       Simplify union and prologue handling, and escape union and lex/parse
+       params with digraphs.
+       * data/bison.m4 (b4_pre_prologue, b4_post_prologue): Set their default
+       values to the empty string since these are no longer guaranteed
+       initialized by the front-end.
+       * data/glr.c, data/glr.cc, data/lalr1.cc, data/push.c, data/yacc.c: Add
+       braces around b4_user_stype since this is no longer done by the
+       front-end.
+       * src/files.c, src/files.h (pre_prologue_obstack,
+       post_prologue_obstack): Remove.
+       * src/muscle_tab.c (muscle_pair_list_grow): Don't duplicate header
+       comments here.  Use MUSCLE_OBSTACK_SGROW so that values are escaped
+       with digraphs.  This fixes lex params and parse params.
+       * src/muscle_tab.h (muscle_pair_list_grow): Update comments.
+       * src/output.c (prepare): Remove muscle insertion of the prologues.
+       (output): Remove freeing of pre_prologue_obstack and
+       post_prologue_obstack.
+       * src/parse-gram.y (prologue_declaration): Use muscle_code_grow rather
+       than prologue_augment for prologue parsing so you don't need prologue
+       obstacks.
+       (grammar_declaration): Use `braceless' instead of "{...}" so that
+       braces are already stripped and code is escaped with digraphs.
+       * src/reader.c (prologue_augment): Remove.
+       (reader): Remove initialization of pre_prologue_obstack and
+       post_prologue_obstack.
+       * src/reader.h (prologue_augment): Remove.
+
+       * data/c.m4: Remove stray parenthesis.
+
 2007-01-08  Joel E. Denny  <address@hidden>
 
        Remove quotes from variables names in %define directives and from
Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.10
diff -p -u -r1.10 bison.m4
--- data/bison.m4       8 Jan 2007 21:38:29 -0000       1.10
+++ data/bison.m4       9 Jan 2007 05:15:10 -0000
@@ -155,6 +155,8 @@ m4_define([b4_fatal_at],
 ## ---------------- ##
 
 # m4_define_default([b4_lex_param], [])   dnl breaks other skeletons
+m4_define_default([b4_pre_prologue], [])
+m4_define_default([b4_post_prologue], [])
 m4_define_default([b4_epilogue], [])
 m4_define_default([b4_parse_param], [])
 
Index: data/c.m4
===================================================================
RCS file: /sources/bison/bison/data/c.m4,v
retrieving revision 1.69
diff -p -u -r1.69 c.m4
--- data/c.m4   6 Jan 2007 06:14:04 -0000       1.69
+++ data/c.m4   9 Jan 2007 05:15:11 -0000
@@ -79,7 +79,7 @@ m4_define([b4_user_args],
 # If defined, b4_parse_param arrives double quoted, but below we prefer
 # it to be single quoted.
 m4_define([b4_parse_param],
-b4_parse_param))
+b4_parse_param)
 
 
 # b4_parse_param_for(DECL, FORMAL, BODY)
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.198
diff -p -u -r1.198 glr.c
--- data/glr.c  8 Jan 2007 21:38:29 -0000       1.198
+++ data/glr.c  9 Jan 2007 05:15:11 -0000
@@ -180,8 +180,9 @@ b4_token_enums(b4_tokens)
 [#ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
 [[typedef union ]b4_union_name[
+{
 ]b4_user_stype[
-       YYSTYPE;
+} YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1]],
 [m4_if(b4_tag_seen_flag, 0,
 [[typedef int YYSTYPE;
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.33
diff -p -u -r1.33 glr.cc
--- data/glr.cc 8 Jan 2007 21:38:29 -0000       1.33
+++ data/glr.cc 9 Jan 2007 05:15:11 -0000
@@ -280,8 +280,9 @@ namespace ]b4_namespace[
 #ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
 [    union semantic_type
+    {
 b4_user_stype
-       ;],
+    };],
 [m4_if(b4_tag_seen_flag, 0,
 [[    typedef int semantic_type;]],
 [[    typedef YYSTYPE semantic_type;]])])[
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.150
diff -p -u -r1.150 lalr1.cc
--- data/lalr1.cc       8 Jan 2007 21:38:29 -0000       1.150
+++ data/lalr1.cc       9 Jan 2007 05:15:12 -0000
@@ -108,8 +108,9 @@ namespace ]b4_namespace[
 #ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
 [    union semantic_type
+    {
 b4_user_stype
-       ;],
+    };],
 [m4_if(b4_tag_seen_flag, 0,
 [[    typedef int semantic_type;]],
 [[    typedef YYSTYPE semantic_type;]])])[
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.33
diff -p -u -r1.33 push.c
--- data/push.c 8 Jan 2007 21:38:29 -0000       1.33
+++ data/push.c 9 Jan 2007 05:15:12 -0000
@@ -205,8 +205,9 @@ b4_token_enums_defines(b4_tokens)[
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 ]m4_ifdef([b4_stype],
 [[typedef union ]b4_union_name[
+{
 ]b4_user_stype[
-       YYSTYPE;
+} YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1]],
 [m4_if(b4_tag_seen_flag, 0,
 [[typedef int YYSTYPE;
@@ -1660,8 +1661,9 @@ b4_token_enums_defines(b4_tokens)
 [#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 ]m4_ifdef([b4_stype],
 [[typedef union ]b4_union_name[
+{
 ]b4_user_stype[
-       YYSTYPE;
+} YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1]],
 [m4_if(b4_tag_seen_flag, 0,
 [[typedef int YYSTYPE;
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.161
diff -p -u -r1.161 yacc.c
--- data/yacc.c 8 Jan 2007 21:38:29 -0000       1.161
+++ data/yacc.c 9 Jan 2007 05:15:12 -0000
@@ -192,8 +192,9 @@ b4_token_enums_defines(b4_tokens)[
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 ]m4_ifdef([b4_stype],
 [[typedef union ]b4_union_name[
+{
 ]b4_user_stype[
-       YYSTYPE;
+} YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1]],
 [m4_if(b4_tag_seen_flag, 0,
 [[typedef int YYSTYPE;
@@ -1497,8 +1498,9 @@ b4_token_enums_defines(b4_tokens)
 [#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 ]m4_ifdef([b4_stype],
 [[typedef union ]b4_union_name[
+{
 ]b4_user_stype[
-       YYSTYPE;
+} YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1]],
 [m4_if(b4_tag_seen_flag, 0,
 [[typedef int YYSTYPE;
Index: src/files.c
===================================================================
RCS file: /sources/bison/bison/src/files.c,v
retrieving revision 1.102
diff -p -u -r1.102 files.c
--- src/files.c 19 Dec 2006 00:34:36 -0000      1.102
+++ src/files.c 9 Jan 2007 05:15:16 -0000
@@ -35,9 +35,6 @@
 #include "getargs.h"
 #include "gram.h"
 
-struct obstack pre_prologue_obstack;
-struct obstack post_prologue_obstack;
-
 /* Initializing some values below (such SPEC_NAME_PREFIX to `yy') is
    tempting, but don't do that: for the time being our handling of the
    %directive vs --option leaves precedence to the options by deciding
Index: src/files.h
===================================================================
RCS file: /sources/bison/bison/src/files.h,v
retrieving revision 1.44
diff -p -u -r1.44 files.h
--- src/files.h 12 Dec 2006 06:47:39 -0000      1.44
+++ src/files.h 9 Jan 2007 05:15:16 -0000
@@ -49,11 +49,6 @@ extern char *spec_defines_file;
 /* Directory prefix of output file names.  */
 extern char *dir_prefix;
 
-
-/* If semantic parser, output a .h file that defines YYSTYPE... */
-extern struct obstack pre_prologue_obstack;
-extern struct obstack post_prologue_obstack;
-
 /* The file name as given on the command line.
    Not named "input_file" because Flex uses this name for an argument,
    and therefore GCC warns about a name clash. */
Index: src/muscle_tab.c
===================================================================
RCS file: /sources/bison/bison/src/muscle_tab.c,v
retrieving revision 1.44
diff -p -u -r1.44 muscle_tab.c
--- src/muscle_tab.c    8 Jan 2007 21:38:29 -0000       1.44
+++ src/muscle_tab.c    9 Jan 2007 05:15:16 -0000
@@ -191,18 +191,15 @@ muscle_code_grow (const char *key, const
 }
 
 
-/*-------------------------------------------------------------------.
-| MUSCLE is an M4 list of pairs.  Create or extend it with the pair  |
-| (A1, A2).  Note that because the muscle values are output *double* |
-| quoted, one needs to strip the first level of quotes to reach the  |
-| list itself.                                                       |
-`-------------------------------------------------------------------*/
-
 void muscle_pair_list_grow (const char *muscle,
                            const char *a1, const char *a2)
 {
   char *pair;
-  obstack_fgrow2 (&muscle_obstack, "[[[%s]], [[%s]]]", a1, a2);
+  obstack_sgrow (&muscle_obstack, "[[[");
+  MUSCLE_OBSTACK_SGROW (&muscle_obstack, a1);
+  obstack_sgrow (&muscle_obstack, "]], [[");
+  MUSCLE_OBSTACK_SGROW (&muscle_obstack, a2);
+  obstack_sgrow (&muscle_obstack, "]]]");
   obstack_1grow (&muscle_obstack, 0);
   pair = obstack_finish (&muscle_obstack);
   muscle_grow (muscle, pair, ",\n");
Index: src/muscle_tab.h
===================================================================
RCS file: /sources/bison/bison/src/muscle_tab.h,v
retrieving revision 1.22
diff -p -u -r1.22 muscle_tab.h
--- src/muscle_tab.h    8 Jan 2007 21:38:29 -0000       1.22
+++ src/muscle_tab.h    9 Jan 2007 05:15:16 -0000
@@ -104,10 +104,9 @@ void muscle_code_grow (const char *key, 
 
 
 /* MUSCLE is an M4 list of pairs.  Create or extend it with the pair
-   (A1, A2).  Note that because the muscle values are output *double*
-   quoted, one needs to strip the first level of quotes to reach the
-   list itself.  */
-
+   (A1, A2) after escaping both values with digraphs.  Note that because the
+   muscle values are output *double* quoted, one needs to strip the first level
+   of quotes to reach the list itself.  */
 void muscle_pair_list_grow (const char *muscle,
                            const char *a1, const char *a2);
 
Index: src/output.c
===================================================================
RCS file: /sources/bison/bison/src/output.c,v
retrieving revision 1.265
diff -p -u -r1.265 output.c
--- src/output.c        6 Jan 2007 06:14:04 -0000       1.265
+++ src/output.c        9 Jan 2007 05:15:16 -0000
@@ -595,12 +595,6 @@ prepare (void)
   DEFINE (spec_verbose_file);
 #undef DEFINE
 
-  /* User Code.  */
-  obstack_1grow (&pre_prologue_obstack, 0);
-  obstack_1grow (&post_prologue_obstack, 0);
-  muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
-  muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
-
   /* Find the right skeleton file, and add muscles about the skeletons.  */
   if (skeleton)
     MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
@@ -639,6 +633,4 @@ output (void)
   output_skeleton ();
 
   obstack_free (&format_obstack, NULL);
-  obstack_free (&pre_prologue_obstack, NULL);
-  obstack_free (&post_prologue_obstack, NULL);
 }
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.112
diff -p -u -r1.112 parse-gram.y
--- src/parse-gram.y    9 Jan 2007 01:17:51 -0000       1.112
+++ src/parse-gram.y    9 Jan 2007 05:15:17 -0000
@@ -228,7 +228,8 @@ prologue_declaration:
       code_props_plain_init (&plain_code, $1, @1);
       code_props_translate_code (&plain_code);
       gram_scanner_last_string_free ();
-      prologue_augment (plain_code.code, @1, union_seen);
+      muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
+                        plain_code.code, @1);
       code_scanner_last_string_free ();
     }
 | "%debug"                         { debug_flag = true; }
@@ -350,28 +351,11 @@ union_name:
 ;
 
 grammar_declaration:
-  "%union" union_name "{...}"
+  "%union" union_name braceless
     {
-      char const *body = $3;
-
-      /* Concatenate the %union bodies.  If this is the first %union, make sure
-        the synchronization line appears after the opening '{' so as not to
-        confuse Doxygen.  Otherwise, turn the previous %union's trailing '}'
-        into '\n', and omit the new %union's leading '{'.  */
-      if (!union_seen)
-       {
-         muscle_grow ("stype", "{", "");
-       }
-      else
-       {
-         char *code = muscle_find ("stype");
-         code[strlen (code) - 1] = '\n';
-       }
-      body++;
-
       union_seen = true;
-      muscle_code_grow ("stype", body, @3);
-      gram_scanner_last_string_free ();
+      muscle_code_grow ("stype", $3, @3);
+      code_scanner_last_string_free ();
     }
 ;
 
Index: src/reader.c
===================================================================
RCS file: /sources/bison/bison/src/reader.c,v
retrieving revision 1.281
diff -p -u -r1.281 reader.c
--- src/reader.c        4 Jan 2007 04:51:22 -0000       1.281
+++ src/reader.c        9 Jan 2007 05:15:17 -0000
@@ -69,27 +69,6 @@ grammar_start_symbol_set (symbol *sym, l
     }
 }
 
-
-/*---------------------------------------------------------------------.
-| There are two prologues: one before the first %union and one after.  |
-| Augment the one specified by POST.                                   |
-`---------------------------------------------------------------------*/
-
-void
-prologue_augment (const char *prologue, location loc, bool post)
-{
-  struct obstack *oout =
-    !post ? &pre_prologue_obstack : &post_prologue_obstack;
-
-  obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
-  /* FIXME: Protection of M4 characters missing here.  See
-     output.c:escaped_output.  */
-  MUSCLE_OBSTACK_SGROW (oout,
-                       quotearg_style (c_quoting_style, loc.start.file));
-  obstack_sgrow (oout, "]])[\n");
-  obstack_sgrow (oout, prologue);
-}
-
 
 
 /*------------------------------------------------------------------------.
@@ -585,10 +564,6 @@ reader (void)
   undeftoken->class = token_sym;
   undeftoken->number = ntokens++;
 
-  /* Initialize the obstacks. */
-  obstack_init (&pre_prologue_obstack);
-  obstack_init (&post_prologue_obstack);
-
   gram_in = xfopen (grammar_file, "r");
 
   gram__flex_debug = trace_flag & trace_scan;
Index: src/reader.h
===================================================================
RCS file: /sources/bison/bison/src/reader.h,v
retrieving revision 1.55
diff -p -u -r1.55 reader.h
--- src/reader.h        9 Jul 2006 20:36:33 -0000       1.55
+++ src/reader.h        9 Jan 2007 05:15:17 -0000
@@ -44,7 +44,6 @@ char const *token_name (int type);
 
 /* From reader.c. */
 void grammar_start_symbol_set (symbol *sym, location loc);
-void prologue_augment (const char *prologue, location loc, bool post);
 void grammar_current_rule_begin (symbol *lhs, location loc);
 void grammar_current_rule_end (location loc);
 void grammar_midrule_action (void);





reply via email to

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