]> git.saurik.com Git - bison.git/commitdiff
Instead of using make_symbol<TOK_FOO>, generate make_FOO for each token type.
authorAkim Demaille <demaille@gostai.com>
Thu, 4 Sep 2008 20:41:01 +0000 (22:41 +0200)
committerAkim Demaille <demaille@gostai.com>
Sat, 15 Nov 2008 09:20:02 +0000 (10:20 +0100)
Using template buys us nothing, and makes it uselessly complex to
construct a symbol.  Besides, it could not be generalized to other
languages, while make_FOO would work in C/Java etc.

* data/lalr1.cc (b4_symbol_): New.
(b4_symbol): Use it.
(b4_symbol_constructor_declaration_)
(b4_symbol_constructor_definition_): Instead of generating
specializations of an overloaded template function, just generate
several functions whose names are forged from the token names
without the token.prefix.
(b4_symbol_constructor_declarations): Generate them for all the
symbols, not just by class of symbol type, now that instead of
specializing a function template by the token, we generate a
function named after the token.
(b4_symbol_constructor_specialization_)
(b4_symbol_constructor_specializations): Remove.
* etc/bench.pl.in: Adjust to this new API.

ChangeLog
data/lalr1.cc
etc/bench.pl.in

index b73a85c520a9e921822c6f05b76f50957a9969c5..c45ded0ea77cb7636e7f99722fa088380d8eaf69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2008-11-15  Akim Demaille  <demaille@gostai.com>
+
+       Instead of using make_symbol<TOK_FOO>, generate make_FOO for each token type.
+       Using template buys us nothing, and makes it uselessly complex to
+       construct a symbol.  Besides, it could not be generalized to other
+       languages, while make_FOO would work in C/Java etc.
+       
+       * data/lalr1.cc (b4_symbol_): New.
+       (b4_symbol): Use it.
+       (b4_symbol_constructor_declaration_)
+       (b4_symbol_constructor_definition_): Instead of generating
+       specializations of an overloaded template function, just generate
+       several functions whose names are forged from the token names
+       without the token.prefix.
+       (b4_symbol_constructor_declarations): Generate them for all the
+       symbols, not just by class of symbol type, now that instead of
+       specializing a function template by the token, we generate a
+       function named after the token.
+       (b4_symbol_constructor_specialization_)
+       (b4_symbol_constructor_specializations): Remove.
+       * etc/bench.pl.in: Adjust to this new API.
+
 2008-11-13  Akim Demaille  <demaille@gostai.com>
 
        %define token.prefix.
 2008-11-13  Akim Demaille  <demaille@gostai.com>
 
        %define token.prefix.
index 851c165bea4bc290daf59227cc21fac996fcc8d1..c3678887386728d64805d2ac7217748f958a86b2 100644 (file)
@@ -143,13 +143,23 @@ m4_define([b4_rhs_location],
           [b4_rhs_data([$1], [$2]).location])
 
 
           [b4_rhs_data([$1], [$2]).location])
 
 
+# b4_symbol_(NUM, FIELD)
+# ----------------------
+# Recover a FIELD about symbol #NUM.  Thanks to m4_indir, fails if
+# undefined.
+m4_define([b4_symbol_],
+[m4_indir([b4_symbol($1, $2)])])
+
+
 # b4_symbol(NUM, FIELD)
 # ---------------------
 # Recover a FIELD about symbol #NUM.  Thanks to m4_indir, fails if
 # undefined.  If FIELD = id, prepend the prefix.
 m4_define([b4_symbol],
 # b4_symbol(NUM, FIELD)
 # ---------------------
 # Recover a FIELD about symbol #NUM.  Thanks to m4_indir, fails if
 # undefined.  If FIELD = id, prepend the prefix.
 m4_define([b4_symbol],
-[m4_if([$2], [id], [b4_percent_define_get([token.prefix])])dnl
-m4_indir([b4_symbol($1, $2)])])
+[m4_case([$2],
+         [id],    [m4_do([b4_percent_define_get([token.prefix])],
+                         [b4_symbol_([$1], [id])])],
+         [b4_symbol_($@)])])
 
 
 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
 
 
 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
@@ -205,67 +215,40 @@ m4_define([b4_type_action_],
 ])])
 
 
 ])])
 
 
