File tree 3 files changed +32
-8
lines changed
3 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -1830,10 +1830,14 @@ class cppfront
1830
1830
auto suffix = std::string{};
1831
1831
for (auto const & x : n.ops ) {
1832
1832
assert (x);
1833
- assert (x->type () == lexeme::Not); // should be the only prefix operator
1834
- printer.add_pad_in_this_line (-3 );
1835
- printer.print_cpp2 (" !(" , n.position ());
1836
- suffix += " )" ;
1833
+ if (x->type () == lexeme::Not) {
1834
+ printer.print_cpp2 (" !(" , n.position ());
1835
+ printer.add_pad_in_this_line (-3 );
1836
+ suffix += " )" ;
1837
+ }
1838
+ else {
1839
+ printer.print_cpp2 (*x, x->position ());
1840
+ }
1837
1841
}
1838
1842
assert (n.expr );
1839
1843
emit (*n.expr );
Original file line number Diff line number Diff line change @@ -95,6 +95,18 @@ enum class lexeme : std::int8_t {
95
95
Identifier
96
96
};
97
97
98
+ auto is_literal (lexeme l) {
99
+ switch (l) {
100
+ break ;case lexeme::FloatLiteral:
101
+ case lexeme::BinaryLiteral:
102
+ case lexeme::DecimalLiteral:
103
+ case lexeme::HexadecimalLiteral:
104
+ case lexeme::StringLiteral:
105
+ case lexeme::CharacterLiteral: return true ;
106
+ break ;default : return false ;
107
+ }
108
+ }
109
+
98
110
// TODO: Remove the duplication above/below with a variadic macro,
99
111
// but for now it's simpler just to write it out
100
112
Original file line number Diff line number Diff line change @@ -37,7 +37,14 @@ auto violates_lifetime_safety = false;
37
37
// G
38
38
auto is_prefix_operator (lexeme l) -> bool
39
39
{
40
- return l == lexeme::Not;
40
+ switch (l) {
41
+ break ;case lexeme::Not:
42
+ case lexeme::Minus:
43
+ case lexeme::Plus:
44
+ return true ;
45
+ break ;default :
46
+ return false ;
47
+ }
41
48
}
42
49
43
50
@@ -1389,9 +1396,10 @@ class parser
1389
1396
curr ().type () == lexeme::Dot
1390
1397
)
1391
1398
{
1392
- // * & and ~ can't be a unary operator if followed by ( or identifier
1393
- if ((curr ().type () == lexeme::Multiply || curr ().type () == lexeme::Ampersand || curr ().type () == lexeme::Tilde) &&
1394
- (peek (1 )->type () == lexeme::LeftParen || peek (1 )->type () == lexeme::Identifier))
1399
+ // * and & can't be a unary operator if followed by a (, identifier, or literal
1400
+ if ((curr ().type () == lexeme::Multiply || curr ().type () == lexeme::Ampersand) &&
1401
+ peek (1 ) &&
1402
+ (peek (1 )->type () == lexeme::LeftParen || peek (1 )->type () == lexeme::Identifier || is_literal (peek (1 )->type ())))
1395
1403
{
1396
1404
break ;
1397
1405
}
You can’t perform that action at this time.
0 commit comments