diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index e0f4dacb..3dca87c2 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -238,11 +238,11 @@ m4_define([b4_public_types_declare], ]]) -# b4_symbol_type_declare -# ---------------------- +# b4_symbol_type_define +# --------------------- # Define symbol_type, the external type for symbols used for symbol # constructors. -m4_define([b4_symbol_type_declare], +m4_define([b4_symbol_type_define], [[ /// A complete symbol. /// /// Expects its Base type to provide access to the symbol type @@ -267,7 +267,7 @@ m4_define([b4_symbol_type_declare], basic_symbol (const basic_symbol& that);]b4_variant_if([[ /// Constructor for valueless symbols, and symbols from each type. -]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[ +]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ /// Constructor for valueless symbols. basic_symbol (typename Base::kind_type t]b4_locations_if([, YY_MOVE_REF (location_type) l])[); @@ -351,7 +351,7 @@ m4_define([b4_symbol_type_declare], symbol_type () {}; /// Constructor for valueless symbols, and symbols from each type. -]b4_type_foreach([_b4_token_constructor_declare])dnl +]b4_type_foreach([_b4_token_constructor_define])dnl ])[}; ]]) @@ -394,9 +394,7 @@ m4_define([b4_public_types_define], [YY_MOVE (that.value)]) ])[} -]b4_variant_if([[ - // Implementation of basic_symbol constructor for each type. -]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ +]b4_variant_if([], [[ /// Constructor for valueless symbols. template ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( @@ -517,16 +515,13 @@ m4_define([b4_public_types_define], return token_type (yytoken_number_[type]); } ]])[]dnl - -b4_token_constructor_define]) +]) -# b4_token_constructor_declare # b4_tolen_constructor_define # ---------------------------- -# Declare/define symbol constructors for all the value types. +# Define symbol constructors for all the value types. # Use at class-level. Redefined in variant.hh. -m4_define([b4_token_constructor_declare], []) m4_define([b4_token_constructor_define], []) diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index 977b4b23..2d82172e 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -180,7 +180,7 @@ m4_define([b4_shared_declarations], { public: ]b4_public_types_declare[ -]b4_symbol_type_declare[ +]b4_symbol_type_define[ /// Build a parser object. ]b4_parser_class_name[ (]b4_parse_param_decl[); virtual ~]b4_parser_class_name[ (); @@ -215,7 +215,7 @@ m4_define([b4_shared_declarations], /// Report a syntax error. void error (const syntax_error& err); -]b4_token_constructor_declare[ +]b4_token_constructor_define[ private: /// This class is not copyable. diff --git a/data/skeletons/variant.hh b/data/skeletons/variant.hh index c613f597..6c681e6e 100644 --- a/data/skeletons/variant.hh +++ b/data/skeletons/variant.hh @@ -87,7 +87,7 @@ m4_define([b4_variant_includes], # b4_value_type_declare # --------------------- -# Declare semantic_type. +# Define semantic_type. m4_define([b4_value_type_declare], [[ /// A buffer to store and retrieve objects. /// @@ -345,49 +345,78 @@ m4_define([_b4_includes_tokens], [m4_map([_b4_is_token], [$@])]) -# _b4_token_maker_declare(SYMBOL-NUM) -# ----------------------------------- +# _b4_token_maker_define(SYMBOL-NUM) +# ---------------------------------- # Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. -m4_define([_b4_token_maker_declare], +m4_define([_b4_token_maker_define], [b4_token_visible_if([$1], [#if 201103L <= YY_CPLUSPLUS - static - symbol_type - make_[]_b4_symbol([$1], [id]) (b4_join( - b4_symbol_if([$1], [has_type], - [b4_symbol([$1], [type]) v]), - b4_locations_if([location_type l]))); + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))); + } #else - static - symbol_type - make_[]_b4_symbol([$1], [id]) (b4_join( - b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))); + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))); + } #endif ])]) -# _b4_token_constructor_declare(SYMBOL-NUM...) -# -------------------------------------------- -# Declare a unique make_symbol for all the SYMBOL-NUM (they +m4_define([_b4_type_clause], +[b4_symbol_if([$1], [is_token], + [b4_symbol_if([$1], [has_id], + [tok == token::b4_symbol([$1], [id])], + [tok == b4_symbol([$1], [user_number])])])]) + + +# _b4_token_constructor_define(SYMBOL-NUM...) +# ------------------------------------------- +# Define a unique make_symbol for all the SYMBOL-NUM (they # have the same type). Use at class-level. -m4_define([_b4_token_constructor_declare], +m4_define([_b4_token_constructor_define], [m4_ifval(_b4_includes_tokens($@), -[#if 201103L <= YY_CPLUSPLUS - symbol_type (b4_join( - [int tok], - b4_symbol_if([$1], [has_type], - [b4_symbol([$1], [type]) v]), - b4_locations_if([location_type l]))); +[[#if 201103L <= YY_CPLUSPLUS + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))[) + : super_type(]b4_join([token_type (tok)], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))[) + { + YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + } #else - symbol_type (b4_join( - [int tok], - b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))); + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : super_type(]b4_join([token_type (tok)], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))[) + { + YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + } #endif -])]) +]])]) # b4_token_constructor_declare @@ -399,123 +428,28 @@ b4_symbol_foreach([_b4_token_maker_declare])]) -# _b4_token_maker_define(SYMBOL-NUM) -# ---------------------------------- -# Define make_SYMBOL for SYMBOL-NUM. -m4_define([_b4_token_maker_define], -[b4_token_visible_if([$1], -[#if 201103L <= YY_CPLUSPLUS - inline - b4_parser_class_name::symbol_type - b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (b4_join( - b4_symbol_if([$1], [has_type], - [b4_symbol([$1], [type]) v]), - b4_locations_if([location_type l]))) - { - return symbol_type (b4_join([token::b4_symbol([$1], [id])], - b4_symbol_if([$1], [has_type], [std::move (v)]), - b4_locations_if([std::move (l)]))); - } -#else - inline - b4_parser_class_name::symbol_type - b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (b4_join( - b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))) - { - return symbol_type (b4_join([token::b4_symbol([$1], [id])], - b4_symbol_if([$1], [has_type], [v]), - b4_locations_if([l]))); - } -#endif -])]) - - -# _b4_token_constructor_define(SYMBOL-NUM...) -# ------------------------------------------- -# Declare a unique make_symbol for all the SYMBOL-NUM (they -# have the same type). Use at class-level. -m4_define([_b4_type_clause], -[b4_symbol_if([$1], [is_token], - [b4_symbol_if([$1], [has_id], - [tok == token::b4_symbol([$1], [id])], - [tok == b4_symbol([$1], [user_number])])])]) - -m4_define([_b4_token_constructor_define], -[m4_ifval(_b4_includes_tokens($@), -[[#if 201103L <= YY_CPLUSPLUS - inline - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_join( - [int tok], - b4_symbol_if([$1], [has_type], - [b4_symbol([$1], [type]) v]), - b4_locations_if([location_type l]))[) - : super_type(]b4_join([token_type (tok)], - b4_symbol_if([$1], [has_type], [std::move (v)]), - b4_locations_if([std::move (l)]))[) - { - YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); - } -#else - inline - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_join( - [int tok], - b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))[) - : super_type(]b4_join([token_type (tok)], - b4_symbol_if([$1], [has_type], [v]), - b4_locations_if([l]))[) - { - YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); - } -#endif -]])]) - - -# b4_basic_symbol_constructor_declare(SYMBOL-NUM) -# ----------------------------------------------- -# Generate a constructor declaration for basic_symbol from given type. -m4_define([b4_basic_symbol_constructor_declare], -[[#if 201103L <= YY_CPLUSPLUS - basic_symbol (]b4_join( - [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), - b4_locations_if([location_type&& l]))[); -#else - basic_symbol (]b4_join( - [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))[); -#endif -]]) - - # b4_basic_symbol_constructor_define(SYMBOL-NUM) # ---------------------------------------------- -# Generate a constructor implementation for basic_symbol from given type. +# Generate a constructor for basic_symbol from given type. m4_define([b4_basic_symbol_constructor_define], [[#if 201103L <= YY_CPLUSPLUS - template - ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( + basic_symbol (]b4_join( [typename Base::kind_type t], b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), b4_locations_if([location_type&& l]))[) - : Base (t)]b4_symbol_if([$1], [has_type], [ - , value (std::move (v))])[]b4_locations_if([ - , location (std::move (l))])[ - {} + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (std::move (v))])[]b4_locations_if([ + , location (std::move (l))])[ + {} #else - template - ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( + basic_symbol (]b4_join( [typename Base::kind_type t], b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), b4_locations_if([const location_type& l]))[) - : Base (t)]b4_symbol_if([$1], [has_type], [ - , value (v)])[]b4_locations_if([ - , location (l)])[ - {} + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (v)])[]b4_locations_if([ + , location (l)])[ + {} #endif ]]) @@ -525,5 +459,4 @@ m4_define([b4_basic_symbol_constructor_define], # Define the overloaded versions of make_symbol for all the value types. m4_define([b4_token_constructor_define], [ // Implementation of make_symbol for each symbol type. -b4_type_foreach([_b4_token_constructor_define]) b4_symbol_foreach([_b4_token_maker_define])])