bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] More %define/%code encapsulation


From: Paolo Bonzini
Subject: Re: [PATCH] More %define/%code encapsulation
Date: Thu, 18 Jan 2007 08:48:17 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)

Ok, I will commit, together with the Java stuff, the attached patch to
only include the _flag_if and _ifdef macros, and to remove the
b4_percent_code_unqualified special case.  I think we have agreement on
those.

Actually, the patch is a bit bold in that it also include the change to
parse-gram.y, to modify the defined value for "%define NAME" without any
value; I may or may not commit it depending on the outcome of the
discussion and the possible input of Akim and Paul.

Paolo

2006-11-16  Paolo Bonzini  <address@hidden>

        * data/bison.m4 (b4_percent_define_ifdef, b4_percent_define_flag_if,
        b4_percent_code_ifdef): New.
        (b4_percent_code_get): Map unqualified %code to b4_percent_code().
        * data/location.cc: Use b4_percent_define_flag_if.

        * doc/bison.texinfo (Directives): Document %define.

        * src/parse-gram.y (Unqualified %code): Change muscle name to
        b4_percent_code().
        (content.opt): Default to empty.

Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.12
diff -u -r1.12 bison.m4
--- data/bison.m4       16 Jan 2007 06:16:03 -0000      1.12
+++ data/bison.m4       18 Jan 2007 06:12:38 -0000
@@ -349,6 +349,30 @@
 [m4_define([b4_percent_define_skeleton_variables(]$1[)])dnl
 m4_ifdef([b4_percent_define(]$1[)], [m4_indir([b4_percent_define(]$1[)])])])
 
+# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
+# ------------------------------------------------------
+# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
+# IF-FALSE.  Also, record the skeleton's usage of VARIABLE by defining
+# b4_percent_define_skeleton_variables(VARIABLE).
+m4_define([b4_percent_define_ifdef],
+[m4_ifdef([b4_percent_define(]$1[)],
+         [m4_define([b4_percent_define_skeleton_variables(]$1[)])$2],
+         [$3])])
+
+# b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
+# --------------------------------------------------------
+# If the %define variable VARIABLE is defined to anything but "0" or "false",
+# expand IF-TRUE. If it is defined to "0" or "false", expand IF-FALSE.  If
+# it is undefined, raise an error (this macro should be preceded by
+# b4_percent_define_default).  Also, record the skeleton's usage of VARIABLE by
+# defining b4_percent_define_skeleton_variables(VARIABLE).
+m4_define([b4_percent_define_flag_if],
+[b4_percent_define_ifdef([$1],
+                        [m4_case(b4_percent_define_get([$1]),
+                                 [0], [$3], [false], [$3],
+                                 [$2])],
+                        [m4_fatal([invalid %define variable passed to 
b4_percent_define_flag_if: ]$1)])])
+
 # b4_percent_define_default(VARIABLE, DEFAULT)
 # --------------------------------------------
 # If the %define variable VARIABLE is undefined, set its value to DEFAULT.
@@ -364,9 +388,9 @@
 # --------------------------------
 # If any %code blocks for QUALIFIER are defined, emit them beginning with a
 # comment and ending with synclines and a newline.  If QUALIFIER is not
-# specified (thus, b4_percent_code_get is invoked without parens), do this for
-# the unqualified %code blocks.  Also, record the skeleton's usage of QUALIFIER
-# (if specified) by defining b4_percent_code_skeleton_qualifiers(QUALIFIER).
+# specified or empty, do this for the unqualified %code blocks.  Also, record
+# the skeleton's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_skeleton_qualifiers(QUALIFIER).
 #
 # For example, to emit any unqualified %code blocks followed by any %code
 # blocks for the qualifier foo:
