Skip to content

Commit 3ea209b

Browse files
committed
Added @maker metafunction.
Creates a 'make_<class name>' function.
1 parent dfb1113 commit 3ea209b

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

source/reflect.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class alias_declaration;
3838
#line 884 "reflect.h2"
3939
class value_member_info;
4040

41-
#line 1370 "reflect.h2"
41+
#line 1382 "reflect.h2"
4242
}
4343

4444
}
@@ -724,7 +724,14 @@ auto cpp2_union(meta::type_declaration& t) -> void;
724724
//
725725
auto print(cpp2::in<meta::type_declaration> t) -> void;
726726

727-
#line 1266 "reflect.h2"
727+
#line 1265 "reflect.h2"
728+
//-----------------------------------------------------------------------
729+
//
730+
// maker - add a make_<class name> function
731+
//
732+
auto maker(meta::type_declaration& t) -> void;
733+
734+
#line 1275 "reflect.h2"
728735
//-----------------------------------------------------------------------
729736
//
730737
// apply_metafunctions
@@ -735,7 +742,7 @@ auto print(cpp2::in<meta::type_declaration> t) -> void;
735742
auto const& error
736743
) -> bool;
737744

738-
#line 1370 "reflect.h2"
745+
#line 1382 "reflect.h2"
739746
}
740747

741748
}
@@ -1771,7 +1778,13 @@ auto print(cpp2::in<meta::type_declaration> t) -> void
17711778
std::cout << CPP2_UFCS_0(print, t) << "\n";
17721779
}
17731780

1774-
#line 1270 "reflect.h2"
1781+
#line 1269 "reflect.h2"
1782+
auto maker(meta::type_declaration& t) -> void
1783+
{
1784+
CPP2_UFCS(add_declaration, t, "make_" + cpp2::to_string(CPP2_UFCS_0(name, t)) + ": (args...: _) -> _ = { return " + cpp2::to_string(CPP2_UFCS_0(name, t)) + "(args...); }");
1785+
}
1786+
1787+
#line 1279 "reflect.h2"
17751788
[[nodiscard]] auto apply_metafunctions(
17761789
declaration_node& n,
17771790
type_declaration& rtype,
@@ -1852,11 +1865,14 @@ auto print(cpp2::in<meta::type_declaration> t) -> void
18521865
else {if (name == "print") {
18531866
print(rtype);
18541867
}
1868+
else {if (name == "maker") {
1869+
maker(rtype);
1870+
}
18551871
else {
18561872
error("unrecognized metafunction name: " + name);
18571873
error("(temporary alpha limitation) currently the supported names are: interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, copyable, basic_value, value, weakly_ordered_value, partially_ordered_value, struct, enum, flag_enum, union, print");
18581874
return false;
1859-
}}}}}}}}}}}}}}}
1875+
}}}}}}}}}}}}}}}}
18601876

18611877
if ((
18621878
!(CPP2_UFCS_0(empty, args))
@@ -1871,7 +1887,7 @@ auto print(cpp2::in<meta::type_declaration> t) -> void
18711887
return true;
18721888
}
18731889

1874-
#line 1370 "reflect.h2"
1890+
#line 1382 "reflect.h2"
18751891
}
18761892

18771893
}

source/reflect.h2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,15 @@ print: (t: meta::type_declaration) =
12621262
std::cout << t.print() << "\n";
12631263
}
12641264

1265+
//-----------------------------------------------------------------------
1266+
//
1267+
// maker - add a make_<class name> function
1268+
//
1269+
maker: (inout t: meta::type_declaration) =
1270+
{
1271+
t.add_declaration("make_(t.name())$: (args...: _) -> _ = { return (t.name())$(args...); }");
1272+
}
1273+
12651274

12661275
//-----------------------------------------------------------------------
12671276
//
@@ -1347,6 +1356,9 @@ apply_metafunctions: (
13471356
else if name == "print" {
13481357
print( rtype );
13491358
}
1359+
else if name == "maker" {
1360+
maker( rtype );
1361+
}
13501362
else {
13511363
error( "unrecognized metafunction name: " + name );
13521364
error( "(temporary alpha limitation) currently the supported names are: interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, copyable, basic_value, value, weakly_ordered_value, partially_ordered_value, struct, enum, flag_enum, union, print" );

0 commit comments

Comments
 (0)