1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibCpp: Add support for parsing function types

This makes it work with types like `Function<T(U, V)>`.
This commit is contained in:
Ali Mohammad Pur 2021-07-28 06:04:51 +04:30 committed by Andreas Kling
parent b3cbe14569
commit 5f66874ea0
3 changed files with 66 additions and 0 deletions

View file

@ -1255,7 +1255,19 @@ NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
type = ref;
}
if (peek().type() == Token::Type::LeftParen) {
consume();
auto fn_type = create_ast_node<FunctionType>(parent, type->start(), position());
fn_type->set_return_type(*type);
type->set_parent(*fn_type);
if (auto parameters = parse_parameter_list(*type); parameters.has_value())
fn_type->set_parameters(parameters.release_value());
consume(Token::Type::RightParen);
type = fn_type;
}
type->set_end(position());
return type;
}