Skip to content

Commit 131df86

Browse files
committed
Add as_expression_list to reflection APIs
Style note: I'm currently trying to follow the pattern of choosing ".get_Y" vs. ".as_Y" names as follows... "get": X::is_Y / X::get_Y pairs - when Y is conceptually "NOT all of" the X - for example, expression_statement::get_expression because even though the expression is most of the statement the expression-statement contains that extra `;` and is at a different conceptual layer "as": X::is_Y / X::as_Y pairs - when Y is conceptually "all of" the X - for example, statement::as_expression_statement because it's really still the whole statement - with the idea that this could legitimately become an actual `as` operator I may not be 100% consistent on that right now, but I think the current API is pretty close to that
1 parent 146c783 commit 131df86

File tree

5 files changed

+655
-580
lines changed

5 files changed

+655
-580
lines changed

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 A427:1507
2+
cppfront compiler v0.8.2 Build A427:1609
33
SPDX-License-Identifier Apache-2.0 WITH LLVM-exception
44
Copyright (c) 2022-2024 Herb Sutter

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"A427:1507"
1+
"A427:1609"

source/parse.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ struct primary_expression_node
161161
auto is_expression_list() const
162162
-> bool;
163163

164+
auto get_expression_list()
165+
-> expression_list_node*;
166+
164167
auto get_expression_list() const
165168
-> expression_list_node const*;
166169

@@ -286,6 +289,9 @@ struct prefix_expression_node
286289
auto is_expression_list() const
287290
-> bool;
288291

292+
auto get_expression_list()
293+
-> expression_list_node*;
294+
289295
auto get_expression_list() const
290296
-> expression_list_node const*;
291297

@@ -413,6 +419,15 @@ struct binary_expression_node
413419
return terms.empty() && expr->is_expression_list();
414420
}
415421

422+
auto get_expression_list()
423+
-> expression_list_node*
424+
{
425+
if (is_expression_list()) {
426+
return expr->get_expression_list();
427+
}
428+
return {};
429+
}
430+
416431
auto get_expression_list() const
417432
-> expression_list_node const*
418433
{
@@ -628,6 +643,15 @@ struct expression_node
628643
return expr->is_expression_list();
629644
}
630645

646+
auto get_expression_list()
647+
-> expression_list_node *
648+
{
649+
if (is_expression_list()) {
650+
return expr->get_expression_list();
651+
}
652+
return {};
653+
}
654+
631655
auto get_expression_list() const
632656
-> expression_list_node const*
633657
{
@@ -836,6 +860,15 @@ auto primary_expression_node::is_expression_list() const
836860
return expr.index() == expression_list;
837861
}
838862

863+
auto primary_expression_node::get_expression_list()
864+
-> expression_list_node *
865+
{
866+
if (is_expression_list()) {
867+
return std::get<expression_list>(expr).get();
868+
}
869+
return {};
870+
}
871+
839872
auto primary_expression_node::get_expression_list() const
840873
-> expression_list_node const*
841874
{
@@ -1035,6 +1068,15 @@ struct postfix_expression_node
10351068
return ops.empty() && expr->is_expression_list();
10361069
}
10371070

1071+
auto get_expression_list()
1072+
-> expression_list_node *
1073+
{
1074+
if (is_expression_list()) {
1075+
return expr->get_expression_list();
1076+
}
1077+
return {};
1078+
}
1079+
10381080
auto get_expression_list() const
10391081
-> expression_list_node const*
10401082
{
@@ -1128,6 +1170,15 @@ auto prefix_expression_node::is_expression_list() const
11281170
return ops.empty() && expr->is_expression_list();
11291171
}
11301172

1173+
auto prefix_expression_node::get_expression_list()
1174+
-> expression_list_node *
1175+
{
1176+
if (is_expression_list()) {
1177+
return expr->get_expression_list();
1178+
}
1179+
return {};
1180+
}
1181+
11311182
auto prefix_expression_node::get_expression_list() const
11321183
-> expression_list_node const*
11331184
{
@@ -1658,6 +1709,15 @@ struct is_as_expression_node
16581709
return ops.empty() && expr->is_expression_list();
16591710
}
16601711

1712+
auto get_expression_list()
1713+
-> expression_list_node *
1714+
{
1715+
if (is_expression_list()) {
1716+
return expr->get_expression_list();
1717+
}
1718+
return {};
1719+
}
1720+
16611721
auto get_expression_list() const
16621722
-> expression_list_node const*
16631723
{

0 commit comments

Comments
 (0)