X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/aea10ef46f726371c21e99d2bfb78c1ab891f73d..cb0b136a632415b57bb9e5042bc51dae02279774:/data/lalr1.cc diff --git a/data/lalr1.cc b/data/lalr1.cc index 01b8166a..8256e0d1 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -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 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]))); ]) @@ -230,9 +230,10 @@ m4_define([b4_symbol_constructor_specialization_], inline b4_parser_class_name::symbol_type b4_parser_class_name::make_symbol (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_args(b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))); + ])])]) # b4_symbol_constructor_specializations @@ -255,23 +256,98 @@ m4_define([b4_symbol_constructor_definition_], [ template <> b4_parser_class_name::symbol_type b4_parser_class_name::make_symbol (dnl -b4_args(b4_symbol_if([$1], [has_type_name], - [const b4_symbol([$1], [type_name])& v]), +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], [id]))], - b4_symbol_if([$1], [has_type_name], [v]), + b4_symbol_if([$1], [has_type], [v]), b4_locations_if([l]))); } ])])]) -# b4_symbol_constructor_declarations +# b4_symbol_constructor_definitions # ---------------------------------- # Define the overloaded versions of make_symbol for all the value types. m4_define([b4_symbol_constructor_definitions], -[b4_variant_if( +[[ // symbol_base_type. + template + ]b4_parser_class_name[::symbol_base_type::symbol_base_type () + : value()]b4_locations_if([ + , location()])[ + { + }]b4_locations_if([[ + + template + ]b4_parser_class_name[::symbol_base_type::symbol_base_type (const location_type& l) + : value() + , location(l) + { + }]])[ + + template + ]b4_parser_class_name[::symbol_base_type::symbol_base_type (]b4_args( + [const semantic_type& v], + b4_locations_if([const location_type& l]))[) + : value(v)]b4_locations_if([ + , location(l)])[ + { + } + + template + const Exact& + ]b4_parser_class_name[::symbol_base_type::self () const + { + return static_cast(*this); + } + + template + Exact& + ]b4_parser_class_name[::symbol_base_type::self () + { + return static_cast(*this); + } + + template + int + ]b4_parser_class_name[::symbol_base_type::type_get () const + { + return self ().type_get_ (); + } + + // symbol_type. + ]b4_parser_class_name[::symbol_type::symbol_type () + : super_type () + , type () + { + } + + ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( + [int t], + b4_locations_if([const location_type& l]))[) + : super_type (]b4_locations_if([l])[) + , type (t) + { + } + + ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( + [int t], + [const semantic_type& v], + b4_locations_if([const location_type& l]))[) + : super_type (v]b4_locations_if([, l])[) + , type (t) + { + } + + int + ]b4_parser_class_name[::symbol_type::type_get_ () const + { + return type; + } + +]b4_variant_if( [ // Implementation of make_symbol for each symbol type. m4_map([b4_symbol_constructor_definition_], m4_defn([b4_symbol_numbers]))])]) @@ -307,7 +383,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 +398,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], +[[ // Symbol number corresponding to token number t. + ]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], @@ -510,8 +622,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 semantic_type;], @@ -616,7 +727,8 @@ m4_ifdef([b4_stype], #if YYDEBUG /// For each rule, its source line number. static const ]b4_int_type_for([b4_rline])[ yyrline_[]; - /// For each scanner token number, its symbol number. + /// (External) token number corresponding to the (internal) symbol + /// number (which must be that of a token). static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; /// Report on the debug stream that the rule \a r is going to be reduced. virtual void yy_reduce_print_ (int r); @@ -629,7 +741,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 inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t); /// A complete symbol, with its type. template @@ -763,7 +875,10 @@ m4_ifdef([b4_stype], ]b4_parse_param_vars[ }; + +]b4_lex_symbol_if([b4_yytranslate_definition])[ ]b4_symbol_constructor_specializations[ +]b4_lex_symbol_if([b4_symbol_constructor_definitions])[ ]b4_namespace_close[ ]b4_percent_define_flag_if([[global_tokens_and_yystype]], @@ -913,82 +1028,7 @@ b4_percent_code_get[]dnl | Symbol types. | `---------------*/ - // symbol_base_type. - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type () - : value()]b4_locations_if([ - , location()])[ - { - }]b4_locations_if([[ - - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (const location_type& l) - : value() - , location(l) - { - }]])[ - - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (]b4_args( - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : value(v)]b4_locations_if([ - , location(l)])[ - { - } - - template - const Exact& - ]b4_parser_class_name[::symbol_base_type::self () const - { - return static_cast(*this); - } - - template - Exact& - ]b4_parser_class_name[::symbol_base_type::self () - { - return static_cast(*this); - } - - template - int - ]b4_parser_class_name[::symbol_base_type::type_get () const - { - return self ().type_get_ (); - } - - // symbol_type. - ]b4_parser_class_name[::symbol_type::symbol_type () - : super_type () - , type () - { - } - - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( - [int t], - b4_locations_if([const location_type& l]))[) - : super_type (]b4_locations_if([l])[) - , type (t) - { - } - - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( - [int t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : super_type (v]b4_locations_if([, l])[) - , type (t) - { - } - - int - ]b4_parser_class_name[::symbol_type::type_get_ () const - { - return type; - } - -]b4_symbol_constructor_definitions[ +]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[ // stack_symbol_type. ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type () @@ -1191,7 +1231,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 @@ -1524,8 +1565,8 @@ b4_error_verbose_if([int yystate, int yytoken], ]b4_table_define([stos], [b4_stos])[; #if YYDEBUG - /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding - to YYLEX-NUM. */ + /* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ ]b4_table_define([token_number], [b4_toknum])[; #endif @@ -1578,27 +1619,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 (t) <= user_token_number_max_) - return translate_table[t]; - else - return undef_token_; - } - +]b4_lex_symbol_if([], [b4_yytranslate_definition])[ ]b4_namespace_close[ ]b4_epilogue[]dnl