Skip to content

Commit 8bd0392

Browse files
committed
chore: Clean up parsing of sizeof expressions
1 parent 11ab097 commit 8bd0392

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Diff for: src/parser/cxx/parser.cc

+14-8
Original file line numberDiff line numberDiff line change
@@ -2085,14 +2085,20 @@ auto Parser::parse_sizeof_expression(ExpressionAST*& yyast) -> bool {
20852085
return true;
20862086
}
20872087

2088-
const auto after_sizeof_op = currentLocation();
2088+
auto lookat_sizeof_type_id = [&] {
2089+
LookaheadParser lookahead{this};
20892090

2090-
SourceLocation lparenLoc;
2091-
TypeIdAST* typeId = nullptr;
2092-
SourceLocation rparenLoc;
2091+
SourceLocation lparenLoc;
2092+
if (!match(TokenKind::T_LPAREN, lparenLoc)) return false;
2093+
2094+
TypeIdAST* typeId = nullptr;
2095+
if (!parse_type_id(typeId)) return false;
2096+
2097+
SourceLocation rparenLoc;
2098+
if (!match(TokenKind::T_RPAREN, rparenLoc)) return false;
2099+
2100+
lookahead.commit();
20932101

2094-
if (match(TokenKind::T_LPAREN, lparenLoc) && parse_type_id(typeId) &&
2095-
match(TokenKind::T_RPAREN, rparenLoc)) {
20962102
auto ast = new (pool) SizeofTypeExpressionAST();
20972103
yyast = ast;
20982104

@@ -2102,9 +2108,9 @@ auto Parser::parse_sizeof_expression(ExpressionAST*& yyast) -> bool {
21022108
ast->rparenLoc = rparenLoc;
21032109

21042110
return true;
2105-
}
2111+
};
21062112

2107-
rewind(after_sizeof_op);
2113+
if (lookat_sizeof_type_id()) return true;
21082114

21092115
auto ast = new (pool) SizeofExpressionAST();
21102116
yyast = ast;

0 commit comments

Comments
 (0)