Skip to content

Commit 01dd69c

Browse files
committed
Use the trailing commas feature to simplify @union code generation a little
1 parent 36de66c commit 01dd69c

File tree

4 files changed

+22
-38
lines changed

4 files changed

+22
-38
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.3.0 Build 9316:1733
2+
cppfront compiler v0.3.0 Build 9316:1739
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ class cmdline_processor
724724
if (arg+1 == args.end()) {
725725
print("Missing argument to option " + arg->text + " (try -help)\n");
726726
help_requested = true;
727+
break;
727728
}
728729
arg->pos = processed;
729730
++arg; // move to next argument, which is the argument to this switch

source/reflect.h

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class alias_declaration;
3939
#line 962 "reflect.h2"
4040
class value_member_info;
4141

42-
#line 1484 "reflect.h2"
42+
#line 1480 "reflect.h2"
4343
}
4444

4545
}
@@ -753,14 +753,14 @@ auto flag_enum(meta::type_declaration& t) -> void;
753753

754754
auto cpp2_union(meta::type_declaration& t) -> void;
755755

756-
#line 1367 "reflect.h2"
756+
#line 1363 "reflect.h2"
757757
//-----------------------------------------------------------------------
758758
//
759759
// print - output a pretty-printed visualization of t
760760
//
761761
auto print(cpp2::impl::in<meta::type_declaration> t) -> void;
762762

763-
#line 1377 "reflect.h2"
763+
#line 1373 "reflect.h2"
764764
//-----------------------------------------------------------------------
765765
//
766766
// apply_metafunctions
@@ -771,7 +771,7 @@ auto print(cpp2::impl::in<meta::type_declaration> t) -> void;
771771
auto const& error
772772
) -> bool;
773773

774-
#line 1484 "reflect.h2"
774+
#line 1480 "reflect.h2"
775775
}
776776

777777
}
@@ -1896,38 +1896,25 @@ std::string storage{" _storage: cpp2::aligned_storage<cpp2::max( "};
18961896

18971897
#line 1286 "reflect.h2"
18981898
{
1899-
{
1900-
std::string comma{""};
1901-
1902-
#line 1288 "reflect.h2"
19031899
for (
1900+
auto const& e : alternatives ) {
1901+
storage += ("sizeof(" + cpp2::to_string(e.type) + "), ");
1902+
}
19041903

1905-
auto const& e : alternatives ) { do {
1906-
storage += comma + ("sizeof(" + cpp2::to_string(e.type) + ")");
1907-
} while (false); comma = ", "; }
1908-
}
1909-
1910-
#line 1294 "reflect.h2"
19111904
storage += "), cpp2::max( ";
1912-
{
1913-
std::string comma{""};
19141905

1915-
#line 1297 "reflect.h2"
19161906
for (
1907+
auto const& e : alternatives ) {
1908+
storage += ("alignof(" + cpp2::to_string(e.type) + "), ");
1909+
}
19171910

1918-
auto const& e : alternatives ) { do {
1919-
storage += comma + ("alignof(" + cpp2::to_string(e.type) + ")");
1920-
} while (false); comma = ", "; }
1921-
}
1922-
1923-
#line 1303 "reflect.h2"
19241911
storage += " )> = ();\n";
19251912
CPP2_UFCS(add_member)(t, std::move(storage));
19261913
}
19271914
}
19281915

19291916
// Provide discriminator
1930-
#line 1308 "reflect.h2"
1917+
#line 1304 "reflect.h2"
19311918
CPP2_UFCS(add_member)(t, (" _discriminator: " + cpp2::to_string(std::move(discriminator_type)) + " = -1;\n"));
19321919

19331920
// Add the alternatives: is_alternative, get_alternative, and set_alternative
@@ -1949,7 +1936,7 @@ std::string destroy{" private _destroy: (inout this) = {\n"};
19491936

19501937
// Add destroy
19511938

1952-
#line 1327 "reflect.h2"
1939+
#line 1323 "reflect.h2"
19531940
{
19541941
for (
19551942
auto const& a : alternatives ) {
@@ -1963,7 +1950,7 @@ std::string destroy{" private _destroy: (inout this) = {\n"};
19631950
}
19641951

19651952
// Add the destructor
1966-
#line 1339 "reflect.h2"
1953+
#line 1335 "reflect.h2"
19671954
CPP2_UFCS(add_member)(t, " operator=: (move this) = { _destroy(); _ = this; }");
19681955

19691956
// Add default constructor
@@ -1973,7 +1960,7 @@ std::string value_set{""};
19731960

19741961
// Add copy/move construction and assignment
19751962

1976-
#line 1346 "reflect.h2"
1963+
#line 1342 "reflect.h2"
19771964
{
19781965
for (
19791966
auto const& a : std::move(alternatives) ) {
@@ -1993,16 +1980,16 @@ std::string value_set{""};
19931980
);
19941981
}
19951982
}
1996-
#line 1364 "reflect.h2"
1983+
#line 1360 "reflect.h2"
19971984
}
19981985

1999-
#line 1371 "reflect.h2"
1986+
#line 1367 "reflect.h2"
20001987
auto print(cpp2::impl::in<meta::type_declaration> t) -> void
20011988
{
20021989
std::cout << CPP2_UFCS(print)(t) << "\n";
20031990
}
20041991

2005-
#line 1381 "reflect.h2"
1992+
#line 1377 "reflect.h2"
20061993
[[nodiscard]] auto apply_metafunctions(
20071994
declaration_node& n,
20081995
type_declaration& rtype,
@@ -2105,7 +2092,7 @@ auto print(cpp2::impl::in<meta::type_declaration> t) -> void
21052092
return true;
21062093
}
21072094

2108-
#line 1484 "reflect.h2"
2095+
#line 1480 "reflect.h2"
21092096
}
21102097

21112098
}

source/reflect.h2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,20 +1284,16 @@ union: (inout t : meta::type_declaration)
12841284
// Provide storage
12851285
(copy storage: std::string = " _storage: cpp2::aligned_storage<cpp2::max( ")
12861286
{
1287-
(copy comma: std::string = "")
12881287
for alternatives
1289-
next comma = ", "
12901288
do (e) {
1291-
storage += comma + "sizeof((e.type)$)";
1289+
storage += "sizeof((e.type)$), ";
12921290
}
12931291

12941292
storage += "), cpp2::max( ";
12951293

1296-
(copy comma: std::string = "")
12971294
for alternatives
1298-
next comma = ", "
12991295
do (e) {
1300-
storage += comma + "alignof((e.type)$)";
1296+
storage += "alignof((e.type)$), ";
13011297
}
13021298

13031299
storage += " )> = ();\n";

0 commit comments

Comments
 (0)