Skip to content

Commit 4d48cc3

Browse files
committed
fix(reflect): fix initialization and regenerate
1 parent 04f2115 commit 4d48cc3

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

source/reflect.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ auto basic_value(meta::type_declaration& t) -> void;
569569
//-----------------------------------------------------------------------
570570
//
571571
// "A 'value' is a totally ordered basic_value..."
572-
//
572+
//
573573
// -- P0707R4, section 3
574574
//
575575
// value - a value type that is totally ordered
@@ -649,20 +649,20 @@ auto basic_enum(
649649
// value of its enumerators's type, and otherwise has only public
650650
// member variables of its enumerator's type, all of which are
651651
// naturally scoped because they are members of a type."
652-
//
652+
//
653653
// -- P0707R4, section 3
654654
//
655655
auto cpp2_enum(meta::type_declaration& t) -> void;
656656

657657
#line 1048 "reflect.h2"
658658
//-----------------------------------------------------------------------
659659
//
660-
// "flag_enum expresses an enumeration that stores values
660+
// "flag_enum expresses an enumeration that stores values
661661
// corresponding to bitwise-or'd enumerators. The enumerators must
662662
// be powers of two, and are automatically generated [...] A none
663663
// value is provided [...] Operators | and & are provided to
664664
// combine and extract values."
665-
//
665+
//
666666
// -- P0707R4, section 3
667667
//
668668
auto flag_enum(meta::type_declaration& t) -> void;
@@ -676,10 +676,10 @@ auto flag_enum(meta::type_declaration& t) -> void;
676676
//
677677
// -- Stroustrup (The Design and Evolution of C++, 14.3.4.1)
678678
//
679-
// "C++17 needs a type-safe union... The implications of the
680-
// consensus `variant` design are well understood and have been
681-
// explored over several LEWG discussions, over a thousand emails,
682-
// a joint LEWG/EWG session, and not to mention 12 years of
679+
// "C++17 needs a type-safe union... The implications of the
680+
// consensus `variant` design are well understood and have been
681+
// explored over several LEWG discussions, over a thousand emails,
682+
// a joint LEWG/EWG session, and not to mention 12 years of
683683
// experience with Boost and other libraries."
684684
//
685685
// -- Axel Naumann, in P0088 (wg21.link/p0088),
@@ -688,9 +688,9 @@ auto flag_enum(meta::type_declaration& t) -> void;
688688
//-----------------------------------------------------------------------
689689
//
690690
// union
691-
//
691+
//
692692
// a type that contains exactly one of a fixed set of values at a time
693-
//
693+
//
694694

695695
auto cpp2_union(meta::type_declaration& t) -> void;
696696

@@ -790,9 +790,7 @@ auto newline_pos = CPP2_UFCS(find)(source, '\n');
790790
newline_pos = CPP2_UFCS(find)(source, '\n');
791791
}
792792
}
793-
}
794793

795-
#line 99 "reflect.h2"
796794
if (!(CPP2_UFCS(empty)(source))) {
797795
std::move(add_line)(std::move(source));
798796
}
@@ -812,6 +810,8 @@ auto newline_pos = CPP2_UFCS(find)(source, '\n');
812810
(*cpp2::assert_not_null(CPP2_UFCS(begin)(CPP2_UFCS(get_map)(*cpp2::assert_not_null(std::move(tokens)))))).second,
813811
*cpp2::assert_not_null(generated_tokens)
814812
);
813+
}
814+
#line 118 "reflect.h2"
815815
}
816816

