Skip to content

Commit 0fe38ba

Browse files
committed
Support reflection on namespaces, including the parent namespace
Also add expression[_node]::is_assignment_expression for symmetry, even though currently expression-nodes have no other alternatives (they could grow try-expressions in the future) Cleanup: Remove old autodiff stub code which I think is no longer being used / needed for reference - Max please let me know if that's not so
1 parent d9bfca1 commit 0fe38ba

File tree

10 files changed

+1439
-1963
lines changed

10 files changed

+1439
-1963
lines changed

regression-tests/pure2-function-body-reflection.cpp2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
xyzzy: namespace = {
3+
4+
// This function will be visible as a namespace member while reflecting on xyzzy::test
5+
sample_function_before_type: () = { }
6+
27
test: @sample_traverser type =
38
{
49
one_liner: (a: double, b: double, c: double) = (a + c) * b;
@@ -70,4 +75,9 @@ test: @sample_traverser type =
7075
}
7176
}
7277

78+
// This function will not be visible as a namespace member while reflecting on xyzzy::test
79+
sample_function_after_type: () = { }
80+
81+
}
82+
7383
main: () = { }

regression-tests/test-results/pure2-function-body-reflection.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,79 +9,101 @@
99
#line 1 "pure2-function-body-reflection.cpp2"
1010

1111
#line 2 "pure2-function-body-reflection.cpp2"
12+
namespace xyzzy {
13+
14+
#line 7 "pure2-function-body-reflection.cpp2"
1215
class test;
1316

17+
#line 81 "pure2-function-body-reflection.cpp2"
18+
}
19+
1420

1521
//=== Cpp2 type definitions and function declarations ===========================
1622

1723
#line 1 "pure2-function-body-reflection.cpp2"
1824