-# b4_symbol_constructor_declaration_(SYMBOL-NUMBERS)
-# ----------------------------------------------------
+# b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
+# -------------------------------------------------
 # Declare the overloaded version of make_symbol for the (common) type of
 # these SYMBOL-NUMBERS.  Use at class-level.
 m4_define([b4_symbol_constructor_declaration_],
 # Declare the overloaded version of make_symbol for the (common) type of
 # these SYMBOL-NUMBERS.  Use at class-level.
 m4_define([b4_symbol_constructor_declaration_],
-[    template <token_type>
-    static inline symbol_type
-    make_symbol (b4_args(b4_symbol_if([$1], [has_type],
-                                      [const b4_symbol([$1], [type])& v]),
-                         b4_locations_if([const location_type& l])));
-
-])
-
-# b4_symbol_constructor_declarations
-# ----------------------------------
-# Declare the overloaded versions of make_symbol for all the value types.
-# Use at class-level.
-m4_define([b4_symbol_constructor_declarations],
-[b4_variant_if([
-    // Declaration of make_symbol for each value type.
-m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_type_names]))])])
-
-
-
-# b4_symbol_constructor_specialization_(SYMBOL-NUMBER)
-# ----------------------------------------------------
-# Declare the specialization of make_symbol for this each SYMBOL-NUMBER.
-# Specializations cannot be declared at class-level, this must be done
-# at namespace-level.
-m4_define([b4_symbol_constructor_specialization_],
 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[  template <>
-  inline
-  b4_parser_class_name::symbol_type
-  b4_parser_class_name::make_symbol <b4_parser_class_name::token::b4_symbol([$1], [id])> (dnl
+[    static inline
+    symbol_type
+    make_[]b4_symbol_([$1], [id]) (dnl
 b4_args(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
         b4_locations_if([const location_type& l])));
 
 ])])])
 
 b4_args(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
         b4_locations_if([const location_type& l])));
 
 ])])])
 
-# b4_symbol_constructor_specializations
-# -------------------------------------
-# Declare specializations of make_symbol.
-m4_define([b4_symbol_constructor_specializations],
+
+# b4_symbol_constructor_declarations
+# ----------------------------------
+# Declare symbol constructors for all the value types.
+# Use at class-level.
+m4_define([b4_symbol_constructor_declarations],
 [b4_variant_if([
 [b4_variant_if([
-  // Specializations of make_symbol for each symbol type.
-m4_map([b4_symbol_constructor_specialization_],
-       m4_defn([b4_symbol_numbers]))])dnl
-])
+    // Symbol constructors declarations.
+m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_symbol_numbers]))])])
 
 
 
 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
 # ------------------------------------------------
 
 
 
 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
 # ------------------------------------------------
-# Define make_symbol for this SYMBOL-NUMBER.
+# Define symbol constructor for this SYMBOL-NUMBER.
 m4_define([b4_symbol_constructor_definition_],
 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
 m4_define([b4_symbol_constructor_definition_],
 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[  template <>
-  b4_parser_class_name::symbol_type
-  b4_parser_class_name::make_symbol <b4_parser_class_name::token::b4_symbol([$1], [id])> (dnl
+[  b4_parser_class_name::symbol_type
+  b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
 b4_args(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
         b4_locations_if([const location_type& l])))
 b4_args(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
         b4_locations_if([const location_type& l])))
@@ -902,7 +885,6 @@ m4_ifdef([b4_stype],
   };
 
 ]b4_lex_symbol_if([b4_yytranslate_definition])[
   };
 
 ]b4_lex_symbol_if([b4_yytranslate_definition])[
-]b4_symbol_constructor_specializations[
 ]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
 ]b4_namespace_close[
 
 ]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
 ]b4_namespace_close[
 
index f8fca8ac714f9f7a9cda4fb63dd4e97e073846e2..7cab2ebec0381347c4cd3a8a131d5c20591fd82b 100755 (executable)
@@ -692,7 +692,7 @@ yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
   if (stage == STAGE_MAX)
     {
 #if USE_LEX_SYMBOL
   if (stage == STAGE_MAX)
     {
 #if USE_LEX_SYMBOL
-      return yy::parser::make_symbol <token::END_OF_FILE> (yy::location());
+      return yy::parser::make_END_OF_FILE (yy::location());
 #else
       *yylloc = yy::location ();
       return token::END_OF_FILE;
 #else
       *yylloc = yy::location ();
       return token::END_OF_FILE;
@@ -701,7 +701,7 @@ yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
   else if (stage % 2)
     {
 #if USE_LEX_SYMBOL
   else if (stage % 2)
     {
 #if USE_LEX_SYMBOL
-      return yy::parser::make_symbol <token::NUMBER> (stage, yy::location());
+      return yy::parser::make_NUMBER (stage, yy::location());
 #elif defined ONE_STAGE_BUILD
       yylval->build(stage);
       *yylloc = yy::location ();
 #elif defined ONE_STAGE_BUILD
       yylval->build(stage);
       *yylloc = yy::location ();
@@ -719,7 +719,7 @@ yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
   else
     {
 #if USE_LEX_SYMBOL
   else
     {
 #if USE_LEX_SYMBOL
-      return yy::parser::make_symbol <token::TEXT> ("A string.", yy::location());
+      return yy::parser::make_TEXT ("A string.", yy::location());
 #elif defined ONE_STAGE_BUILD
       yylval->build(std::string("A string."));
       *yylloc = yy::location ();
 #elif defined ONE_STAGE_BUILD
       yylval->build(std::string("A string."));
       *yylloc = yy::location ();