bison-patches
[Top][All Lists]
Advanced

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

[PATCH] overquoting in implementation of %code and %defines


From: Paolo Bonzini
Subject: [PATCH] overquoting in implementation of %code and %defines
Date: Tue, 09 Jan 2007 16:39:15 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)

The definitions in %code and %defines are overquoted. It is useless to specify "[[namespace]]", for example. I tested manually that crazy %code qualifiers like "m4_ifdef" or "m4_format" are warned properly (m4_format is recognized even without parameters), but putting it into the testsuite causes autotest to barf about an unexpanded m4 macro in the output.

In addition, the check for bad qualifiers can be simplified by using internal macro names like STEM(name) for each skeleton-tested name, and then using "m4_ifdef" instead of nesting two m4_foreach loops.

Finally, I added an argument to b4_get_percent_define which is the default value of the %define. I found it valuable in the conversion of the Java skeleton to the new system.

Ok?

Paolo
2007-01-09  Paolo Bonzini  <address@hidden>

        * data/bison.m4 (b4_check_user_names): Check for special "STEM(name)"
        macros instead of using two nested m4_foreach loops.
        (b4_get_percent_code): Adjust.
        (b4_get_percent_define): Adjust.  Add a second argument for the
        default value of the %define.
        (b4_check_user_names_wrap): Define outside the m4_wrap.
        * data/glr.c: Don't overquote b4_get_percent_code and
        b4_get_percent_define.
        * data/glr.cc: Likewise.
        * data/lalr1.cc: Likewise.
        * data/location.cc: Likewise.
        * data/push.c: Likewise.
        * data/yacc.c: Likewise.

Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.11
diff -u -r1.11 bison.m4
--- bison.m4    9 Jan 2007 05:24:11 -0000       1.11
+++ bison.m4    9 Jan 2007 15:10:30 -0000
@@ -285,10 +285,10 @@
 b4_define_user_code([stype])
 
 
-# b4_check_user_names(WHAT, USER-LIST, SKELETON-LIST)
+# b4_check_user_names(WHAT, USER-LIST, SKELETON-STEM)
 # ---------------------------------------------------
 # Warn if any name of type WHAT is used by the user (as recorded in USER-LIST)
-# but is not used by the skeleton (as recorded in SKELETON-LIST).
+# but is not used by the skeleton (as recorded in SKELETON-STEM).
 #
 # USER-LIST must expand to a list specifying all grammar occurrences of all
 # names of type WHAT.   Each item in the list is a triplet specifying one
@@ -303,16 +303,9 @@
 #               [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
 #               [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
 #
-# SKELETON-LIST must expand to a list specifying all names of type WHAT that
-# are used by the skeleton.  Multiple occurrences of the same name are fine.
-# Empty string names are fine, but it would be ugly for a Bison skeleton to
-# actually use one.  An empty list is fine.
-#
-# For example, to define b4_skeleton_foo_names to be used for SKELETON-LIST
-# with two names and with correct quoting:
-#
-#   m4_define([b4_skeleton_foo_names],
-#             [[[[bar]], [[baz]]]])
+# SKELETON-STEM is the stem of macros identifying names of type WHAT that
+# are used by the skeleton.  If "bar" is used, for example, a macro
+# SKELETON-STEM(bar) would be defined.
 #
 # To invoke b4_check_user_names with TYPE foo, with USER-LIST
 # b4_user_foo_names, with SKELETON-LIST b4_skeleton_foo_names, and with correct
@@ -325,28 +318,22 @@
 m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
 m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
 m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
-m4_pushdef([b4_found], [[0]])dnl
-m4_foreach([b4_skeleton_name], $3,
-           [m4_if(m4_quote(b4_user_name),
-                  m4_quote(b4_skeleton_name),
-                  [m4_define([b4_found], [[1]])])])dnl
-m4_if(b4_found, [0], [b4_warn_at([b4_start], [b4_end],
-                                 [[%s `%s' is not used]],
-                                 [$1], [b4_user_name])])[]dnl
-m4_popdef([b4_found])dnl
+m4_ifdef($3(b4_user_name), [],
+        [b4_warn_at([b4_start], [b4_end],
+                     [[%s `%s' is not used]], [$1], [b4_user_name])])[]dnl
 m4_popdef([b4_occurrence])dnl
 m4_popdef([b4_user_name])dnl
 m4_popdef([b4_start])dnl
 m4_popdef([b4_end])dnl
 ])])
 
-# b4_get_percent_define(VARIABLE)
-# --------------------------------
+# b4_get_percent_define(VARIABLE, DEFAULT)
+# ----------------------------------------
 # If the %define variable VARIABLE is defined, emit it.  Also, record VARIABLE
-# in b4_skeleton_percent_define_variables.
+# in b4_skeleton_percent_define_variables(VARIABLE).
 m4_define([b4_get_percent_define],
-[m4_append([b4_skeleton_percent_define_variables], [[$1]], [[, ]])dnl
-m4_ifdef([b4_percent_define_]$1, [b4_percent_define_]$1)])
+[m4_define([b4_skeleton_percent_define_variables($1)])dnl
+m4_ifdef([b4_percent_define_]$1, [b4_percent_define_$1], [$2])])
 
 # b4_get_percent_code([QUALIFIER])
 # --------------------------------
