]> git.saurik.com Git - bison.git/commitdiff
Make it easier to move the definition of yytranslate_.
authorAkim Demaille <demaille@gostai.com>
Thu, 28 Aug 2008 11:00:26 +0000 (13:00 +0200)
committerAkim Demaille <demaille@gostai.com>
Thu, 13 Nov 2008 05:36:51 +0000 (06:36 +0100)
Forthcoming changes will make it possible to use yytranslate_
from outside the parser implementation file.

* data/lalr1.cc (b4_yytranslate_definition): New.
Use it.

ChangeLog
data/lalr1.cc

index b3e5658ce355cdfa30a8cdb7e7c97f2fac4ade6d..1c76086cae34f7558d66d20243c8e3d05e565e3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-11-13  Akim Demaille  <demaille@gostai.com>
+
+       Make it easier to move the definition of yytranslate_.
+       Forthcoming changes will make it possible to use yytranslate_
+       from outside the parser implementation file.
+       
+       * data/lalr1.cc (b4_yytranslate_definition): New.
+       Use it.
+
 2008-11-13  Akim Demaille  <demaille@gostai.com>
 
        Remove useless class specification.
index 95d984607b41ce569847b1fd2d967d97f098e112..d6a48780fd3f7d7e543624b4555a8449830e4fcb 100644 (file)
@@ -330,6 +330,35 @@ m4_map([b4_char_sizeof_], [$@])dnl
 ])])
 
 
+# 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],
            [2002, 2003, 2004, 2005, 2006, 2007, 2008])
 
@@ -635,8 +664,7 @@ m4_ifdef([b4_stype],
 #endif
 
     /// Convert a scanner token number \a t to a symbol number.
-    static inline token_number_type yytranslate_ (]b4_lex_symbol_if(
-                                                  [token_type], [int])[ t);
+    static token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
 
     /// A complete symbol, with its type.
     template <typename Exact>
@@ -1586,28 +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_ (]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_;
-  }
-
+]b4_yytranslate_definition[
 ]b4_namespace_close[
 
 ]b4_epilogue[]dnl