diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp index 8b8a42496..5dbc710c2 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp @@ -19,12 +19,12 @@ namespace hex::pl { class ASTNodeArrayVariableDecl : public ASTNode, public Attributable { public: - ASTNodeArrayVariableDecl(std::string name, std::unique_ptr &&type, std::unique_ptr &&size, std::unique_ptr &&placementOffset = {}) + ASTNodeArrayVariableDecl(std::string name, std::shared_ptr type, std::unique_ptr &&size, std::unique_ptr &&placementOffset = {}) : ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_size(std::move(size)), m_placementOffset(std::move(placementOffset)) { } ASTNodeArrayVariableDecl(const ASTNodeArrayVariableDecl &other) : ASTNode(other), Attributable(other) { this->m_name = other.m_name; - this->m_type = other.m_type->clone(); + this->m_type = other.m_type; if (other.m_size != nullptr) this->m_size = other.m_size->clone(); else @@ -81,7 +81,7 @@ namespace hex::pl { private: std::string m_name; - std::unique_ptr m_type; + std::shared_ptr m_type; std::unique_ptr m_size; std::unique_ptr m_placementOffset; diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_pointer_variable_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_pointer_variable_decl.hpp index 3ab071cce..796b925e4 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_pointer_variable_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_pointer_variable_decl.hpp @@ -10,13 +10,13 @@ namespace hex::pl { class ASTNodePointerVariableDecl : public ASTNode, public Attributable { public: - ASTNodePointerVariableDecl(std::string name, std::shared_ptr &&type, std::shared_ptr &&sizeType, std::unique_ptr &&placementOffset = nullptr) + ASTNodePointerVariableDecl(std::string name, std::shared_ptr type, std::shared_ptr sizeType, std::unique_ptr &&placementOffset = nullptr) : ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_sizeType(std::move(sizeType)), m_placementOffset(std::move(placementOffset)) { } ASTNodePointerVariableDecl(const ASTNodePointerVariableDecl &other) : ASTNode(other), Attributable(other) { this->m_name = other.m_name; - this->m_type = other.m_type->clone(); - this->m_sizeType = other.m_sizeType->clone(); + this->m_type = other.m_type; + this->m_sizeType = other.m_sizeType; if (other.m_placementOffset != nullptr) this->m_placementOffset = other.m_placementOffset->clone(); @@ -29,8 +29,8 @@ namespace hex::pl { } [[nodiscard]] const std::string &getName() const { return this->m_name; } - [[nodiscard]] constexpr const std::shared_ptr &getType() const { return this->m_type; } - [[nodiscard]] constexpr const std::shared_ptr &getSizeType() const { return this->m_sizeType; } + [[nodiscard]] constexpr const std::shared_ptr &getType() const { return this->m_type; } + [[nodiscard]] constexpr const std::shared_ptr &getSizeType() const { return this->m_sizeType; } [[nodiscard]] constexpr const std::unique_ptr &getPlacementOffset() const { return this->m_placementOffset; } [[nodiscard]] std::vector> createPatterns(Evaluator *evaluator) const override { @@ -87,8 +87,8 @@ namespace hex::pl { private: std::string m_name; - std::shared_ptr m_type; - std::shared_ptr m_sizeType; + std::shared_ptr m_type; + std::shared_ptr m_sizeType; std::unique_ptr m_placementOffset; }; diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp index 39b35c4a3..7661e6563 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp @@ -8,7 +8,7 @@ namespace hex::pl { class ASTNodeTypeDecl : public ASTNode, public Attributable { public: - ASTNodeTypeDecl(std::string name, std::shared_ptr &&type, std::optional endian = std::nullopt) + ASTNodeTypeDecl(std::string name, std::shared_ptr type, std::optional endian = std::nullopt) : ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_endian(endian) { } ASTNodeTypeDecl(const ASTNodeTypeDecl &other) : ASTNode(other), Attributable(other) { diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_variable_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_variable_decl.hpp index cf18af2a2..a1f9a2325 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_variable_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_variable_decl.hpp @@ -3,18 +3,19 @@ #include #include #include +#include namespace hex::pl { class ASTNodeVariableDecl : public ASTNode, public Attributable { public: - ASTNodeVariableDecl(std::string name, std::unique_ptr &&type, std::unique_ptr &&placementOffset = nullptr, bool inVariable = false, bool outVariable = false) + ASTNodeVariableDecl(std::string name, std::shared_ptr type, std::unique_ptr &&placementOffset = nullptr, bool inVariable = false, bool outVariable = false) : ASTNode(), m_name(std::move(name)), m_type(std::move(type)), m_placementOffset(std::move(placementOffset)), m_inVariable(inVariable), m_outVariable(outVariable) { } ASTNodeVariableDecl(const ASTNodeVariableDecl &other) : ASTNode(other), Attributable(other) { this->m_name = other.m_name; - this->m_type = other.m_type->clone(); + this->m_type = other.m_type; if (other.m_placementOffset != nullptr) this->m_placementOffset = other.m_placementOffset->clone(); @@ -30,7 +31,7 @@ namespace hex::pl { } [[nodiscard]] const std::string &getName() const { return this->m_name; } - [[nodiscard]] constexpr const std::unique_ptr &getType() const { return this->m_type; } + [[nodiscard]] constexpr const std::shared_ptr &getType() const { return this->m_type; } [[nodiscard]] constexpr const std::unique_ptr &getPlacementOffset() const { return this->m_placementOffset; } [[nodiscard]] constexpr bool isInVariable() const { return this->m_inVariable; } @@ -71,7 +72,7 @@ namespace hex::pl { private: std::string m_name; - std::unique_ptr m_type; + std::shared_ptr m_type; std::unique_ptr m_placementOffset; bool m_inVariable = false, m_outVariable = false; diff --git a/lib/libimhex/include/hex/pattern_language/parser.hpp b/lib/libimhex/include/hex/pattern_language/parser.hpp index b388b2f28..98238df06 100644 --- a/lib/libimhex/include/hex/pattern_language/parser.hpp +++ b/lib/libimhex/include/hex/pattern_language/parser.hpp @@ -112,17 +112,17 @@ namespace hex::pl { std::unique_ptr parseType(bool allowFunctionTypes = false); std::shared_ptr parseUsingDeclaration(); std::unique_ptr parsePadding(); - std::unique_ptr parseMemberVariable(std::unique_ptr &&type); - std::unique_ptr parseMemberArrayVariable(std::unique_ptr &&type); - std::unique_ptr parseMemberPointerVariable(std::unique_ptr &&type); + std::unique_ptr parseMemberVariable(const std::shared_ptr &type); + std::unique_ptr parseMemberArrayVariable(const std::shared_ptr &type); + std::unique_ptr parseMemberPointerVariable(const std::shared_ptr &type); std::unique_ptr parseMember(); std::shared_ptr parseStruct(); std::shared_ptr parseUnion(); std::shared_ptr parseEnum(); std::shared_ptr parseBitfield(); - std::unique_ptr parseVariablePlacement(std::unique_ptr &&type); - std::unique_ptr parseArrayVariablePlacement(std::unique_ptr &&type); - std::unique_ptr parsePointerVariablePlacement(std::unique_ptr &&type); + std::unique_ptr parseVariablePlacement(const std::shared_ptr &type); + std::unique_ptr parseArrayVariablePlacement(const std::shared_ptr &type); + std::unique_ptr parsePointerVariablePlacement(const std::shared_ptr &type); std::unique_ptr parsePlacement(); std::vector> parseNamespace(); std::vector> parseStatements(); diff --git a/lib/libimhex/source/pattern_language/parser.cpp b/lib/libimhex/source/pattern_language/parser.cpp index 5a42cb7b1..d477351b5 100644 --- a/lib/libimhex/source/pattern_language/parser.cpp +++ b/lib/libimhex/source/pattern_language/parser.cpp @@ -686,9 +686,9 @@ namespace hex::pl { std::string typeName = parseNamespaceResolution(); if (this->m_types.contains(typeName)) - return create(new ASTNodeTypeDecl({}, this->m_types[typeName]->clone(), endian)); + return create(new ASTNodeTypeDecl({}, this->m_types[typeName], endian)); else if (this->m_types.contains(getNamespacePrefixedName(typeName))) - return create(new ASTNodeTypeDecl({}, this->m_types[getNamespacePrefixedName(typeName)]->clone(), endian)); + return create(new ASTNodeTypeDecl({}, this->m_types[getNamespacePrefixedName(typeName)], endian)); else throwParserError(hex::format("unknown type '{}'", typeName)); } else if (MATCHES(sequence(VALUETYPE_ANY))) { // Builtin type @@ -728,24 +728,24 @@ namespace hex::pl { } // (parseType) Identifier - std::unique_ptr Parser::parseMemberVariable(std::unique_ptr &&type) { + std::unique_ptr Parser::parseMemberVariable(const std::shared_ptr &type) { if (peek(SEPARATOR_COMMA)) { std::vector> variables; do { - variables.push_back(create(new ASTNodeVariableDecl(getValue(-1).get(), type->clone()))); + variables.push_back(create(new ASTNodeVariableDecl(getValue(-1).get(), type))); } while (MATCHES(sequence(SEPARATOR_COMMA, IDENTIFIER))); return create(new ASTNodeMultiVariableDecl(std::move(variables))); } else if (MATCHES(sequence(OPERATOR_AT))) - return create(new ASTNodeVariableDecl(getValue(-2).get(), std::move(type), parseMathematicalExpression())); + return create(new ASTNodeVariableDecl(getValue(-2).get(), type, parseMathematicalExpression())); else - return create(new ASTNodeVariableDecl(getValue(-1).get(), std::move(type))); + return create(new ASTNodeVariableDecl(getValue(-1).get(), type)); } // (parseType) Identifier[(parseMathematicalExpression)] - std::unique_ptr Parser::parseMemberArrayVariable(std::unique_ptr &&type) { + std::unique_ptr Parser::parseMemberArrayVariable(const std::shared_ptr &type) { auto name = getValue(-2).get(); std::unique_ptr size; @@ -761,13 +761,13 @@ namespace hex::pl { } if (MATCHES(sequence(OPERATOR_AT))) - return create(new ASTNodeArrayVariableDecl(name, std::move(type), std::move(size), parseMathematicalExpression())); + return create(new ASTNodeArrayVariableDecl(name, type, std::move(size), parseMathematicalExpression())); else - return create(new ASTNodeArrayVariableDecl(name, std::move(type), std::move(size))); + return create(new ASTNodeArrayVariableDecl(name, type, std::move(size))); } // (parseType) *Identifier : (parseType) - std::unique_ptr Parser::parseMemberPointerVariable(std::unique_ptr &&type) { + std::unique_ptr Parser::parseMemberPointerVariable(const std::shared_ptr &type) { auto name = getValue(-2).get(); auto sizeType = parseType(); @@ -780,9 +780,9 @@ namespace hex::pl { } if (MATCHES(sequence(OPERATOR_AT))) - return create(new ASTNodePointerVariableDecl(name, std::move(type), std::move(sizeType), parseMathematicalExpression())); + return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType), parseMathematicalExpression())); else - return create(new ASTNodePointerVariableDecl(name, std::move(type), std::move(sizeType))); + return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType))); } // [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)] @@ -977,7 +977,7 @@ namespace hex::pl { } // (parseType) Identifier @ Integer - std::unique_ptr Parser::parseVariablePlacement(std::unique_ptr &&type) { + std::unique_ptr Parser::parseVariablePlacement(const std::shared_ptr &type) { bool inVariable = false; bool outVariable = false; @@ -992,11 +992,11 @@ namespace hex::pl { outVariable = true; } - return create(new ASTNodeVariableDecl(name, type->clone(), std::move(placementOffset), inVariable, outVariable)); + return create(new ASTNodeVariableDecl(name, type, std::move(placementOffset), inVariable, outVariable)); } // (parseType) Identifier[[(parseMathematicalExpression)]] @ Integer - std::unique_ptr Parser::parseArrayVariablePlacement(std::unique_ptr &&type) { + std::unique_ptr Parser::parseArrayVariablePlacement(const std::shared_ptr &type) { auto name = getValue(-2).get(); std::unique_ptr size; @@ -1016,11 +1016,11 @@ namespace hex::pl { auto placementOffset = parseMathematicalExpression(); - return create(new ASTNodeArrayVariableDecl(name, std::move(type), std::move(size), std::move(placementOffset))); + return create(new ASTNodeArrayVariableDecl(name, type, std::move(size), std::move(placementOffset))); } // (parseType) *Identifier : (parseType) @ Integer - std::unique_ptr Parser::parsePointerVariablePlacement(std::unique_ptr &&type) { + std::unique_ptr Parser::parsePointerVariablePlacement(const std::shared_ptr &type) { auto name = getValue(-2).get(); auto sizeType = parseType(); @@ -1037,7 +1037,7 @@ namespace hex::pl { auto placementOffset = parseMathematicalExpression(); - return create(new ASTNodePointerVariableDecl(name, type->clone(), std::move(sizeType), std::move(placementOffset))); + return create(new ASTNodePointerVariableDecl(name, type, std::move(sizeType), std::move(placementOffset))); } std::vector> Parser::parseNamespace() { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index c7422c295..b4acfb536 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -357,10 +357,12 @@ namespace hex::plugin::builtin { this->m_console = this->m_lastEvaluationLog; if (!this->m_lastEvaluationResult) { - TextEditor::ErrorMarkers errorMarkers = { - {this->m_lastEvaluationError->getLineNumber(), this->m_lastEvaluationError->what()} - }; - this->m_textEditor.SetErrorMarkers(errorMarkers); + if (this->m_lastEvaluationError) { + TextEditor::ErrorMarkers errorMarkers = { + {this->m_lastEvaluationError->getLineNumber(), this->m_lastEvaluationError->what()} + }; + this->m_textEditor.SetErrorMarkers(errorMarkers); + } } else { for (auto &[name, variable] : this->m_patternVariables) { if (variable.outVariable && this->m_lastEvaluationOutVars.contains(name))