@@ -354,14 +341,14 @@
 # comment and ending with synclines and a newline.  If QUALIFIER is not
 # specified (thus, b4_get_percent_code is invoked without parens), do this for
 # the unqualified %code blocks.  Also, record QUALIFIER (if specified) in
-# b4_skeleton_percent_code_qualifiers.
+# b4_skeleton_percent_code_qualifiers(QUALIFIER).
 m4_define([b4_get_percent_code],
-[m4_pushdef([b4_macro_name], [[b4_percent_code]]m4_if([$#], [1], [[[_]$1]]))dnl
+[m4_pushdef([b4_macro_name], [[b4_percent_code]]m4_if([$#], [1], [[[_$1]]]))dnl
 m4_if([$#], [1],
-      [m4_append([b4_skeleton_percent_code_qualifiers], [[$1]], [[, ]])])dnl
+      [m4_define([b4_skeleton_percent_code_qualifiers($1)], [])])dnl
 m4_ifdef(b4_macro_name,
 [b4_comment([m4_if([$#], [0], [[Unqualified %code]],
-                   [[%code "]$1["]])[ blocks.]])
+                   [[%code "$1"]])[ blocks.]])
 b4_user_code(b4_macro_name)])dnl
 m4_popdef([b4_macro_name])])
 
@@ -371,8 +358,7 @@
 ## %define variables and %code qualifiers were used.         ##
 ## --------------------------------------------------------- ##
 
-m4_wrap([
-m4_pushdef([b4_check_user_names_wrap],
+m4_define([b4_check_user_names_wrap],
 [m4_ifdef([b4_skeleton_percent_$1],
           [m4_define([b4_skeleton_percent_$1],
                      m4_dquote(m4_dquote(b4_skeleton_percent_$1)))],
@@ -381,11 +367,10 @@
 m4_ifdef([b4_user_percent_$1],
          [b4_check_user_names([$2],
                               [b4_user_percent_$1],
-                              [b4_skeleton_percent_$1])])
+                              [[b4_skeleton_percent_$1]])])
 ])
 
+m4_wrap([
 b4_check_user_names_wrap([define_variables], [[%define variable]])
 b4_check_user_names_wrap([code_qualifiers], [[%code qualifier]])
-
-m4_popdef([b4_check_user_names_wrap])
 ])
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.199
diff -u -r1.199 glr.c
--- glr.c       9 Jan 2007 05:24:11 -0000       1.199
+++ glr.c       9 Jan 2007 15:10:34 -0000
@@ -153,7 +153,7 @@
 
 ]b4_identification
 
-b4_get_percent_code([[top]])[]dnl
+b4_get_percent_code([top])[]dnl
 m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
@@ -173,7 +173,7 @@
 dnl # Declaration that might either go into the header (if --defines)
 dnl # or open coded in the parser body.
 m4_define([b4_shared_declarations],
-[b4_get_percent_code([[requires]])[]dnl
+[b4_get_percent_code([requires])[]dnl
 
 b4_token_enums(b4_tokens)
 
@@ -205,7 +205,7 @@
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
-]b4_get_percent_code([[provides]])[]dnl
+]b4_get_percent_code([provides])[]dnl
 ])
 
 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.34
diff -u -r1.34 glr.cc
--- glr.cc      9 Jan 2007 05:24:11 -0000       1.34
+++ glr.cc      9 Jan 2007 15:10:34 -0000
@@ -58,9 +58,9 @@
 m4_include(b4_pkgdatadir/[location.cc])
 
 m4_define([b4_parser_class_name],
-          [b4_get_percent_define([[parser_class_name]])])
+          [b4_get_percent_define([parser_class_name])])
 m4_define([b4_namespace],
-          [b4_get_percent_define([[namespace]])])
+          [b4_get_percent_define([namespace])])
 
 # Save the parse parameters.
 m4_define([b4_parse_param_orig], m4_defn([b4_parse_param]))
@@ -230,7 +230,7 @@
 #ifndef PARSER_HEADER_H
 # define PARSER_HEADER_H
 
-]b4_get_percent_code([[requires]])[
+]b4_get_percent_code([requires])[
 
 #include <string>
 #include <iostream>
@@ -290,7 +290,7 @@
     typedef YYSTYPE semantic_type;
 #endif
     /// Symbol locations.
-    typedef ]b4_get_percent_define([[location_type]])[ location_type;
+    typedef ]b4_get_percent_define([location_type])[ location_type;
     /// Tokens.
     struct token
     {
@@ -365,7 +365,7 @@
   };
 
 ]dnl Redirections for glr.c.
-m4_ifval(b4_get_percent_define([[global_tokens_and_yystype]]),
+m4_ifval(b4_get_percent_define([global_tokens_and_yystype]),
 [b4_token_defines(b4_tokens)])
 [
 #ifndef YYSTYPE
@@ -377,7 +377,7 @@
 
 }
 
-]b4_get_percent_code([[provides]])[]dnl
+]b4_get_percent_code([provides])[]dnl
 
 [#endif /* ! defined PARSER_HEADER_H */]
 m4_divert_pop(0)
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.151
diff -u -r1.151 lalr1.cc
--- lalr1.cc    9 Jan 2007 05:24:11 -0000       1.151
+++ lalr1.cc    9 Jan 2007 15:10:35 -0000
@@ -20,9 +20,9 @@
 m4_include(b4_pkgdatadir/[c++.m4])
 
 m4_define([b4_parser_class_name],
-          [b4_get_percent_define([[parser_class_name]])])
+          [b4_get_percent_define([parser_class_name])])
 m4_define([b4_namespace],
-          [b4_get_percent_define([[namespace]])])
+          [b4_get_percent_define([namespace])])
 
 # The header is mandatory.
 b4_defines_if([],
@@ -46,7 +46,7 @@
 #ifndef PARSER_HEADER_H
 # define PARSER_HEADER_H
 
-]b4_get_percent_code([[requires]])[
+]b4_get_percent_code([requires])[
 
 #include <string>
 #include <iostream>
@@ -118,7 +118,7 @@
     typedef YYSTYPE semantic_type;
 #endif
     /// Symbol locations.
-    typedef ]b4_get_percent_define([[location_type]])[ location_type;
+    typedef ]b4_get_percent_define([location_type])[ location_type;
     /// Tokens.
     struct token
     {
@@ -289,7 +289,7 @@
   };
 }
 
