mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
LibCpp: Parse sizeof() expression
This commit is contained in:
parent
8bcf5daf3f
commit
fc503b1368
4 changed files with 44 additions and 1 deletions
|
@ -447,6 +447,9 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression(ASTNode& parent)
|
|||
if (match_cpp_cast_expression())
|
||||
return parse_cpp_cast_expression(parent);
|
||||
|
||||
if(match_sizeof_expression())
|
||||
return parse_sizeof_expression(parent);
|
||||
|
||||
if (match_name()) {
|
||||
if (match_function_call() != TemplatizedMatchResult::NoMatch)
|
||||
return parse_function_call(parent);
|
||||
|
@ -847,7 +850,8 @@ bool Parser::match_expression()
|
|||
return match_literal()
|
||||
|| token_type == Token::Type::Identifier
|
||||
|| match_unary_expression()
|
||||
|| match_cpp_cast_expression();
|
||||
|| match_cpp_cast_expression()
|
||||
|| match_sizeof_expression();
|
||||
}
|
||||
|
||||
bool Parser::eof() const
|
||||
|
@ -1399,4 +1403,20 @@ NonnullRefPtr<CppCastExpression> Parser::parse_cpp_cast_expression(ASTNode& pare
|
|||
return cast_expression;
|
||||
}
|
||||
|
||||
bool Parser::match_sizeof_expression()
|
||||
{
|
||||
return match_keyword("sizeof");
|
||||
}
|
||||
|
||||
NonnullRefPtr<SizeofExpression> Parser::parse_sizeof_expression(ASTNode& parent)
|
||||
{
|
||||
auto exp = create_ast_node<SizeofExpression>(parent, position(), {});
|
||||
consume(Token::Type::Keyword);
|
||||
consume(Token::Type::LeftParen);
|
||||
exp->m_type = parse_type(parent);
|
||||
consume(Token::Type::RightParen);
|
||||
exp->set_end(position());
|
||||
return exp;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue