mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
c++: style changes
* data/c++.m4, data/variant.hh: Improve layout of the generated code. Avoid casts. (_b4_symbol_constructor_declare, _b4_symbol_constructor_define): Rename as... (_b4_token_maker_declare, _b4_token_maker_define): these. * tests/types.at: Improve pair printing.
This commit is contained in:
@@ -259,9 +259,8 @@ m4_define([b4_symbol_type_declare],
|
|||||||
basic_symbol ();
|
basic_symbol ();
|
||||||
|
|
||||||
/// Move or copy constructor.
|
/// Move or copy constructor.
|
||||||
basic_symbol (YY_RVREF (basic_symbol) other);
|
basic_symbol (YY_RVREF (basic_symbol) other);]b4_variant_if([[
|
||||||
|
|
||||||
]b4_variant_if([[
|
|
||||||
/// Constructor for valueless symbols, and symbols from each type.
|
/// Constructor for valueless symbols, and symbols from each type.
|
||||||
]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[
|
]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[
|
||||||
/// Constructor for valueless symbols.
|
/// Constructor for valueless symbols.
|
||||||
@@ -360,8 +359,8 @@ m4_define([b4_public_types_define],
|
|||||||
, location (YY_MOVE (other.location))])[
|
, location (YY_MOVE (other.location))])[
|
||||||
{]b4_variant_if([
|
{]b4_variant_if([
|
||||||
b4_symbol_variant([other.type_get ()], [value], [YY_MOVE_OR_COPY],
|
b4_symbol_variant([other.type_get ()], [value], [YY_MOVE_OR_COPY],
|
||||||
[YY_MOVE (other.value)])])[
|
[YY_MOVE (other.value)])
|
||||||
}
|
])[}
|
||||||
|
|
||||||
]b4_variant_if([[
|
]b4_variant_if([[
|
||||||
// Implementation of basic_symbol constructor for each type.
|
// Implementation of basic_symbol constructor for each type.
|
||||||
@@ -475,7 +474,7 @@ m4_define([b4_public_types_define],
|
|||||||
{
|
{
|
||||||
]b4_toknum[
|
]b4_toknum[
|
||||||
};
|
};
|
||||||
return static_cast<token_type> (yytoken_number_[type]);
|
return token_type (yytoken_number_[type]);
|
||||||
}
|
}
|
||||||
]])[]dnl
|
]])[]dnl
|
||||||
|
|
||||||
|
|||||||
@@ -335,25 +335,25 @@ m4_define([b4_symbol_value_template],
|
|||||||
## ------------- ##
|
## ------------- ##
|
||||||
|
|
||||||
|
|
||||||
# _b4_symbol_constructor_declare(SYMBOL-NUM)
|
# _b4_token_maker_declare(SYMBOL-NUM)
|
||||||
# ------------------------------------------
|
# -----------------------------------
|
||||||
# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level.
|
# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level.
|
||||||
m4_define([_b4_symbol_constructor_declare],
|
m4_define([_b4_token_maker_declare],
|
||||||
[b4_token_visible_if([$1],
|
[b4_token_visible_if([$1],
|
||||||
[#if 201103L <= YY_CPLUSPLUS
|
[#if 201103L <= YY_CPLUSPLUS
|
||||||
static
|
static
|
||||||
symbol_type
|
symbol_type
|
||||||
make_[]_b4_symbol([$1], [id]) (dnl
|
make_[]_b4_symbol([$1], [id]) (b4_join(
|
||||||
b4_join(b4_symbol_if([$1], [has_type],
|
b4_symbol_if([$1], [has_type],
|
||||||
[b4_symbol([$1], [type]) v]),
|
[b4_symbol([$1], [type]) v]),
|
||||||
b4_locations_if([location_type l])));
|
b4_locations_if([location_type l])));
|
||||||
#else
|
#else
|
||||||
static
|
static
|
||||||
symbol_type
|
symbol_type
|
||||||
make_[]_b4_symbol([$1], [id]) (dnl
|
make_[]_b4_symbol([$1], [id]) (b4_join(
|
||||||
b4_join(b4_symbol_if([$1], [has_type],
|
b4_symbol_if([$1], [has_type],
|
||||||
[const b4_symbol([$1], [type])& v]),
|
[const b4_symbol([$1], [type])& v]),
|
||||||
b4_locations_if([const location_type& l])));
|
b4_locations_if([const location_type& l])));
|
||||||
#endif
|
#endif
|
||||||
])])
|
])])
|
||||||
|
|
||||||
@@ -364,22 +364,22 @@ b4_join(b4_symbol_if([$1], [has_type],
|
|||||||
# Use at class-level.
|
# Use at class-level.
|
||||||
m4_define([b4_symbol_constructor_declare],
|
m4_define([b4_symbol_constructor_declare],
|
||||||
[ // Symbol constructors declarations.
|
[ // Symbol constructors declarations.
|
||||||
b4_symbol_foreach([_b4_symbol_constructor_declare])])
|
b4_symbol_foreach([_b4_token_maker_declare])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# _b4_symbol_constructor_define(SYMBOL-NUM)
|
# _b4_token_maker_define(SYMBOL-NUM)
|
||||||
# -----------------------------------------
|
# ----------------------------------
|
||||||
# Define make_SYMBOL for SYMBOL-NUM.
|
# Define make_SYMBOL for SYMBOL-NUM.
|
||||||
m4_define([_b4_symbol_constructor_define],
|
m4_define([_b4_token_maker_define],
|
||||||
[b4_token_visible_if([$1],
|
[b4_token_visible_if([$1],
|
||||||
[#if 201103L <= YY_CPLUSPLUS
|
[#if 201103L <= YY_CPLUSPLUS
|
||||||
inline
|
inline
|
||||||
b4_parser_class_name::symbol_type
|
b4_parser_class_name::symbol_type
|
||||||
b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (dnl
|
b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (b4_join(
|
||||||
b4_join(b4_symbol_if([$1], [has_type],
|
b4_symbol_if([$1], [has_type],
|
||||||
[b4_symbol([$1], [type]) v]),
|
[b4_symbol([$1], [type]) v]),
|
||||||
b4_locations_if([location_type l])))
|
b4_locations_if([location_type l])))
|
||||||
{
|
{
|
||||||
return symbol_type (b4_join([token::b4_symbol([$1], [id])],
|
return symbol_type (b4_join([token::b4_symbol([$1], [id])],
|
||||||
b4_symbol_if([$1], [has_type], [std::move (v)]),
|
b4_symbol_if([$1], [has_type], [std::move (v)]),
|
||||||
@@ -388,10 +388,10 @@ b4_join(b4_symbol_if([$1], [has_type],
|
|||||||
#else
|
#else
|
||||||
inline
|
inline
|
||||||
b4_parser_class_name::symbol_type
|
b4_parser_class_name::symbol_type
|
||||||
b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (dnl
|
b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (b4_join(
|
||||||
b4_join(b4_symbol_if([$1], [has_type],
|
b4_symbol_if([$1], [has_type],
|
||||||
[const b4_symbol([$1], [type])& v]),
|
[const b4_symbol([$1], [type])& v]),
|
||||||
b4_locations_if([const location_type& l])))
|
b4_locations_if([const location_type& l])))
|
||||||
{
|
{
|
||||||
return symbol_type (b4_join([token::b4_symbol([$1], [id])],
|
return symbol_type (b4_join([token::b4_symbol([$1], [id])],
|
||||||
b4_symbol_if([$1], [has_type], [v]),
|
b4_symbol_if([$1], [has_type], [v]),
|
||||||
@@ -446,9 +446,10 @@ m4_define([b4_basic_symbol_constructor_define],
|
|||||||
#endif
|
#endif
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_constructor_define
|
# b4_symbol_constructor_define
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Define the overloaded versions of make_symbol for all the value types.
|
# Define the overloaded versions of make_symbol for all the value types.
|
||||||
m4_define([b4_symbol_constructor_define],
|
m4_define([b4_symbol_constructor_define],
|
||||||
[ // Implementation of make_symbol for each symbol type.
|
[ // Implementation of make_symbol for each symbol type.
|
||||||
b4_symbol_foreach([_b4_symbol_constructor_define])])
|
b4_symbol_foreach([_b4_token_maker_define])])
|
||||||
|
|||||||
@@ -295,15 +295,14 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
|||||||
[[%token <std::unique_ptr<int>> '1';
|
[[%token <std::unique_ptr<int>> '1';
|
||||||
%token <std::pair<int, int>> '2';]],
|
%token <std::pair<int, int>> '2';]],
|
||||||
['1' '2' { std::cout << *$1 << ", "
|
['1' '2' { std::cout << *$1 << ", "
|
||||||
<< $2.first << ", "
|
<< $2.first << ':' << $2.second << '\n'; }],
|
||||||
<< $2.second << '\n'; }],
|
|
||||||
["12"],
|
["12"],
|
||||||
[[if (res == '1')
|
[[if (res == '1')
|
||||||
]AT_VAL[.emplace <std::unique_ptr<int>>
|
]AT_VAL[.emplace <std::unique_ptr<int>>
|
||||||
(std::make_unique <int> (10));
|
(std::make_unique <int> (10));
|
||||||
else if (res == '2')
|
else if (res == '2')
|
||||||
]AT_VAL[.emplace <std::pair<int, int>> (21, 22);]],
|
]AT_VAL[.emplace <std::pair<int, int>> (21, 22);]],
|
||||||
[10, 21, 22],
|
[10, 21:22],
|
||||||
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
|
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
|
||||||
|
|
||||||
# Token constructors on move-only types, and types with commas.
|
# Token constructors on move-only types, and types with commas.
|
||||||
@@ -315,8 +314,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
|||||||
%token <std::pair<int, int>> TWO;
|
%token <std::pair<int, int>> TWO;
|
||||||
%token EOI 0;]],
|
%token EOI 0;]],
|
||||||
[ONE TWO { std::cout << *$1 << ", "
|
[ONE TWO { std::cout << *$1 << ", "
|
||||||
<< $2.first << ", "
|
<< $2.first << ':' << $2.second << '\n'; }],
|
||||||
<< $2.second << '\n'; }],
|
|
||||||
["12"],
|
["12"],
|
||||||
[[if (res == '1')
|
[[if (res == '1')
|
||||||
return yy::parser::make_ONE (std::make_unique<int> (10));
|
return yy::parser::make_ONE (std::make_unique<int> (10));
|
||||||
@@ -324,7 +322,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
|||||||
return yy::parser::make_TWO (std::make_pair (21, 22));
|
return yy::parser::make_TWO (std::make_pair (21, 22));
|
||||||
else
|
else
|
||||||
return yy::parser::make_EOI ()]],
|
return yy::parser::make_EOI ()]],
|
||||||
[10, 21, 22],
|
[10, 21:22],
|
||||||
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
|
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user