-]m4_ifval(b4_get_percent_define([[global_tokens_and_yystype]]),
+]m4_ifval(b4_get_percent_define([global_tokens_and_yystype]),
 [b4_token_defines(b4_tokens)
 
 #ifndef YYSTYPE
@@ -297,14 +297,14 @@
 # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
 ])
-b4_get_percent_code([[provides]])[]dnl
+b4_get_percent_code([provides])[]dnl
 
 [#endif /* ! defined PARSER_HEADER_H */]
 ])dnl
 @output(b4_parser_file_name@)
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
-b4_get_percent_code([[top]])[]dnl
+b4_get_percent_code([top])[]dnl
 m4_if(b4_prefix, [yy], [],
 [
 // Take the name prefix into account.
Index: data/location.cc
===================================================================
RCS file: /sources/bison/bison/data/location.cc,v
retrieving revision 1.15
diff -u -r1.15 location.cc
--- location.cc 8 Jan 2007 21:38:29 -0000       1.15
+++ location.cc 9 Jan 2007 15:10:37 -0000
@@ -26,7 +26,7 @@
 
 /**
  ** \file position.hh
- ** Define the ]b4_get_percent_define([[namespace]])[::position class.
+ ** Define the ]b4_get_percent_define([namespace])[::position class.
  */
 
 #ifndef BISON_POSITION_HH
@@ -36,7 +36,7 @@
 # include <string>
 # include <algorithm>
 
-namespace ]b4_get_percent_define([[namespace]])[
+namespace ]b4_get_percent_define([namespace])[
 {
   /// Abstract a position.
   class position
@@ -51,7 +51,7 @@
 
 ])[
     /// Initialization.
-    inline void initialize (]b4_get_percent_define([[filename_type]])[* fn)
+    inline void initialize (]b4_get_percent_define([filename_type])[* fn)
     {
       filename = fn;
       line = ]b4_location_initial_line[;
@@ -77,7 +77,7 @@
 
   public:
     /// File name to which this position refers.
-    ]b4_get_percent_define([[filename_type]])[* filename;
+    ]b4_get_percent_define([filename_type])[* filename;
     /// Current line number.
     unsigned int line;
     /// Current column number.
@@ -113,7 +113,7 @@
   {
     return begin + -width;
   }
-]m4_if(b4_get_percent_define([[define_location_comparison]]), [1], [[
+]m4_if(b4_get_percent_define([define_location_comparison]), [1], [[
   /// Compare two position objects.
   inline bool
   operator== (const position& pos1, const position& pos2)
@@ -151,7 +151,7 @@
 
 /**
  ** \file location.hh
- ** Define the ]b4_get_percent_define([[namespace]])[::location class.
+ ** Define the ]b4_get_percent_define([namespace])[::location class.
  */
 
 #ifndef BISON_LOCATION_HH
@@ -161,7 +161,7 @@
 # include <string>
 # include "position.hh"
 
-namespace ]b4_get_percent_define([[namespace]])[
+namespace ]b4_get_percent_define([namespace])[
 {
 
   /// Abstract a location.
@@ -177,7 +177,7 @@
 
 ])[
     /// Initialization.
-    inline void initialize (]b4_get_percent_define([[filename_type]])[* fn)
+    inline void initialize (]b4_get_percent_define([filename_type])[* fn)
     {
       begin.initialize (fn);
       end = begin;
@@ -235,7 +235,7 @@
     res.columns (width);
     return res;
   }
-]m4_if(b4_get_percent_define([[define_location_comparison]]), [1], [[
+]m4_if(b4_get_percent_define([define_location_comparison]), [1], [[
   /// Compare two location objects.
   inline bool
   operator== (const location& loc1, const location& loc2)
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.34
diff -u -r1.34 push.c
--- push.c      9 Jan 2007 05:24:11 -0000       1.34
+++ push.c      9 Jan 2007 15:10:40 -0000
@@ -160,7 +160,7 @@
    USER NAME SPACE" below.  */
 
 ]b4_identification
-b4_get_percent_code([[top]])[]dnl
+b4_get_percent_code([top])[]dnl
 m4_if(b4_prefix, [yy], [],
 [[/* Substitute the variable and function names.  */
 ]b4_pull_if([[#define yyparse         ]b4_prefix[parse
@@ -198,7 +198,7 @@
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-]b4_get_percent_code([[requires]])[]dnl
+]b4_get_percent_code([requires])[]dnl
 
 b4_token_enums_defines(b4_tokens)[
 
@@ -250,7 +250,7 @@
                    [[[yypstate *yyps]], [[yyps]]])[
 #endif
 ]])
-b4_get_percent_code([[provides]])[]dnl
+b4_get_percent_code([provides])[]dnl
 
 [/* Copy the second part of user declarations.  */
 ]b4_user_post_prologue
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.162
diff -u -r1.162 yacc.c
--- yacc.c      9 Jan 2007 05:24:11 -0000       1.162
+++ yacc.c      9 Jan 2007 15:10:41 -0000
@@ -152,7 +152,7 @@
    USER NAME SPACE" below.  */
 
 ]b4_identification
-b4_get_percent_code([[top]])[]dnl
+b4_get_percent_code([top])[]dnl
 m4_if(b4_prefix, [yy], [],
 [/* Substitute the variable and function names.  */
 #define yyparse b4_prefix[]parse
@@ -185,7 +185,7 @@
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
-]b4_get_percent_code([[requires]])[]dnl
+]b4_get_percent_code([requires])[]dnl
 
 b4_token_enums_defines(b4_tokens)[
 
@@ -216,7 +216,7 @@
 # define YYLTYPE_IS_TRIVIAL 1
 #endif])
 
-b4_get_percent_code([[provides]])[]dnl
+b4_get_percent_code([provides])[]dnl
 
 [/* Copy the second part of user declarations.  */
 ]b4_user_post_prologue
@@ -1491,7 +1491,7 @@
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
 
-b4_get_percent_code([[requires]])[]dnl
+b4_get_percent_code([requires])[]dnl
 
 b4_token_enums_defines(b4_tokens)
 
@@ -1530,7 +1530,7 @@
           [extern YYLTYPE b4_prefix[]lloc;])
 )dnl b4_locations_if
 
-b4_get_percent_code([[provides]])
+b4_get_percent_code([provides])
 ])dnl b4_defines_if
 m4_divert_pop(0)
 

reply via email to

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