From 6e0aa656257633f9ffbd00803d131f8df7a6227d Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 1 Nov 2020 12:50:32 +0100 Subject: [PATCH] Fixes memory leaks in ParsedVirtPropStatement. --- src/Parser/Statements/ParsedStatement.hpp | 18 ++++++++++++------ tests/ParserTests/ParserIntegrationTests.cpp | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Parser/Statements/ParsedStatement.hpp b/src/Parser/Statements/ParsedStatement.hpp index 1830150..7362c28 100644 --- a/src/Parser/Statements/ParsedStatement.hpp +++ b/src/Parser/Statements/ParsedStatement.hpp @@ -211,34 +211,40 @@ namespace MalachScript::Parser { _setStatement(setStatement) {} [[nodiscard]] inline AccessModifier GetAccess() const noexcept { return _access; } - [[nodiscard]] inline const ParsedStatement* GetReturnType() const noexcept { return _returnType; } + [[nodiscard]] inline const std::unique_ptr& GetReturnType() const noexcept { + return _returnType; + } [[nodiscard]] inline bool IsReturnTypeRef() const noexcept { return _isReturnTypeRef; } [[nodiscard]] inline const Identifier& GetIdentifier() const noexcept { return _identifier; } [[nodiscard]] inline bool HasGet() const noexcept { return _hasGet; } [[nodiscard]] inline bool IsGetConst() const noexcept { return _getConst; } [[nodiscard]] inline FuncAttr GetGetFuncAttr() const noexcept { return _getAttr; } - [[nodiscard]] inline const ParsedStatement* GetGetStatement() const noexcept { return _getStatement; } + [[nodiscard]] inline const std::unique_ptr& GetGetStatement() const noexcept { + return _getStatement; + } [[nodiscard]] inline bool HasSet() const noexcept { return _hasSet; } [[nodiscard]] inline bool IsSetConst() const noexcept { return _setConst; } [[nodiscard]] inline FuncAttr GetSetFuncAttr() const noexcept { return _setAttr; } - [[nodiscard]] inline const ParsedStatement* GetSetStatement() const noexcept { return _setStatement; } + [[nodiscard]] inline const std::unique_ptr& GetSetStatement() const noexcept { + return _setStatement; + } private: AccessModifier _access; - const ParsedStatement* _returnType; + std::unique_ptr _returnType; bool _isReturnTypeRef; Identifier _identifier; bool _hasGet = false; bool _getConst = false; FuncAttr _getAttr = FuncAttr::None; - const ParsedStatement* _getStatement; + std::unique_ptr _getStatement; bool _hasSet = false; bool _setConst = false; FuncAttr _setAttr = FuncAttr::None; - const ParsedStatement* _setStatement; + std::unique_ptr _setStatement; }; } diff --git a/tests/ParserTests/ParserIntegrationTests.cpp b/tests/ParserTests/ParserIntegrationTests.cpp index 10e5b3a..054306d 100644 --- a/tests/ParserTests/ParserIntegrationTests.cpp +++ b/tests/ParserTests/ParserIntegrationTests.cpp @@ -43,4 +43,8 @@ PARSE_TEST("Parse class with virtprop", "class foobar { private bool foo { get; auto virtPropStatement = dynamic_cast(firstClassStatement); REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Private); REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo"); + REQUIRE(virtPropStatement->HasGet()); + REQUIRE(virtPropStatement->HasSet()); + REQUIRE(virtPropStatement->GetGetStatement() == nullptr); + REQUIRE(virtPropStatement->GetSetStatement() == nullptr); }) \ No newline at end of file