]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
Make it easier to move the definition of yytranslate_.
[bison.git] / data / lalr1.cc
index fd5e5ec8cc25e598faae584df6b945396344ab54..d6a48780fd3f7d7e543624b4555a8449830e4fcb 100644 (file)
@@ -185,11 +185,11 @@ m4_define([b4_symbol_case_],
 # Run actions for the symbol NUMS that all have the same type-name.
 # Skip NUMS that have no type-name.
 m4_define([b4_type_action_],
-[b4_symbol_if([$1], [has_type_name],
+[b4_symbol_if([$1], [has_type],
 [m4_map([b4_symbol_case_], [$@])[]dnl
         b4_dollar_dollar([b4_symbol([$1], [number])],
                          [b4_symbol([$1], [tag])],
-                         [b4_symbol([$1], [type_name])]);
+                         [b4_symbol([$1], [type])]);
        break;
 
 ])])
@@ -202,8 +202,8 @@ m4_define([b4_type_action_],
 m4_define([b4_symbol_constructor_declaration_],
 [    template <token_type>
     static inline symbol_type
-    make_symbol (b4_args(b4_symbol_if([$1], [has_type_name],
-                                      [const b4_symbol([$1], [type_name])& v]),
+    make_symbol (b4_args(b4_symbol_if([$1], [has_type],
+                                      [const b4_symbol([$1], [type])& v]),
                          b4_locations_if([const location_type& l])));
 
 ])
@@ -225,14 +225,14 @@ m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_type_names]))])])
 # 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], [tag_is_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], [tag])> (dnl
-b4_args(b4_symbol_if([$1], [has_type_name],
-                     [const b4_symbol([$1], [type_name])& v]),
-        b4_locations_if([const b4_parser_class_name::location_type& l])));
+  b4_parser_class_name::make_symbol <b4_parser_class_name::token::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_symbol_constructor_specializations
@@ -251,16 +251,16 @@ m4_map([b4_symbol_constructor_specialization_],
 # ------------------------------------------------
 # Define make_symbol for this SYMBOL-NUMBER.
 m4_define([b4_symbol_constructor_definition_],
-[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [tag_is_id],
+[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], [tag])> (dnl
-b4_args(b4_symbol_if([$1], [has_type_name],
-                     [const b4_symbol([$1], [type_name])& v]),
+  b4_parser_class_name::make_symbol <b4_parser_class_name::token::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])))
   {
-    return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [tag]))],
-                                b4_symbol_if([$1], [has_type_name], [v]),
+    return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
+                                b4_symbol_if([$1], [has_type], [v]),
                                 b4_locations_if([l])));
   }
 
@@ -307,7 +307,14 @@ m4_define([_b4_char_sizeof_dummy],
 dummy[]_b4_char_sizeof_counter])
 
 
-# b4_char_sizeof(SYMBOL-NUM)
+# b4_char_sizeof_(SYMBOL-NUM)
+# ---------------------------
+# A comment describing this symbol.
+m4_define([b4_char_sizeof_],
+[      // b4_symbol([$1], [tag])
+])
+
+# b4_char_sizeof(SYMBOL-NUMS)
 # --------------------------
 # To be mapped on the list of type names to produce:
 #
@@ -315,12 +322,41 @@ dummy[]_b4_char_sizeof_counter])
 #    char dummy2[sizeof(type_name_2)];
 #
 # for defined type names.
-# $3 is doubly-quoted, do not quote it again.
 m4_define([b4_char_sizeof],
-[m4_ifval(b4_symbol([$1], [type_name]),
+[b4_symbol_if([$1], [has_type],
 [
-      char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type_name])])@}; // b4_symbol([$1], [tag])])dnl
-])
+m4_map([b4_char_sizeof_], [$@])dnl
+      char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type])])@};
+])])
+
+
+# b4_yytranslate_definition
+# -------------------------
+# Define yytranslate_.  Sometimes we want it in the header file,
+# sometimes the cc file suffices.
+m4_define([b4_yytranslate_definition],
+[[  // YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.
+  ]b4_parser_class_name[::token_number_type
+  ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
+                                                          [int])[ t)
+  {
+    static
+    const token_number_type
+    translate_table[] =
+    {
+]b4_translate[
+    };
+    const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
+    const token_number_type undef_token_ = ]b4_undef_token_number[;
+
+    if (static_cast<int>(t) <= yyeof_)
+      return yyeof_;
+    else if (static_cast<unsigned int> (t) <= user_token_number_max_)
+      return translate_table[t];
+    else
+      return undef_token_;
+  }
+]])
 
 
 m4_pushdef([b4_copyright_years],
@@ -510,8 +546,7 @@ do {                                                            \
 ]b4_variant_if(
 [    /// An auxiliary type to compute the largest semantic type.
     union union_type
-    {]m4_map([b4_char_sizeof], m4_defn([b4_symbol_numbers]))[
-    };
+    {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[};
 
     /// Symbol semantic values.
     typedef variant<sizeof(union_type)> semantic_type;],
@@ -629,7 +664,7 @@ m4_ifdef([b4_stype],
 #endif
 
     /// Convert a scanner token number \a t to a symbol number.
-    static inline token_number_type yytranslate_ (int t);
+    static token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
 
     /// A complete symbol, with its type.
     template <typename Exact>
@@ -1191,7 +1226,8 @@ m4_popdef([b4_at_dollar])])dnl
       {
         YYCDEBUG << "Reading a token: ";
 ]b4_lex_symbol_if(
-[        yyla = yylex();],
+[        yyla = b4_c_function_call([yylex], [symbol_type],
+                                   m4_ifdef([b4_lex_param], b4_lex_param));],
 [        yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
                                     [[YYSTYPE*], [&yyla.value]][]dnl
 b4_locations_if([, [[location*], [&yyla.location]]])dnl
@@ -1578,27 +1614,7 @@ b4_error_verbose_if([int yystate, int yytoken],
   }
 #endif // YYDEBUG
 
-  /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
-  ]b4_parser_class_name[::token_number_type
-  ]b4_parser_class_name[::yytranslate_ (int t)
-  {
-    static
-    const token_number_type
-    translate_table[] =
-    {
-]b4_translate[
-    };
-    const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
-    const token_number_type undef_token_ = ]b4_undef_token_number[;
-
-    if (t <= yyeof_)
-      return yyeof_;
-    else if (static_cast<unsigned int> (t) <= user_token_number_max_)
-      return translate_table[t];
-    else
-      return undef_token_;
-  }
-
+]b4_yytranslate_definition[
 ]b4_namespace_close[
 
 ]b4_epilogue[]dnl