From: Akim Demaille Date: Thu, 28 Aug 2008 11:00:26 +0000 (+0200) Subject: Make it easier to move the definition of yytranslate_. X-Git-Tag: v2.7.90~1057 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/788355718faaaafcc78ba3b94903acb11c1a1da5 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. --- diff --git a/ChangeLog b/ChangeLog index b3e5658c..1c76086c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-13 Akim Demaille + + 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 Remove useless class specification. diff --git a/data/lalr1.cc b/data/lalr1.cc index 95d98460..d6a48780 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -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(t) <= yyeof_) + return yyeof_; + else if (static_cast (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 @@ -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(t) <= yyeof_) - return yyeof_; - else if (static_cast (t) <= user_token_number_max_) - return translate_table[t]; - else - return undef_token_; - } - +]b4_yytranslate_definition[ ]b4_namespace_close[ ]b4_epilogue[]dnl