From 949a26ca0ed0821a010aabef12bf5d9f434d85c0 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 3 Mar 2022 12:11:47 +0100 Subject: [PATCH] patterns: Fixed memory leak when using `format` attribute --- .../ast/ast_node_array_variable_decl.hpp | 6 ++--- .../ast/ast_node_bitfield.hpp | 2 +- .../pattern_language/ast/ast_node_cast.hpp | 2 +- .../ast/ast_node_mathematical_expression.hpp | 26 +++++++++---------- .../pattern_language/ast/ast_node_rvalue.hpp | 22 ++++++++-------- .../ast/ast_node_variable_decl.hpp | 2 +- .../hex/pattern_language/patterns/pattern.hpp | 4 +-- .../patterns/pattern_array_dynamic.hpp | 2 +- .../patterns/pattern_array_static.hpp | 2 +- .../patterns/pattern_bitfield.hpp | 4 +-- .../patterns/pattern_enum.hpp | 4 +-- .../patterns/pattern_struct.hpp | 2 +- .../patterns/pattern_union.hpp | 2 +- .../include/hex/pattern_language/token.hpp | 12 ++++----- .../source/pattern_language/evaluator.cpp | 6 +++-- .../source/content/pl_builtin_functions.cpp | 2 +- 16 files changed, 51 insertions(+), 49 deletions(-) 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 5c76f6d67..0466c16e0 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 @@ -49,7 +49,7 @@ namespace hex::pl { evaluator->dataOffset() = std::visit(overloaded { [this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); }, - [this](const std::shared_ptr &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); }, + [this](Pattern *) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); }, [](auto &&offset) -> u64 { return offset; } }, offset->getValue()); } @@ -101,7 +101,7 @@ namespace hex::pl { if (auto literal = dynamic_cast(sizeNode.get())) { entryCount = std::visit(overloaded { [this](const std::string &) -> i128 { LogConsole::abortEvaluation("cannot use string to index array", this); }, - [this](const std::shared_ptr &) -> i128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, + [this](Pattern *) -> i128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, [](auto &&size) -> i128 { return size; } }, literal->getValue()); } else if (auto whileStatement = dynamic_cast(sizeNode.get())) { @@ -197,7 +197,7 @@ namespace hex::pl { if (auto literal = dynamic_cast(sizeNode.get())) { auto entryCount = std::visit(overloaded { [this](const std::string &) -> u128 { LogConsole::abortEvaluation("cannot use string to index array", this); }, - [this](const std::shared_ptr &) -> u128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, + [this](Pattern *) -> u128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, [](auto &&size) -> u128 { return size; } }, literal->getValue()); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_bitfield.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_bitfield.hpp index 0ce0a7238..413ce4e11 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_bitfield.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_bitfield.hpp @@ -53,7 +53,7 @@ namespace hex::pl { u8 bitSize = std::visit(overloaded { [this](const std::string &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a string", this); }, - [this](const std::shared_ptr &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a custom type", this); }, + [this](Pattern *) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a custom type", this); }, [](auto &&offset) -> u8 { return static_cast(offset); } }, dynamic_cast(literal.get())->getValue()); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp index 58b115d85..c8198b513 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp @@ -30,7 +30,7 @@ namespace hex::pl { auto &typePattern = typePatterns.front(); return std::unique_ptr(std::visit(overloaded { - [&, this](const std::shared_ptr &value) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast custom type '{}' to '{}'", value->getTypeName(), Token::getTypeName(type)), this); }, + [&, this](Pattern *value) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast custom type '{}' to '{}'", value->getTypeName(), Token::getTypeName(type)), this); }, [&, this](const std::string &) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast string to '{}'", Token::getTypeName(type)), this); }, [&, this](auto &&value) -> ASTNode * { auto endianAdjustedValue = hex::changeEndianess(value, typePattern->getSize(), typePattern->getEndian()); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp index a773a8fb5..d3e954464 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp @@ -76,19 +76,19 @@ namespace hex::pl { return std::unique_ptr(std::visit(overloaded { // TODO: :notlikethis: - [this](u128 left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](i128 left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](double left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](char left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](bool left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::string &left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, u128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, i128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, double right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, char right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, bool right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, - [this](const std::shared_ptr &left, const std::shared_ptr &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](u128 left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](i128 left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](double left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](char left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](bool left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](const std::string &left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, u128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, i128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, double right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, char right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, bool right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, [this](auto &&left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, [this](const std::string &left, auto &&right) -> ASTNode * { diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp index 8fed02189..f4cee2de0 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp @@ -119,7 +119,7 @@ namespace hex::pl { readVariable(evaluator, value, pattern.get()); literal = u128(hex::extract(bitfieldFieldPattern->getBitOffset() + (bitfieldFieldPattern->getBitSize() - 1), bitfieldFieldPattern->getBitOffset(), value)); } else { - literal = pattern->clone(); + literal = pattern.get(); } if (auto transformFunc = pattern->getTransformFunction(); transformFunc.has_value()) { @@ -205,7 +205,7 @@ namespace hex::pl { std::visit(overloaded { [this](const std::string &) { LogConsole::abortEvaluation("cannot use string to index array", this); }, - [this](const std::shared_ptr &) { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, + [this](Pattern *) { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, [&, this](auto &&index) { if (auto dynamicArrayPattern = dynamic_cast(currPattern.get())) { if (index >= searchScope.size() || index < 0) @@ -231,25 +231,25 @@ namespace hex::pl { currPattern = pointerPattern->getPointedAtPattern()->clone(); } - std::shared_ptr indexPattern; + Pattern *indexPattern; if (currPattern->isLocal()) { auto stackLiteral = evaluator->getStack()[currPattern->getOffset()]; - if (auto stackPattern = std::get_if>(&stackLiteral); stackPattern != nullptr) + if (auto stackPattern = std::get_if(&stackLiteral); stackPattern != nullptr) indexPattern = *stackPattern; else return hex::moveToVector>(std::move(currPattern)); } else - indexPattern = currPattern->clone(); + indexPattern = currPattern.get(); - if (auto structPattern = dynamic_cast(indexPattern.get())) + if (auto structPattern = dynamic_cast(indexPattern)) searchScope = structPattern->getMembers(); - else if (auto unionPattern = dynamic_cast(indexPattern.get())) + else if (auto unionPattern = dynamic_cast(indexPattern)) searchScope = unionPattern->getMembers(); - else if (auto bitfieldPattern = dynamic_cast(indexPattern.get())) + else if (auto bitfieldPattern = dynamic_cast(indexPattern)) searchScope = bitfieldPattern->getFields(); - else if (auto dynamicArrayPattern = dynamic_cast(indexPattern.get())) + else if (auto dynamicArrayPattern = dynamic_cast(indexPattern)) searchScope = dynamicArrayPattern->getEntries(); - else if (auto staticArrayPattern = dynamic_cast(indexPattern.get())) + else if (auto staticArrayPattern = dynamic_cast(indexPattern)) searchScope = { staticArrayPattern->getTemplate() }; } @@ -272,7 +272,7 @@ namespace hex::pl { [&](std::string &assignmentValue) { if constexpr (isString) value = assignmentValue; }, - [&](std::shared_ptr &assignmentValue) { readVariable(evaluator, value, assignmentValue.get()); }, + [&](Pattern *assignmentValue) { readVariable(evaluator, value, assignmentValue); }, [&](auto &&assignmentValue) { value = assignmentValue; } }, literal); } else { 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 75c5404bd..cf18af2a2 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 @@ -45,7 +45,7 @@ namespace hex::pl { evaluator->dataOffset() = std::visit(overloaded { [this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); }, - [this](const std::shared_ptr &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); }, + [this](Pattern *) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); }, [](auto &&offset) -> u64 { return offset; } }, offset->getValue()); } diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp index 061fc4549..5cb6f83a8 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp @@ -233,7 +233,7 @@ namespace hex::pl { } protected: - void createDefaultEntry(const std::string &value, const Token::Literal &literal) const { + void createDefaultEntry(const std::string &value, Token::Literal &&literal) const { ImGui::TableNextRow(); ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap); ImGui::TableNextColumn(); @@ -258,7 +258,7 @@ namespace hex::pl { ImGui::TableNextColumn(); ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName()); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", formatDisplayValue(value, literal)); + ImGui::TextFormatted("{}", formatDisplayValue(value, std::move(literal))); } void drawCommentTooltip() const { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_dynamic.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_dynamic.hpp index c9e0b99f9..65ec864ea 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_dynamic.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_dynamic.hpp @@ -58,7 +58,7 @@ namespace hex::pl { ImGui::TextUnformatted("]"); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this)); } if (open) { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_static.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_static.hpp index ee74910c6..29bcc8145 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_static.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_array_static.hpp @@ -49,7 +49,7 @@ namespace hex::pl { ImGui::TextUnformatted("]"); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this)); } if (open) { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp index ec827716b..8f5d6f0a7 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp @@ -43,7 +43,7 @@ namespace hex::pl { u8 numBytes = (this->m_bitSize / 8) + 1; u64 extractedValue = hex::extract(this->m_bitOffset + (this->m_bitSize - 1), this->m_bitOffset, value); - ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{0} (0x{1:X})", extractedValue, extractedValue), this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{0} (0x{1:X})", extractedValue, extractedValue), this)); } } @@ -120,7 +120,7 @@ namespace hex::pl { valueString += hex::format("{0:02X} ", i); valueString += "}"; - ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this)); } if (open) { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_enum.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_enum.hpp index 31dbd601f..115b1d8b3 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_enum.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_enum.hpp @@ -34,7 +34,7 @@ namespace hex::pl { return false; }, [](std::string &) { return false; }, - [](std::shared_ptr &) { return false; } }, + [](Pattern *) { return false; } }, entryValueLiteral); if (matches) break; @@ -63,7 +63,7 @@ namespace hex::pl { ImGui::SameLine(); ImGui::TextUnformatted(Pattern::getTypeName().c_str()); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2), this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2), this)); } [[nodiscard]] std::string getFormattedName() const override { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_struct.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_struct.hpp index 1f1e300b3..bcc8df277 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_struct.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_struct.hpp @@ -45,7 +45,7 @@ namespace hex::pl { ImGui::SameLine(); ImGui::TextUnformatted(this->getTypeName().c_str()); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this)); } if (open) { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_union.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_union.hpp index acaf57982..f2d0e29b7 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_union.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_union.hpp @@ -46,7 +46,7 @@ namespace hex::pl { ImGui::TextUnformatted(Pattern::getTypeName().c_str()); ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); + ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this)); } if (open) { diff --git a/lib/libimhex/include/hex/pattern_language/token.hpp b/lib/libimhex/include/hex/pattern_language/token.hpp index 8c3d60f19..78562550c 100644 --- a/lib/libimhex/include/hex/pattern_language/token.hpp +++ b/lib/libimhex/include/hex/pattern_language/token.hpp @@ -139,7 +139,7 @@ namespace hex::pl { std::string m_identifier; }; - using Literal = std::variant>; + using Literal = std::variant; using ValueTypes = std::variant; Token(Type type, auto value, u32 lineNumber) : type(type), value(value), lineNumber(lineNumber) { @@ -164,7 +164,7 @@ namespace hex::pl { static u128 literalToUnsigned(const pl::Token::Literal &literal) { return std::visit(overloaded { [](const std::string &) -> u128 { LogConsole::abortEvaluation("expected integral type, got string"); }, - [](const std::shared_ptr &) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, + [](Pattern *) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](auto &&result) -> u128 { return result; } }, literal); } @@ -172,7 +172,7 @@ namespace hex::pl { static i128 literalToSigned(const pl::Token::Literal &literal) { return std::visit(overloaded { [](const std::string &) -> i128 { LogConsole::abortEvaluation("expected integral type, got string"); }, - [](const std::shared_ptr &) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, + [](Pattern *) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](auto &&result) -> i128 { return result; } }, literal); } @@ -180,7 +180,7 @@ namespace hex::pl { static double literalToFloatingPoint(const pl::Token::Literal &literal) { return std::visit(overloaded { [](const std::string &) -> double { LogConsole::abortEvaluation("expected integral type, got string"); }, - [](const std::shared_ptr &) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); }, + [](Pattern *) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](auto &&result) -> double { return result; } }, literal); } @@ -188,7 +188,7 @@ namespace hex::pl { static bool literalToBoolean(const pl::Token::Literal &literal) { return std::visit(overloaded { [](const std::string &) -> bool { LogConsole::abortEvaluation("expected integral type, got string"); }, - [](const std::unique_ptr &) -> bool { LogConsole::abortEvaluation("expected integral type, got custom type"); }, + [](Pattern *) -> bool { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](auto &&result) -> bool { return result != 0; } }, literal); } @@ -203,7 +203,7 @@ namespace hex::pl { [](i128 result) -> std::string { return hex::to_string(result); }, [](bool result) -> std::string { return result ? "true" : "false"; }, [](char result) -> std::string { return { 1, result }; }, - [](const std::shared_ptr &) -> std::string { LogConsole::abortEvaluation("expected integral type, got custom type"); }, + [](Pattern *) -> std::string { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](auto &&result) -> std::string { return std::to_string(result); } }, literal); } diff --git a/lib/libimhex/source/pattern_language/evaluator.cpp b/lib/libimhex/source/pattern_language/evaluator.cpp index ce460a55b..19e212bed 100644 --- a/lib/libimhex/source/pattern_language/evaluator.cpp +++ b/lib/libimhex/source/pattern_language/evaluator.cpp @@ -15,6 +15,8 @@ #include #include +#include + namespace hex::pl { void Evaluator::createParameterPack(const std::string &name, const std::vector &values) { @@ -56,7 +58,7 @@ namespace hex::pl { pattern = std::unique_ptr(new PatternCharacter(this, 0)); else if (std::get_if(&value.value()) != nullptr) pattern = std::unique_ptr(new PatternString(this, 0, 1)); - else if (auto patternValue = std::get_if>(&value.value()); patternValue != nullptr) { + else if (auto patternValue = std::get_if(&value.value()); patternValue != nullptr) { pattern = (*patternValue)->clone(); referenceType = true; } else @@ -127,7 +129,7 @@ namespace hex::pl { else LogConsole::abortEvaluation(hex::format("cannot cast type 'string' to type '{}'", pattern->getTypeName())); }, - [&](const std::shared_ptr &value) -> Token::Literal { + [&](Pattern *value) -> Token::Literal { if (value->getTypeName() == pattern->getTypeName()) return value; else diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index fa98c5450..8c3193165 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -25,7 +25,7 @@ namespace hex::plugin::builtin { auto ¶m = params[i]; std::visit(overloaded { - [&](const std::shared_ptr &value) { + [&](pl::Pattern *value) { formatArgs.push_back(value->toString(ctx->getProvider())); }, [&](auto &&value) {