diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-28 05:14:03 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-02 01:03:59 +0200 |
commit | 3c1422d774f2b18d687a276d5ca1a459ed60b8e3 (patch) | |
tree | 6150af0b69b27131ec14031a070f266256a02560 /Userland/Libraries | |
parent | c866a56f078a5f6151d67670a04eab9475a0be49 (diff) | |
download | serenity-3c1422d774f2b18d687a276d5ca1a459ed60b8e3.zip |
LibCpp: Allow virtual destructors
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index fd3eba2600..c3a630f0db 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -1311,7 +1311,7 @@ Vector<StringView> Parser::parse_function_qualifiers() if (token.type() != Token::Type::Keyword) break; 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); consume(); } else { @@ -1595,6 +1595,9 @@ bool Parser::match_destructor(const StringView& class_name) save_state(); ScopeGuard state_guard = [this] { load_state(); }; + if (match_keyword("virtual")) + consume(); + if (!match(Token::Type::Tilde)) return false; consume(); @@ -1611,13 +1614,19 @@ bool Parser::match_destructor(const StringView& class_name) 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()); } 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); + } auto name_token = consume(); 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); + if (type == CtorOrDtor::Dtor && match_keyword("override")) + consume(); + // TODO: Parse =default, =delete. RefPtr<FunctionDefinition> body; |