mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibCpp: Allow virtual destructors
This commit is contained in:
parent
c866a56f07
commit
3c1422d774
1 changed files with 14 additions and 2 deletions
|
@ -1311,7 +1311,7 @@ Vector<StringView> Parser::parse_function_qualifiers()
|
||||||
if (token.type() != Token::Type::Keyword)
|
if (token.type() != Token::Type::Keyword)
|
||||||
break;
|
break;
|
||||||
auto text = text_of_token(token);
|
auto text = text_of_token(token);
|
||||||
if (text == "static" || text == "inline" || text == "extern") {
|
if (text == "static" || text == "inline" || text == "extern" || text == "virtual") {
|
||||||
qualifiers.append(text);
|
qualifiers.append(text);
|
||||||
consume();
|
consume();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1595,6 +1595,9 @@ bool Parser::match_destructor(const StringView& class_name)
|
||||||
save_state();
|
save_state();
|
||||||
ScopeGuard state_guard = [this] { load_state(); };
|
ScopeGuard state_guard = [this] { load_state(); };
|
||||||
|
|
||||||
|
if (match_keyword("virtual"))
|
||||||
|
consume();
|
||||||
|
|
||||||
if (!match(Token::Type::Tilde))
|
if (!match(Token::Type::Tilde))
|
||||||
return false;
|
return false;
|
||||||
consume();
|
consume();
|
||||||
|
@ -1611,13 +1614,19 @@ bool Parser::match_destructor(const StringView& class_name)
|
||||||
|
|
||||||
while (consume().type() != Token::Type::RightParen && !eof()) { };
|
while (consume().type() != Token::Type::RightParen && !eof()) { };
|
||||||
|
|
||||||
|
if (match_keyword("override"))
|
||||||
|
consume();
|
||||||
|
|
||||||
return (peek(Token::Type::Semicolon).has_value() || peek(Token::Type::LeftCurly).has_value());
|
return (peek(Token::Type::Semicolon).has_value() || peek(Token::Type::LeftCurly).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::parse_constructor_or_destructor_impl(FunctionDeclaration& func, CtorOrDtor type)
|
void Parser::parse_constructor_or_destructor_impl(FunctionDeclaration& func, CtorOrDtor type)
|
||||||
{
|
{
|
||||||
if (type == CtorOrDtor::Dtor)
|
if (type == CtorOrDtor::Dtor) {
|
||||||
|
if (match_keyword("virtual"))
|
||||||
|
func.set_qualifiers({ consume().text() });
|
||||||
consume(Token::Type::Tilde);
|
consume(Token::Type::Tilde);
|
||||||
|
}
|
||||||
|
|
||||||
auto name_token = consume();
|
auto name_token = consume();
|
||||||
if (name_token.type() != Token::Type::Identifier && name_token.type() != Token::Type::KnownType) {
|
if (name_token.type() != Token::Type::Identifier && name_token.type() != Token::Type::KnownType) {
|
||||||
|
@ -1636,6 +1645,9 @@ void Parser::parse_constructor_or_destructor_impl(FunctionDeclaration& func, Cto
|
||||||
|
|
||||||
consume(Token::Type::RightParen);
|
consume(Token::Type::RightParen);
|
||||||
|
|
||||||
|
if (type == CtorOrDtor::Dtor && match_keyword("override"))
|
||||||
|
consume();
|
||||||
|
|
||||||
// TODO: Parse =default, =delete.
|
// TODO: Parse =default, =delete.
|
||||||
|
|
||||||
RefPtr<FunctionDefinition> body;
|
RefPtr<FunctionDefinition> body;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue