Skip to content

Commit 5a04b1d

Browse files
committed
Added generate_binary_expression metafunction.
1 parent 3ea209b commit 5a04b1d

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

source/reflect.h

Lines changed: 27 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 1382 "reflect.h2"
41+
#line 1399 "reflect.h2"
4242
}
4343

4444
}
@@ -731,7 +731,14 @@ auto print(cpp2::in<meta::type_declaration> t) -> void;
731731
//
732732
auto maker(meta::type_declaration& t) -> void;
733733

734-
#line 1275 "reflect.h2"
734+
#line 1274 "reflect.h2"
735+
//-----------------------------------------------------------------------
736+
//
737+
// generate_expressions - adds expression syntax
738+
//
739+
auto generate_binary_expression(meta::type_declaration& t) -> void;
740+
741+
#line 1289 "reflect.h2"
735742
//-----------------------------------------------------------------------
736743
//
737744
// apply_metafunctions
@@ -742,7 +749,7 @@ auto maker(meta::type_declaration& t) -> void;
742749
auto const& error
743750
) -> bool;
744751

745-
#line 1382 "reflect.h2"
752+
#line 1399 "reflect.h2"
746753
}
747754

748755
}
@@ -1784,7 +1791,18 @@ auto maker(meta::type_declaration& t) -> void
17841791
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...); }");
17851792
}
17861793

1787-
#line 1279 "reflect.h2"
1794+
#line 1278 "reflect.h2"
1795+
auto generate_binary_expression(meta::type_declaration& t) -> void
1796+
{
1797+
1798+
std::string op_name {CPP2_UFCS(substr, CPP2_UFCS_0(name, t), 8)}; // Skip 'Operator'
1799+
1800+
CPP2_UFCS(add_declaration, t, cpp2::to_string(op_name) + ": <A, B> (arg_a: Expression<A>, arg_b: Expression<B>) -> _ = BinaryExpression<A, B, " + cpp2::to_string(CPP2_UFCS_0(name, t)) + ">(arg_a, arg_b);");
1801+
CPP2_UFCS(add_declaration, t, cpp2::to_string(op_name) + ": <A> (arg_a: Expression<A>, arg_b: double) -> _ = BinaryExpression<A, Constant<double>, " + cpp2::to_string(CPP2_UFCS_0(name, t)) + ">(arg_a, Constant<double>(arg_b));");
1802+
CPP2_UFCS(add_declaration, t, cpp2::to_string(std::move(op_name)) + ": <B> (arg_a: double, arg_b: Expression<B>) -> _ = BinaryExpression<Constant<double>, B, " + cpp2::to_string(CPP2_UFCS_0(name, t)) + ">(Constant<double>(arg_a), arg_b);");
1803+
}
1804+
1805+
#line 1293 "reflect.h2"
17881806
[[nodiscard]] auto apply_metafunctions(
17891807
declaration_node& n,
17901808
type_declaration& rtype,
@@ -1868,11 +1886,14 @@ auto maker(meta::type_declaration& t) -> void
18681886
else {if (name == "maker") {
18691887
maker(rtype);
18701888
}
1889+
else {if (name == "generate_binary_expression") {
1890+
generate_binary_expression(rtype);
1891+
}
18711892
else {
18721893
error("unrecognized metafunction name: " + name);
18731894
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");
18741895
return false;
1875-
}}}}}}}}}}}}}}}}
1896+
}}}}}}}}}}}}}}}}}
18761897

18771898
if ((
18781899
!(CPP2_UFCS_0(empty, args))
@@ -1887,7 +1908,7 @@ auto maker(meta::type_declaration& t) -> void
18871908
return true;
18881909
}
18891910

1890-
#line 1382 "reflect.h2"
1911+
#line 1399 "reflect.h2"
18911912
}
18921913

18931914
}

source/reflect.h2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,20 @@ maker: (inout t: meta::type_declaration) =
12711271
t.add_declaration("make_(t.name())$: (args...: _) -> _ = { return (t.name())$(args...); }");
12721272
}
12731273

1274+
//-----------------------------------------------------------------------
1275+
//
1276+
// generate_expressions - adds expression syntax
1277+
//
1278+
generate_binary_expression: (inout t: meta::type_declaration) =
1279+
{
1280+
1281+
op_name: std::string = t.name().substr(8); // Skip 'Operator'
1282+
1283+
t.add_declaration("(op_name)$: <A, B> (arg_a: Expression<A>, arg_b: Expression<B>) -> _ = BinaryExpression<A, B, (t.name())$>(arg_a, arg_b);");
1284+
t.add_declaration("(op_name)$: <A> (arg_a: Expression<A>, arg_b: double) -> _ = BinaryExpression<A, Constant<double>, (t.name())$>(arg_a, Constant<double>(arg_b));");
1285+
t.add_declaration("(op_name)$: <B> (arg_a: double, arg_b: Expression<B>) -> _ = BinaryExpression<Constant<double>, B, (t.name())$>(Constant<double>(arg_a), arg_b);");
1286+
}
1287+
12741288

12751289
//-----------------------------------------------------------------------
12761290
//
@@ -1359,6 +1373,9 @@ apply_metafunctions: (
13591373
else if name == "maker" {
13601374
maker( rtype );
13611375
}
1376+
else if name == "generate_binary_expression" {
1377+
generate_binary_expression( rtype );
1378+
}
13621379
else {
13631380
error( "unrecognized metafunction name: " + name );
13641381
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)