@@ -125,10 +125,9 @@ struct template_argument;
125
125
126
126
struct primary_expression_node
127
127
{
128
- enum active : u8 { empty=0 , identifier, expression_list, id_expression, declaration, inspect, literal };
128
+ enum active : u8 { empty=0 , expression_list, id_expression, declaration, inspect, literal };
129
129
std::variant<
130
130
std::monostate,
131
- token const *,
132
131
std::unique_ptr<expression_list_node>,
133
132
std::unique_ptr<id_expression_node>,
134
133
std::unique_ptr<declaration_node>,
@@ -150,6 +149,9 @@ struct primary_expression_node
150
149
auto is_identifier () const
151
150
-> bool;
152
151
152
+ auto get_identifier () const
153
+ -> token const *;
154
+
153
155
auto is_id_expression () const
154
156
-> bool;
155
157
@@ -272,6 +274,9 @@ struct prefix_expression_node
272
274
auto is_identifier () const
273
275
-> bool;
274
276
277
+ auto get_identifier () const
278
+ -> token const *;
279
+
275
280
auto is_id_expression () const
276
281
-> bool;
277
282
@@ -380,6 +385,16 @@ struct binary_expression_node
380
385
return terms.empty () && expr->is_identifier ();
381
386
}
382
387
388
+ auto get_identifier () const
389
+ -> token const *
390
+ {
391
+ if (!terms.empty ()) {
392
+ return nullptr ;
393
+ }
394
+ // Else
395
+ return expr->get_identifier ();
396
+ }
397
+
383
398
auto is_id_expression () const
384
399
-> bool
385
400
{
@@ -589,6 +604,12 @@ struct expression_node
589
604
return expr->is_identifier ();
590
605
}
591
606
607
+ auto get_identifier () const
608
+ -> token const *
609
+ {
610
+ return expr->get_identifier ();
611
+ }
612
+
592
613
auto is_id_expression () const
593
614
-> bool
594
615
{
@@ -755,6 +776,12 @@ struct expression_list_node
755
776
return ret;
756
777
}
757
778
779
+ auto get_expressions () const
780
+ -> std::vector<term> const &
781
+ {
782
+ return expressions;
783
+ }
784
+
758
785
auto to_string () const
759
786
-> std::string
760
787
{
@@ -797,12 +824,6 @@ struct expression_list_node
797
824
}
798
825
};
799
826
800
- auto primary_expression_node::is_identifier () const
801
- -> bool
802
- {
803
- return expr.index () == identifier;
804
- }
805
-
806
827
auto primary_expression_node::is_id_expression () const
807
828
-> bool
808
829
{
@@ -975,6 +996,16 @@ struct postfix_expression_node
975
996
return ops.empty () && expr->is_identifier ();
976
997
}
977
998
999
+ auto get_identifier () const
1000
+ -> token const *
1001
+ {
1002
+ if (!ops.empty ()) {
1003
+ return nullptr ;
1004
+ }
1005
+ // Else
1006
+ return expr->get_identifier ();
1007
+ }
1008
+
978
1009
auto is_id_expression () const
979
1010
-> bool
980
1011
{
@@ -1069,6 +1100,16 @@ auto prefix_expression_node::is_identifier() const
1069
1100
return ops.empty () && expr->is_identifier ();
1070
1101
}
1071
1102
1103
+ auto prefix_expression_node::get_identifier () const
1104
+ -> token const *
1105
+ {
1106
+ if (!ops.empty ()) {
1107
+ return nullptr ;
1108
+ }
1109
+ // Else
1110
+ return expr->get_identifier ();
1111
+ }
1112
+
1072
1113
auto prefix_expression_node::is_id_expression () const
1073
1114
-> bool
1074
1115
{
@@ -1252,6 +1293,22 @@ struct unqualified_id_node
1252
1293
return {};
1253
1294
}
1254
1295
1296
+ auto is_identifier () const
1297
+ -> bool
1298
+ {
1299
+ return template_args.empty ();
1300
+ }
1301
+
1302
+ auto get_identifier () const
1303
+ -> token const *
1304
+ {
1305
+ if (is_identifier ()) {
1306
+ return identifier;
1307
+ }
1308
+ // Else
1309
+ return nullptr ;
1310
+ }
1311
+
1255
1312
auto to_string () const
1256
1313
-> std::string;
1257
1314
@@ -1573,6 +1630,16 @@ struct is_as_expression_node
1573
1630
return ops.empty () && expr->is_identifier ();
1574
1631
}
1575
1632
1633
+ auto get_identifier () const
1634
+ -> token const *
1635
+ {
1636
+ if (!ops.empty ()) {
1637
+ return nullptr ;
1638
+ }
1639
+ // Else
1640
+ return expr->get_identifier ();
1641
+ }
1642
+
1576
1643
auto is_id_expression () const
1577
1644
-> bool
1578
1645
{
@@ -1719,6 +1786,26 @@ struct id_expression_node
1719
1786
return std::get<qualified>(id)->template_arguments ();
1720
1787
}
1721
1788
1789
+ auto is_identifier () const
1790
+ -> bool
1791
+ {
1792
+ if (auto puid = std::get_if<unqualified>(&id)) {
1793
+ return (*puid)->is_identifier ();
1794
+ }
1795
+ // Else
1796
+ return false ;
1797
+ }
1798
+
1799
+ auto get_identifier () const
1800
+ -> token const *
1801
+ {
1802
+ if (auto puid = std::get_if<unqualified>(&id)) {
1803
+ return (*puid)->get_identifier ();
1804
+ }
1805
+ // Else
1806
+ return nullptr ;
1807
+ }
1808
+
1722
1809
auto is_fold_expression () const
1723
1810
-> bool
1724
1811
{
@@ -1786,6 +1873,28 @@ struct id_expression_node
1786
1873
};
1787
1874
1788
1875
1876
+ auto primary_expression_node::is_identifier () const
1877
+ -> bool
1878
+ {
1879
+ if (auto pid = std::get_if<id_expression>(&expr)) {
1880
+ return (*pid)->is_identifier ();
1881
+ }
1882
+ // Else
1883
+ return false ;
1884
+ }
1885
+
1886
+
1887
+ auto primary_expression_node::get_identifier () const
1888
+ -> token const *
1889
+ {
1890
+ if (auto pid = std::get_if<id_expression>(&expr)) {
1891
+ return (*pid)->get_identifier ();
1892
+ }
1893
+ // Else
1894
+ return nullptr ;
1895
+ }
1896
+
1897
+
1789
1898
postfix_expression_node::~postfix_expression_node ()
1790
1899
{
1791
1900
if (cap_grp) {
@@ -1813,8 +1922,6 @@ auto primary_expression_node::is_fold_expression() const
1813
1922
// This is a fold-expression if any subexpression has
1814
1923
// has an identifier named "..."
1815
1924
switch (expr.index ()) {
1816
- break ;case identifier:
1817
- return *std::get<identifier>(expr) == " ..." ;
1818
1925
break ;case expression_list:
1819
1926
return expression_list_is_fold_expression;
1820
1927
break ;case id_expression:
@@ -4659,10 +4766,7 @@ auto primary_expression_node::template_arguments() const
4659
4766
auto primary_expression_node::get_token () const
4660
4767
-> token const *
4661
4768
{
4662
- if (expr.index () == identifier) {
4663
- return std::get<identifier>(expr);
4664
- }
4665
- else if (expr.index () == id_expression) {
4769
+ if (expr.index () == id_expression) {
4666
4770
return std::get<id_expression>(expr)->get_token ();
4667
4771
}
4668
4772
else if (expr.index () == literal) {
@@ -4682,12 +4786,6 @@ auto primary_expression_node::position() const
4682
4786
break ;case empty:
4683
4787
return { 0 , 0 };
4684
4788
4685
- break ;case identifier: {
4686
- auto const & s = std::get<identifier>(expr);
4687
- assert (s);
4688
- return s->position ();
4689
- }
4690
-
4691
4789
break ;case expression_list: {
4692
4790
auto const & s = std::get<expression_list>(expr);
4693
4791
assert (s);
@@ -4729,7 +4827,6 @@ auto primary_expression_node::visit(auto& v, int depth)
4729
4827
-> void
4730
4828
{
4731
4829
v.start (*this , depth);
4732
- try_visit<identifier >(expr, v, depth);
4733
4830
try_visit<expression_list>(expr, v, depth);
4734
4831
try_visit<id_expression >(expr, v, depth);
4735
4832
try_visit<declaration >(expr, v, depth);
@@ -5027,12 +5124,6 @@ auto primary_expression_node::to_string() const
5027
5124
break ; case empty:
5028
5125
return {};
5029
5126
5030
- break ; case identifier: {
5031
- auto const & s = std::get<identifier>(expr);
5032
- assert (s);
5033
- return s->to_string ();
5034
- }
5035
-
5036
5127
break ; case expression_list: {
5037
5128
auto const & s = std::get<expression_list>(expr);
5038
5129
assert (s);
@@ -5119,7 +5210,6 @@ auto pretty_print_visualize(primary_expression_node const& n, int indent)
5119
5210
{
5120
5211
auto ret = std::string{};
5121
5212
5122
- ret += try_pretty_print_visualize<primary_expression_node::identifier >(n.expr , indent);
5123
5213
ret += try_pretty_print_visualize<primary_expression_node::expression_list>(n.expr , indent);
5124
5214
ret += try_pretty_print_visualize<primary_expression_node::id_expression >(n.expr , indent);
5125
5215
ret += try_pretty_print_visualize<primary_expression_node::declaration >(n.expr , indent);
0 commit comments