diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2018-12-26 09:04:07 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2018-12-26 09:12:25 +0100 |
commit | 5fb0d276b3fe2e736fce1e002d7a08a3d1a86944 (patch) | |
tree | 469e0b1ed55a3ac84d72da8225cd466c81438c9d /data/skeletons/variant.hh | |
parent | 50285ff06695a8c5d977337f0ede3a4d72aa048d (diff) | |
download | bison-5fb0d276b3fe2e736fce1e002d7a08a3d1a86944.tar.gz |
c++: variants: fuse declarations and definitions
We used to create a short definition of yy::parser with all the
implementations of its member functions outside. But yy::parser is no
longer short and simple to read. Maintaining each function twice is
painful: a lot of redundancy but different indentation levels, output
which depends on whether we are in a header or not (see
d132c2d5455135f63a7497c38358eadd6e3a6af8), etc.
Let's simplify this and put the implementations into the class
definition itself.
Discussed in this monologue:
https://lists.gnu.org/archive/html/bison-patches/2018-12/msg00058.html.
* data/skeletons/c++.m4, data/skeletons/lalr1.cc,
* data/skeletons/variant.hh (b4_basic_symbol_constructor_define)
(_b4_token_constructor_declare, b4_token_constructor_declare)
Merge into...
(b4_basic_symbol_constructor_define, _b4_token_constructor_define)
(b4_token_constructor_define): these.
Diffstat (limited to 'data/skeletons/variant.hh')
-rw-r--r-- | data/skeletons/variant.hh | 205 |
1 files changed, 69 insertions, 136 deletions
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,177 +345,111 @@ m4_define([_b4_includes_tokens], [m4_map([_b4_is_token], [$@])]) -# _b4_token_maker_declare(SYMBOL-NUM) -# ----------------------------------- -# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. -m4_define([_b4_token_maker_declare], -[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]))); -#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]))); -#endif -])]) - - -# _b4_token_constructor_declare(SYMBOL-NUM...) -# -------------------------------------------- -# Declare 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_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]))); -#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]))); -#endif -])]) - - -# b4_token_constructor_declare -# ---------------------------- -# Declare token constructors. Use at class-level. -m4_define([b4_token_constructor_declare], -[ // Symbol constructors declarations. -b4_symbol_foreach([_b4_token_maker_declare])]) - - - # _b4_token_maker_define(SYMBOL-NUM) # ---------------------------------- -# Define make_SYMBOL for SYMBOL-NUM. +# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. 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)]))); - } + 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 - 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]))); - } + 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_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])])])]) + +# _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_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], [, ], [$@]))[); - } + 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], [, ], [$@]))[); - } + 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_token_constructor_declare +# ---------------------------- +# Declare token constructors. Use at class-level. +m4_define([b4_token_constructor_declare], +[ // Symbol constructors declarations. +b4_symbol_foreach([_b4_token_maker_declare])]) + # 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 <typename Base> - ]b4_parser_class_name[::basic_symbol<Base>::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 <typename Base> - ]b4_parser_class_name[::basic_symbol<Base>::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])]) |