@@ -374,9 +398,8 @@
 #   b4_percent_code_get
 #   b4_percent_code_get([[foo]])
 m4_define([b4_percent_code_get],
-[m4_pushdef([b4_macro_name], [[b4_percent_code]]m4_if([$#], [1], [[[(]$1[)]]],
-                                                      [[[_unqualified]]]))dnl
-m4_if([$#], [1], [m4_define([b4_percent_code_skeleton_qualifiers(]$1[)])])dnl
+[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
+m4_ifval([$1], [m4_define([b4_percent_code_skeleton_qualifiers(]$1[)])])dnl
 m4_ifdef(b4_macro_name,
 [b4_comment([m4_if([$#], [0], [[Unqualified %code]],
                    [[%code "]$1["]])[ blocks.]])
@@ -384,6 +407,17 @@
 ])dnl
 m4_popdef([b4_macro_name])])
 
+# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------
+# If any %code blocks for QUALIFIER (or unqualified %code blocks if
+# QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
+# Also, record the skeleton's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_skeleton_qualifiers(QUALIFIER).
+m4_define([b4_percent_code_ifdef],
+[m4_ifdef([b4_percent_code(]$1[)],
+          [m4_ifval([$1], 
[m4_define([b4_percent_code_skeleton_qualifiers(]$1[)])])$2],
+         [$3])])
+
 
 ## --------------------------------------------------------- ##
 ## After processing the skeletons, check that all the user's ##
Index: data/c++.m4
===================================================================
RCS file: /sources/bison/bison/data/c++.m4,v
retrieving revision 1.13
diff -u -r1.13 c++.m4
--- data/c++.m4 17 Jan 2007 08:36:07 -0000      1.13
+++ data/c++.m4 18 Jan 2007 06:12:38 -0000
@@ -31,6 +31,7 @@
 b4_percent_define_default([[location_type]], [[location]])
 b4_percent_define_default([[filename_type]], [[std::string]])
 b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
+b4_percent_define_default([[global_tokens_and_yystype]], [[0]])
 b4_percent_define_default([[define_location_comparison]],
                           [m4_if(b4_percent_define_get([[filename_type]]),
                                  [std::string], [[1]], [[0]])])
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.36
diff -u -r1.36 glr.cc
--- data/glr.cc 17 Jan 2007 08:36:07 -0000      1.36
+++ data/glr.cc 18 Jan 2007 06:12:38 -0000
@@ -366,7 +366,7 @@
   };
 
 ]dnl Redirections for glr.c.
-m4_ifval(b4_percent_define_get([[global_tokens_and_yystype]]),
+b4_percent_define_flag_if([[global_tokens_and_yystype]],
 [b4_token_defines(b4_tokens)])
 [
 #ifndef YYSTYPE
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.154
diff -u -r1.154 lalr1.cc
--- data/lalr1.cc       17 Jan 2007 08:36:07 -0000      1.154
+++ data/lalr1.cc       18 Jan 2007 06:12:40 -0000
@@ -290,7 +290,7 @@
   };
 }
 
-]m4_ifval(b4_percent_define_get([[global_tokens_and_yystype]]),
+]b4_percent_define_flag_if([[global_tokens_and_yystype]],
 [b4_token_defines(b4_tokens)
 
 #ifndef YYSTYPE
Index: data/location.cc
===================================================================
RCS file: /sources/bison/bison/data/location.cc,v
retrieving revision 1.17
diff -u -r1.17 location.cc
--- data/location.cc    17 Jan 2007 08:36:07 -0000      1.17
+++ data/location.cc    18 Jan 2007 06:12:41 -0000
@@ -114,7 +114,7 @@
   {
     return begin + -width;
   }
-]m4_if(b4_percent_define_get([[define_location_comparison]]), [1], [[
+]b4_percent_define_flag_if([[define_location_comparison]], [[
   /// Compare two position objects.
   inline bool
   operator== (const position& pos1, const position& pos2)
@@ -236,7 +236,7 @@
     res.columns (width);
     return res;
   }
-]m4_if(b4_percent_define_get([[define_location_comparison]]), [1], [[
+]b4_percent_define_flag_if([[define_location_comparison]], [[
   /// Compare two location objects.
   inline bool
   operator== (const location& loc1, const location& loc2)
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.116
diff -u -r1.116 parse-gram.y
--- src/parse-gram.y    17 Jan 2007 09:00:00 -0000      1.116
+++ src/parse-gram.y    18 Jan 2007 06:12:46 -0000
@@ -324,7 +324,7 @@
     }
 | "%code" braceless
     {
-      muscle_code_grow ("percent_code_unqualified", $2, @2);
+      muscle_code_grow ("percent_code()", $2, @2);
       code_scanner_last_string_free ();
     }
 | "%code" ID braceless
@@ -528,12 +528,11 @@
   | STRING { $$ = uniqstr_new ($1); } /* deprecated and not M4-friendly */
   ;
 
-/* Some content or "1" by default. */
+/* Some content or empty by default. */
 content.opt:
   /* Nothing. */
     {
-      static char one[] = "1";
-      $$ = one;
+      $$ = "";
     }
 | STRING
 ;
Index: doc/bison.texinfo
===================================================================
RCS file: /sources/bison/bison/doc/bison.texinfo,v
retrieving revision 1.219
diff -u -r1.219 bison.texinfo
--- doc/bison.texinfo   9 Jan 2007 01:17:50 -0000       1.219
+++ doc/bison.texinfo   17 Jan 2007 14:34:21 -0000
@@ -4615,6 +4625,15 @@
 @xref{Table of Symbols, ,%code}.
 @end deffn
 
address@hidden {Directive} %define @var{define-variable}
address@hidden {Directive} %define @var{define-variable} @var{value}
+Define a variable to be used by the skeleton in order to adjust its
+behavior.  The @var{value} can be omitted for boolean variables; for
+boolean variables, the skeletons will treat a @var{value} of @samp{0}
+or @samp{false} as the boolean variable being false, and anything else
+as true.
address@hidden deffn
+
 @deffn {Directive} %defines @var{defines-file}
 Same as above, but save in the file @var{defines-file}.
 @end deffn


reply via email to

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