@@ -125,10 +125,9 @@ struct template_argument;
125125
126126struct primary_expression_node
127127{
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 };
129129 std::variant<
130130 std::monostate,
131- token const *,
132131 std::unique_ptr<expression_list_node>,
133132 std::unique_ptr<id_expression_node>,
134133 std::unique_ptr<declaration_node>,
@@ -150,6 +149,9 @@ struct primary_expression_node
150149 auto is_identifier () const
151150 -> bool;
152151
152+ auto get_identifier () const
153+ -> token const *;
154+
153155 auto is_id_expression () const
154156 -> bool;
155157
@@ -272,6 +274,9 @@ struct prefix_expression_node
272274 auto is_identifier () const
273275 -> bool;
274276
277+ auto get_identifier () const
278+ -> token const *;
279+
275280 auto is_id_expression () const
276281 -> bool;
277282
@@ -380,6 +385,16 @@ struct binary_expression_node
380385 return terms.empty () && expr->is_identifier ();
381386 }
382387
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+
383398 auto is_id_expression () const
384399 -> bool
385400 {
@@ -589,6 +604,12 @@ struct expression_node
589604 return expr->is_identifier ();
590605 }
591606
607+ auto get_identifier () const
608+ -> token const *
609+ {
610+ return expr->get_identifier ();
611+ }
612+
592613 auto is_id_expression () const
593614 -> bool
594615 {
@@ -755,6 +776,12 @@ struct expression_list_node
755776 return ret;
756777 }
757778
779+ auto get_expressions () const
780+ -> std::vector<term> const &
781+ {
782+ return expressions;
783+ }
784+
758785 auto to_string () const
759786 -> std::string
760787 {
@@ -797,12 +824,6 @@ struct expression_list_node
797824 }
798825};
799826
800- auto primary_expression_node::is_identifier () const
801- -> bool
802- {
803- return expr.index () == identifier;
804- }
805-
806827auto primary_expression_node::is_id_expression () const
807828 -> bool
808829{
@@ -975,6 +996,16 @@ struct postfix_expression_node
975996 return ops.empty () && expr->is_identifier ();
976997 }
977998
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+
9781009 auto is_id_expression () const
9791010 -> bool
9801011 {
@@ -1069,6 +1100,16 @@ auto prefix_expression_node::is_identifier() const
10691100 return ops.empty () && expr->is_identifier ();
10701101}
10711102
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+
10721113auto prefix_expression_node::is_id_expression () const
10731114 -> bool
10741115{
@@ -1252,6 +1293,22 @@ struct unqualified_id_node
12521293 return {};
12531294 }
12541295
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+
12551312 auto to_string () const
12561313 -> std::string;
12571314
@@ -1573,6 +1630,16 @@ struct is_as_expression_node
15731630 return ops.empty () && expr->is_identifier ();
15741631 }
15751632
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+
15761643 auto is_id_expression () const
15771644 -> bool
15781645 {
@@ -1719,6 +1786,26 @@ struct id_expression_node
17191786 return std::get<qualified>(id)->template_arguments ();
17201787 }
17211788
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+
17221809 auto is_fold_expression () const
17231810 -> bool
17241811 {
@@ -1786,6 +1873,28 @@ struct id_expression_node
17861873};
17871874
17881875
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+
17891898postfix_expression_node::~postfix_expression_node ()
17901899{
17911900 if (cap_grp) {
@@ -1813,8 +1922,6 @@ auto primary_expression_node::is_fold_expression() const
18131922 // This is a fold-expression if any subexpression has
18141923 // has an identifier named "..."
18151924 switch (expr.index ()) {
1816- break ;case identifier:
1817- return *std::get<identifier>(expr) == " ..." ;
18181925 break ;case expression_list:
18191926 return expression_list_is_fold_expression;
18201927 break ;case id_expression:
@@ -4659,10 +4766,7 @@ auto primary_expression_node::template_arguments() const
46594766auto primary_expression_node::get_token () const
46604767 -> token const *
46614768{
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) {
46664770 return std::get<id_expression>(expr)->get_token ();
46674771 }
46684772 else if (expr.index () == literal) {
@@ -4682,12 +4786,6 @@ auto primary_expression_node::position() const
46824786 break ;case empty:
46834787 return { 0 , 0 };
46844788
4685- break ;case identifier: {
4686- auto const & s = std::get<identifier>(expr);
4687- assert (s);
4688- return s->position ();
4689- }
4690-
46914789 break ;case expression_list: {
46924790 auto const & s = std::get<expression_list>(expr);
46934791 assert (s);
@@ -4729,7 +4827,6 @@ auto primary_expression_node::visit(auto& v, int depth)
47294827 -> void
47304828{
47314829 v.start (*this , depth);
4732- try_visit<identifier >(expr, v, depth);
47334830 try_visit<expression_list>(expr, v, depth);
47344831 try_visit<id_expression >(expr, v, depth);
47354832 try_visit<declaration >(expr, v, depth);
@@ -5027,12 +5124,6 @@ auto primary_expression_node::to_string() const
50275124 break ; case empty:
50285125 return {};
50295126
5030- break ; case identifier: {
5031- auto const & s = std::get<identifier>(expr);
5032- assert (s);
5033- return s->to_string ();
5034- }
5035-
50365127 break ; case expression_list: {
50375128 auto const & s = std::get<expression_list>(expr);
50385129 assert (s);
@@ -5119,7 +5210,6 @@ auto pretty_print_visualize(primary_expression_node const& n, int indent)
51195210{
51205211 auto ret = std::string{};
51215212
5122- ret += try_pretty_print_visualize<primary_expression_node::identifier >(n.expr , indent);
51235213 ret += try_pretty_print_visualize<primary_expression_node::expression_list>(n.expr , indent);
51245214 ret += try_pretty_print_visualize<primary_expression_node::id_expression >(n.expr , indent);
51255215 ret += try_pretty_print_visualize<primary_expression_node::declaration >(n.expr , indent);
0 commit comments