1925
#line 2 "pure2-function-body-reflection.cpp2"
26+
namespace xyzzy {
27+
28+
// This function will be visible as a namespace member while reflecting on xyzzy::test
29+
auto sample_function_before_type() -> void;
30+
2031
class test
2132
{
2233
public: [[nodiscard]] static auto one_liner(cpp2::impl::in<double> a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> decltype(auto);
2334
struct return_list_ret { double r; float s; std::string t; };
2435

2536

2637

27-
#line 6 "pure2-function-body-reflection.cpp2"
38+
#line 11 "pure2-function-body-reflection.cpp2"
2839
public: [[nodiscard]] static auto return_list() -> return_list_ret;
2940
using branches_ret = double;
3041

3142

32-
#line 14 "pure2-function-body-reflection.cpp2"
43+
#line 19 "pure2-function-body-reflection.cpp2"
3344
public: [[nodiscard]] static auto branches(cpp2::impl::in<double> a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> branches_ret;
3445

35-
#line 29 "pure2-function-body-reflection.cpp2"
46+
#line 34 "pure2-function-body-reflection.cpp2"
3647
public: static auto binary_ops(double& a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> void;
3748

38-
#line 38 "pure2-function-body-reflection.cpp2"
49+
#line 43 "pure2-function-body-reflection.cpp2"
3950
public: [[nodiscard]] static auto prefix() -> int;
4051

41-
#line 48 "pure2-function-body-reflection.cpp2"
52+
#line 53 "pure2-function-body-reflection.cpp2"
4253
public: static auto postfix(double& a) -> void;
4354

44-
#line 54 "pure2-function-body-reflection.cpp2"
55+
#line 59 "pure2-function-body-reflection.cpp2"
4556
public: [[nodiscard]] static auto qualified_ids() -> auto;
4657

47-
#line 60 "pure2-function-body-reflection.cpp2"
58+
#line 65 "pure2-function-body-reflection.cpp2"
4859
public: static auto loops() -> void;
4960
public: test() = default;
5061
public: test(test const&) = delete; /* No 'that' constructor, suppress copy */
5162
public: auto operator=(test const&) -> void = delete;
5263

5364

54-
#line 71 "pure2-function-body-reflection.cpp2"
65+
#line 76 "pure2-function-body-reflection.cpp2"
5566
};
5667

68+
// This function will not be visible as a namespace member while reflecting on xyzzy::test
69+
auto sample_function_after_type() -> void;
70+
71+
}
72+
5773
auto main() -> int;
5874

5975
//=== Cpp2 function definitions =================================================
6076

6177
#line 1 "pure2-function-body-reflection.cpp2"
6278

63-
#line 4 "pure2-function-body-reflection.cpp2"
79+
#line 2 "pure2-function-body-reflection.cpp2"
80+
namespace xyzzy {
81+
82+
#line 5 "pure2-function-body-reflection.cpp2"
83+
auto sample_function_before_type() -> void{}
84+
85+
#line 9 "pure2-function-body-reflection.cpp2"
6486
[[nodiscard]] auto test::one_liner(cpp2::impl::in<double> a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> decltype(auto) { return (a + c) * b; }
6587

66-
#line 6 "pure2-function-body-reflection.cpp2"
88+
#line 11 "pure2-function-body-reflection.cpp2"
6789
[[nodiscard]] auto test::return_list() -> return_list_ret
6890

6991
{
7092
cpp2::impl::deferred_init<double> r;
7193
cpp2::impl::deferred_init<float> s;
7294
cpp2::impl::deferred_init<std::string> t;
73-
#line 9 "pure2-function-body-reflection.cpp2"
95+
#line 14 "pure2-function-body-reflection.cpp2"
7496
r.construct(42.0);
7597
s.construct(2.71828f);
7698
t.construct("e times pi");
7799
return { std::move(r.value()), std::move(s.value()), std::move(t.value()) }; }
78100

79-
#line 14 "pure2-function-body-reflection.cpp2"
101+
#line 19 "pure2-function-body-reflection.cpp2"
80102
[[nodiscard]] auto test::branches(cpp2::impl::in<double> a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> branches_ret
81103

82104
{
83105
double r {3.14159};
84-
#line 17 "pure2-function-body-reflection.cpp2"
106+
#line 22 "pure2-function-body-reflection.cpp2"
85107
if (true) {
86108
r = r + a;
87109
}
@@ -94,7 +116,7 @@ auto main() -> int;
94116
}return r;
95117
}
96118

97-
#line 29 "pure2-function-body-reflection.cpp2"
119+
#line 34 "pure2-function-body-reflection.cpp2"
98120
auto test::binary_ops(double& a, cpp2::impl::in<double> b, cpp2::impl::in<double> c) -> void
99121
{
100122
a -= b * c + (1 << 2);
@@ -104,7 +126,7 @@ auto main() -> int;
104126
auto z {5 | 6};
105127
}
106128

107-
#line 38 "pure2-function-body-reflection.cpp2"
129+
#line 43 "pure2-function-body-reflection.cpp2"
108130
[[nodiscard]] auto test::prefix() -> int
109131
{
110132
auto a {-1};
@@ -115,21 +137,21 @@ auto main() -> int;
115137
return cpp2::move(a) + cpp2::move(b);
116138
}
117139

118-
#line 48 "pure2-function-body-reflection.cpp2"
140+
#line 53 "pure2-function-body-reflection.cpp2"
119141
auto test::postfix(double& a) -> void
120142
{
121143
auto ptr {&a};
122144
--++*cpp2::impl::assert_not_null(cpp2::move(ptr));
123145
}
124146

125-
#line 54 "pure2-function-body-reflection.cpp2"
147+
#line 59 "pure2-function-body-reflection.cpp2"
126148
[[nodiscard]] auto test::qualified_ids() -> auto
127149
{
128150
std::vector<int> v {1, 2, 3};
129151
return CPP2_UFCS(ssize)(cpp2::move(v));
130152
}
131153

132-
#line 60 "pure2-function-body-reflection.cpp2"
154+
#line 65 "pure2-function-body-reflection.cpp2"
133155
auto test::loops() -> void
134156
{
135157
std::vector v {1, 2, 3};
@@ -142,6 +164,11 @@ auto main() -> int;
142164
do {std::cout << "plugh\n"; } while ( false);
143165
}
144166

145-
#line 73 "pure2-function-body-reflection.cpp2"
167+
#line 79 "pure2-function-body-reflection.cpp2"
168+
auto sample_function_after_type() -> void{}
169+
170+
}
171+
172+
#line 83 "pure2-function-body-reflection.cpp2"
146173
auto main() -> int{}
147174

regression-tests/test-results/pure2-function-body-reflection.cpp2.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pure2-function-body-reflection.cpp2...Type: test
2+
is a member of namespace xyzzy which contains the following names:
3+
sample_function_before_type
24
Declaration: one_liner
35
Function: one_liner
46
Parameters:

regression-tests/test-results/version

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

2-
cppfront compiler v0.8.2 Build A802:2205
2+
cppfront compiler v0.8.2 Build A811:1537
33
SPDX-License-Identifier Apache-2.0 WITH LLVM-exception
44
Copyright (c) 2022-2025 Herb Sutter

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"A802:2205"
1+
"A811:1537"

0 commit comments

Comments
 (0)