817817
[[nodiscard]] auto compiler_services::position() const -> source_position
@@ -835,7 +835,7 @@ auto newline_pos = CPP2_UFCS(find)(source, '\n');
835835
{
836836
auto message {cpp2::as_<std::string>(msg)};
837837
if (!(CPP2_UFCS(empty)(metafunction_name))) {
838-
message = "while applying @" + metafunction_name + " - " + message;
838+
message = "while applying @" + metafunction_name + " - " + std::move(message);
839839
}
840840
static_cast<void>(CPP2_UFCS(emplace_back)((*cpp2::assert_not_null(errors)), position(), std::move(message)));
841841
}
@@ -1360,7 +1360,7 @@ auto basic_enum(
13601360
std::vector<value_member_info> enumerators {};
13611361
cpp2::i64 min_value {};
13621362
cpp2::i64 max_value {};
1363-
cpp2::deferred_init<std::string> underlying_type;
1363+
std::string underlying_type {};
13641364

13651365
CPP2_UFCS(reserve_names)(t, "operator=", "operator<=>");
13661366
if (bitwise) {
@@ -1369,7 +1369,7 @@ auto basic_enum(
13691369

13701370
// 1. Gather: The names of all the user-written members, and find/compute the type
13711371

1372-
underlying_type.construct(CPP2_UFCS(get_argument)(t, 0));// use the first template argument, if there was one
1372+
underlying_type = CPP2_UFCS(get_argument)(t, 0);// use the first template argument, if there was one
13731373

13741374
auto found_non_numeric {false};
13751375
{
@@ -1415,23 +1415,23 @@ std::string value = "-1";
14151415

14161416
// Compute the default underlying type, if it wasn't explicitly specified
14171417
#line 913 "reflect.h2"
1418-
if (underlying_type.value() == "")
1418+
if (underlying_type == "")
14191419
{
14201420
CPP2_UFCS(require)(t, !(std::move(found_non_numeric)),
14211421
"if you write an enumerator with a non-numeric-literal value, you must specify the enumeration's underlying type");
14221422

14231423
if (!(bitwise)) {
14241424
if (cpp2::cmp_greater_eq(min_value,std::numeric_limits<cpp2::i8>::min()) && cpp2::cmp_less_eq(max_value,std::numeric_limits<cpp2::i8>::max())) {
1425-
underlying_type.value() = "i8";
1425+
underlying_type = "i8";
14261426
}
14271427
else {if (cpp2::cmp_greater_eq(min_value,std::numeric_limits<cpp2::i16>::min()) && cpp2::cmp_less_eq(max_value,std::numeric_limits<cpp2::i16>::max())) {
1428-
underlying_type.value() = "i16";
1428+
underlying_type = "i16";
14291429
}
14301430
else {if (cpp2::cmp_greater_eq(min_value,std::numeric_limits<cpp2::i32>::min()) && cpp2::cmp_less_eq(max_value,std::numeric_limits<cpp2::i32>::max())) {
1431-
underlying_type.value() = "i32";
1431+
underlying_type = "i32";
14321432
}
1433-
else {if (cpp2::cmp_greater_eq(std::move(min_value),std::numeric_limits<cpp2::i64>::min()) && cpp2::cmp_less_eq(max_value,std::numeric_limits<cpp2::i64>::max())) {
1434-
underlying_type.value() = "i64";
1433+
else {if (cpp2::cmp_greater_eq(std::move(min_value),std::numeric_limits<cpp2::i64>::min()) && cpp2::cmp_less_eq(std::move(max_value),std::numeric_limits<cpp2::i64>::max())) {
1434+
underlying_type = "i64";
14351435
}
14361436
else {
14371437
CPP2_UFCS(error)(t, "values are outside the range representable by the largest supported underlying signed type (i64)");
@@ -1440,16 +1440,16 @@ std::string value = "-1";
14401440
else {
14411441
auto umax {std::move(max_value) * cpp2::as_<cpp2::u64, 2>()};
14421442
if (cpp2::cmp_less_eq(umax,std::numeric_limits<cpp2::u8>::max())) {
1443-
underlying_type.value() = "u8";
1443+
underlying_type = "u8";
14441444
}
14451445
else {if (cpp2::cmp_less_eq(umax,std::numeric_limits<cpp2::u16>::max())) {
1446-
underlying_type.value() = "u16";
1446+
underlying_type = "u16";
14471447
}
14481448
else {if (cpp2::cmp_less_eq(std::move(umax),std::numeric_limits<cpp2::u32>::max())) {
1449-
underlying_type.value() = "u32";
1449+
underlying_type = "u32";
14501450
}
14511451
else {
1452-
underlying_type.value() = "u64";
1452+
underlying_type = "u64";
14531453
}}}
14541454
}
14551455
}
@@ -1462,9 +1462,9 @@ std::string value = "-1";
14621462
CPP2_UFCS(remove_marked_members)(t);
14631463

14641464
// Generate all the common material: value and common functions
1465-
CPP2_UFCS(add_member)(t, " _value : " + cpp2::to_string(underlying_type.value()) + ";");
1466-
CPP2_UFCS(add_member)(t, " private operator= : (implicit out this, _val: i64) == _value = cpp2::unsafe_narrow<" + cpp2::to_string(underlying_type.value()) + ">(_val);");
1467-
CPP2_UFCS(add_member)(t, " get_raw_value : (this) -> " + cpp2::to_string(std::move(underlying_type.value())) + " == _value;");
1465+
CPP2_UFCS(add_member)(t, " _value : " + cpp2::to_string(underlying_type) + ";");
1466+
CPP2_UFCS(add_member)(t, " private operator= : (implicit out this, _val: i64) == _value = cpp2::unsafe_narrow<" + cpp2::to_string(underlying_type) + ">(_val);");
1467+
CPP2_UFCS(add_member)(t, " get_raw_value : (this) -> " + cpp2::to_string(std::move(underlying_type)) + " == _value;");
14681468
CPP2_UFCS(add_member)(t, " operator= : (out this, that) == { }");
14691469
CPP2_UFCS(add_member)(t, " operator<=> : (this, that) -> std::strong_ordering;");
14701470

source/reflect.h2

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ compiler_services: @polymorphic_base @copyable type =
8484

8585
// First split this string into source_lines
8686
//
87-
(copy newline_pos := source.find('\n'))
87+
(copy newline_pos := source.find('\n'))
8888
if source.ssize() > 1
8989
&& newline_pos != source.npos
9090
{
@@ -286,7 +286,7 @@ declaration: @polymorphic_base @copyable type =
286286

287287
parent_is_polymorphic: (this) -> bool = n*.parent_is_polymorphic();
288288

289-
mark_for_removal_from_enclosing_type: (inout this)
289+
mark_for_removal_from_enclosing_type: (inout this)
290290
pre<Type>( parent_is_type() ) // this precondition should be sufficient ...
291291
= {
292292
test := n*.type_member_mark_for_removal();
@@ -406,7 +406,7 @@ type_declaration: @copyable type =
406406
assert( n*.is_type() );
407407
}
408408

409-
reserve_names: (this, name: std::string_view, forward etc...) =
409+
reserve_names: (this, name: std::string_view, forward etc...) =
410410
{ // etc is not declared ':string_view' for compatibility with GCC 10.x
411411
for get_members()
412412
do (m) {
@@ -758,7 +758,7 @@ basic_value: (inout t: meta::type_declaration) =
758758
//-----------------------------------------------------------------------
759759
//
760760
// "A 'value' is a totally ordered basic_value..."
761-
//
761+
//
762762
// -- P0707R4, section 3
763763
//
764764
// value - a value type that is totally ordered
@@ -859,7 +859,7 @@ basic_enum: (
859859
enumerators : std::vector<value_member_info> = ();
860860
min_value : i64 = ();
861861
max_value : i64 = ();
862-
underlying_type : std::string;
862+
underlying_type : std::string = ();
863863

864864
t.reserve_names( "operator=", "operator<=>" );
865865
if bitwise {
@@ -910,7 +910,7 @@ basic_enum: (
910910
}
911911

912912
// Compute the default underlying type, if it wasn't explicitly specified
913-
if underlying_type == ""
913+
if underlying_type == ""
914914
{
915915
t.require( !found_non_numeric,
916916
"if you write an enumerator with a non-numeric-literal value, you must specify the enumeration's underlying type");
@@ -993,7 +993,7 @@ basic_enum: (
993993
to_string += " if this == none { return \"(none)\"; }\n";
994994
}
995995

996-
for enumerators
996+
for enumerators
997997
do (e) {
998998
if e.name != "_" { // ignore unnamed values
999999
if bitwise {
@@ -1025,7 +1025,7 @@ basic_enum: (
10251025
// value of its enumerators's type, and otherwise has only public
10261026
// member variables of its enumerator's type, all of which are
10271027
// naturally scoped because they are members of a type."
1028-
//
1028+
//
10291029
// -- P0707R4, section 3
10301030
//
10311031
enum: (inout t: meta::type_declaration) =
@@ -1047,12 +1047,12 @@ enum: (inout t: meta::type_declaration) =
10471047

10481048
//-----------------------------------------------------------------------
10491049
//
1050-
// "flag_enum expresses an enumeration that stores values
1050+
// "flag_enum expresses an enumeration that stores values
10511051
// corresponding to bitwise-or'd enumerators. The enumerators must
10521052
// be powers of two, and are automatically generated [...] A none
10531053
// value is provided [...] Operators | and & are provided to
10541054
// combine and extract values."
1055-
//
1055+
//
10561056
// -- P0707R4, section 3
10571057
//
10581058
flag_enum: (inout t: meta::type_declaration) =
@@ -1085,10 +1085,10 @@ flag_enum: (inout t: meta::type_declaration) =
10851085
//
10861086
// -- Stroustrup (The Design and Evolution of C++, 14.3.4.1)
10871087
//
1088-
// "C++17 needs a type-safe union... The implications of the
1089-
// consensus `variant` design are well understood and have been
1090-
// explored over several LEWG discussions, over a thousand emails,
1091-
// a joint LEWG/EWG session, and not to mention 12 years of
1088+
// "C++17 needs a type-safe union... The implications of the
1089+
// consensus `variant` design are well understood and have been
1090+
// explored over several LEWG discussions, over a thousand emails,
1091+
// a joint LEWG/EWG session, and not to mention 12 years of
10921092
// experience with Boost and other libraries."
10931093
//
10941094
// -- Axel Naumann, in P0088 (wg21.link/p0088),
@@ -1097,9 +1097,9 @@ flag_enum: (inout t: meta::type_declaration) =
10971097
//-----------------------------------------------------------------------
10981098
//
10991099
// union
1100-
//
1100+
//
11011101
// a type that contains exactly one of a fixed set of values at a time
1102-
//
1102+
//
11031103

11041104
union: (inout t : meta::type_declaration)
11051105
= {
@@ -1154,8 +1154,8 @@ union: (inout t : meta::type_declaration)
11541154
(copy storage: std::string = " _storage: std::aligned_storage_t<cpp2::max( ")
11551155
{
11561156
(copy comma: std::string = "")
1157-
for alternatives
1158-
next comma = ", "
1157+
for alternatives
1158+
next comma = ", "
11591159
do (e) {
11601160
storage += comma + "sizeof((e.type)$)";
11611161
}
@@ -1168,7 +1168,7 @@ union: (inout t : meta::type_declaration)
11681168
t.add_member( " _discriminator: (discriminator_type)$ = -1;\n");
11691169

11701170
// Add the alternatives: is_alternative, get_alternative, and set_alternative
1171-
for alternatives
1171+
for alternatives
11721172
do (a)
11731173
{
11741174
t.add_member( " is_(a.name)$: (this) -> bool = _discriminator == (a.value)$;\n");
@@ -1266,7 +1266,7 @@ apply_metafunctions: (
12661266

12671267
args: std::vector<std::string> = ();
12681268
for meta*.template_arguments()
1269-
do (arg)
1269+
do (arg)
12701270
args.push_back( arg.to_string() );
12711271

12721272
rtype.set_metafunction_name( name, args );
@@ -1325,9 +1325,9 @@ apply_metafunctions: (
13251325
}
13261326

13271327
if (
1328-
!args.empty()
1328+
!args.empty()
13291329
&& !rtype.arguments_were_used()
1330-
)
1330+
)
13311331
{
13321332
error( name + " did not use its template arguments - did you mean to write '" + name + " <" + args[0] + "> type' (with the spaces)?");
13331333
return false;

0 commit comments

Comments
 (0)