1
0
mirror of synced 2024-11-12 10:10:53 +01:00

patterns: Fixed memory leak when using format attribute

This commit is contained in:
WerWolv 2022-03-03 12:11:47 +01:00
parent 2880ca00da
commit 949a26ca0e
16 changed files with 51 additions and 49 deletions

View File

@ -49,7 +49,7 @@ namespace hex::pl {
evaluator->dataOffset() = std::visit(overloaded { evaluator->dataOffset() = std::visit(overloaded {
[this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); }, [this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> 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; } }, [](auto &&offset) -> u64 { return offset; } },
offset->getValue()); offset->getValue());
} }
@ -101,7 +101,7 @@ namespace hex::pl {
if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) { if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) {
entryCount = std::visit(overloaded { entryCount = std::visit(overloaded {
[this](const std::string &) -> i128 { LogConsole::abortEvaluation("cannot use string to index array", this); }, [this](const std::string &) -> i128 { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) -> 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; } }, [](auto &&size) -> i128 { return size; } },
literal->getValue()); literal->getValue());
} else if (auto whileStatement = dynamic_cast<ASTNodeWhileStatement *>(sizeNode.get())) { } else if (auto whileStatement = dynamic_cast<ASTNodeWhileStatement *>(sizeNode.get())) {
@ -197,7 +197,7 @@ namespace hex::pl {
if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) { if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) {
auto entryCount = std::visit(overloaded { auto entryCount = std::visit(overloaded {
[this](const std::string &) -> u128 { LogConsole::abortEvaluation("cannot use string to index array", this); }, [this](const std::string &) -> u128 { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) -> 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; } }, [](auto &&size) -> u128 { return size; } },
literal->getValue()); literal->getValue());

View File

@ -53,7 +53,7 @@ namespace hex::pl {
u8 bitSize = std::visit(overloaded { u8 bitSize = std::visit(overloaded {
[this](const std::string &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a string", this); }, [this](const std::string &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> 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<u8>(offset); } }, [](auto &&offset) -> u8 { return static_cast<u8>(offset); } },
dynamic_cast<ASTNodeLiteral *>(literal.get())->getValue()); dynamic_cast<ASTNodeLiteral *>(literal.get())->getValue());

View File

@ -30,7 +30,7 @@ namespace hex::pl {
auto &typePattern = typePatterns.front(); auto &typePattern = typePatterns.front();
return std::unique_ptr<ASTNode>(std::visit(overloaded { return std::unique_ptr<ASTNode>(std::visit(overloaded {
[&, this](const std::shared_ptr<Pattern> &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](const std::string &) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast string to '{}'", Token::getTypeName(type)), this); },
[&, this](auto &&value) -> ASTNode * { [&, this](auto &&value) -> ASTNode * {
auto endianAdjustedValue = hex::changeEndianess(value, typePattern->getSize(), typePattern->getEndian()); auto endianAdjustedValue = hex::changeEndianess(value, typePattern->getSize(), typePattern->getEndian());

View File

@ -76,19 +76,19 @@ namespace hex::pl {
return std::unique_ptr<ASTNode>(std::visit(overloaded { return std::unique_ptr<ASTNode>(std::visit(overloaded {
// TODO: :notlikethis: // TODO: :notlikethis:
[this](u128 left, const std::shared_ptr<Pattern> &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, const std::shared_ptr<Pattern> &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, const std::shared_ptr<Pattern> &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, const std::shared_ptr<Pattern> &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, const std::shared_ptr<Pattern> &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, const std::shared_ptr<Pattern> &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](const std::shared_ptr<Pattern> &left, u128 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](const std::shared_ptr<Pattern> &left, i128 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](const std::shared_ptr<Pattern> &left, double 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](const std::shared_ptr<Pattern> &left, char 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](const std::shared_ptr<Pattern> &left, bool 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](const std::shared_ptr<Pattern> &left, const std::string &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](const std::shared_ptr<Pattern> &left, const std::shared_ptr<Pattern> &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](auto &&left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::string &left, auto &&right) -> ASTNode * { [this](const std::string &left, auto &&right) -> ASTNode * {

View File

@ -119,7 +119,7 @@ namespace hex::pl {
readVariable(evaluator, value, pattern.get()); readVariable(evaluator, value, pattern.get());
literal = u128(hex::extract(bitfieldFieldPattern->getBitOffset() + (bitfieldFieldPattern->getBitSize() - 1), bitfieldFieldPattern->getBitOffset(), value)); literal = u128(hex::extract(bitfieldFieldPattern->getBitOffset() + (bitfieldFieldPattern->getBitSize() - 1), bitfieldFieldPattern->getBitOffset(), value));
} else { } else {
literal = pattern->clone(); literal = pattern.get();
} }
if (auto transformFunc = pattern->getTransformFunction(); transformFunc.has_value()) { if (auto transformFunc = pattern->getTransformFunction(); transformFunc.has_value()) {
@ -205,7 +205,7 @@ namespace hex::pl {
std::visit(overloaded { std::visit(overloaded {
[this](const std::string &) { LogConsole::abortEvaluation("cannot use string to index array", this); }, [this](const std::string &) { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) { 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) { [&, this](auto &&index) {
if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(currPattern.get())) { if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(currPattern.get())) {
if (index >= searchScope.size() || index < 0) if (index >= searchScope.size() || index < 0)
@ -231,25 +231,25 @@ namespace hex::pl {
currPattern = pointerPattern->getPointedAtPattern()->clone(); currPattern = pointerPattern->getPointedAtPattern()->clone();
} }
std::shared_ptr<Pattern> indexPattern; Pattern *indexPattern;
if (currPattern->isLocal()) { if (currPattern->isLocal()) {
auto stackLiteral = evaluator->getStack()[currPattern->getOffset()]; auto stackLiteral = evaluator->getStack()[currPattern->getOffset()];
if (auto stackPattern = std::get_if<std::shared_ptr<Pattern>>(&stackLiteral); stackPattern != nullptr) if (auto stackPattern = std::get_if<Pattern *>(&stackLiteral); stackPattern != nullptr)
indexPattern = *stackPattern; indexPattern = *stackPattern;
else else
return hex::moveToVector<std::unique_ptr<Pattern>>(std::move(currPattern)); return hex::moveToVector<std::unique_ptr<Pattern>>(std::move(currPattern));
} else } else
indexPattern = currPattern->clone(); indexPattern = currPattern.get();
if (auto structPattern = dynamic_cast<PatternStruct *>(indexPattern.get())) if (auto structPattern = dynamic_cast<PatternStruct *>(indexPattern))
searchScope = structPattern->getMembers(); searchScope = structPattern->getMembers();
else if (auto unionPattern = dynamic_cast<PatternUnion *>(indexPattern.get())) else if (auto unionPattern = dynamic_cast<PatternUnion *>(indexPattern))
searchScope = unionPattern->getMembers(); searchScope = unionPattern->getMembers();
else if (auto bitfieldPattern = dynamic_cast<PatternBitfield *>(indexPattern.get())) else if (auto bitfieldPattern = dynamic_cast<PatternBitfield *>(indexPattern))
searchScope = bitfieldPattern->getFields(); searchScope = bitfieldPattern->getFields();
else if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(indexPattern.get())) else if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(indexPattern))
searchScope = dynamicArrayPattern->getEntries(); searchScope = dynamicArrayPattern->getEntries();
else if (auto staticArrayPattern = dynamic_cast<PatternArrayStatic *>(indexPattern.get())) else if (auto staticArrayPattern = dynamic_cast<PatternArrayStatic *>(indexPattern))
searchScope = { staticArrayPattern->getTemplate() }; searchScope = { staticArrayPattern->getTemplate() };
} }
@ -272,7 +272,7 @@ namespace hex::pl {
[&](std::string &assignmentValue) { [&](std::string &assignmentValue) {
if constexpr (isString) value = assignmentValue; if constexpr (isString) value = assignmentValue;
}, },
[&](std::shared_ptr<Pattern> &assignmentValue) { readVariable(evaluator, value, assignmentValue.get()); }, [&](Pattern *assignmentValue) { readVariable(evaluator, value, assignmentValue); },
[&](auto &&assignmentValue) { value = assignmentValue; } }, [&](auto &&assignmentValue) { value = assignmentValue; } },
literal); literal);
} else { } else {

View File

@ -45,7 +45,7 @@ namespace hex::pl {
evaluator->dataOffset() = std::visit(overloaded { evaluator->dataOffset() = std::visit(overloaded {
[this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); }, [this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> 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; } }, [](auto &&offset) -> u64 { return offset; } },
offset->getValue()); offset->getValue());
} }

View File

@ -233,7 +233,7 @@ namespace hex::pl {
} }
protected: 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::TableNextRow();
ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap); ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -258,7 +258,7 @@ namespace hex::pl {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName()); ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("{}", formatDisplayValue(value, literal)); ImGui::TextFormatted("{}", formatDisplayValue(value, std::move(literal)));
} }
void drawCommentTooltip() const { void drawCommentTooltip() const {

View File

@ -58,7 +58,7 @@ namespace hex::pl {
ImGui::TextUnformatted("]"); ImGui::TextUnformatted("]");
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
} }
if (open) { if (open) {

View File

@ -49,7 +49,7 @@ namespace hex::pl {
ImGui::TextUnformatted("]"); ImGui::TextUnformatted("]");
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
} }
if (open) { if (open) {

View File

@ -43,7 +43,7 @@ namespace hex::pl {
u8 numBytes = (this->m_bitSize / 8) + 1; u8 numBytes = (this->m_bitSize / 8) + 1;
u64 extractedValue = hex::extract(this->m_bitOffset + (this->m_bitSize - 1), this->m_bitOffset, value); 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 += hex::format("{0:02X} ", i);
valueString += "}"; valueString += "}";
ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this->clone())); ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this));
} }
if (open) { if (open) {

View File

@ -34,7 +34,7 @@ namespace hex::pl {
return false; return false;
}, },
[](std::string &) { return false; }, [](std::string &) { return false; },
[](std::shared_ptr<Pattern> &) { return false; } }, [](Pattern *) { return false; } },
entryValueLiteral); entryValueLiteral);
if (matches) if (matches)
break; break;
@ -63,7 +63,7 @@ namespace hex::pl {
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextUnformatted(Pattern::getTypeName().c_str()); ImGui::TextUnformatted(Pattern::getTypeName().c_str());
ImGui::TableNextColumn(); 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 { [[nodiscard]] std::string getFormattedName() const override {

View File

@ -45,7 +45,7 @@ namespace hex::pl {
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextUnformatted(this->getTypeName().c_str()); ImGui::TextUnformatted(this->getTypeName().c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
} }
if (open) { if (open) {

View File

@ -46,7 +46,7 @@ namespace hex::pl {
ImGui::TextUnformatted(Pattern::getTypeName().c_str()); ImGui::TextUnformatted(Pattern::getTypeName().c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone())); ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
} }
if (open) { if (open) {

View File

@ -139,7 +139,7 @@ namespace hex::pl {
std::string m_identifier; std::string m_identifier;
}; };
using Literal = std::variant<char, bool, u128, i128, double, std::string, std::shared_ptr<Pattern>>; using Literal = std::variant<char, bool, u128, i128, double, std::string, Pattern *>;
using ValueTypes = std::variant<Keyword, Identifier, Operator, Literal, ValueType, Separator>; using ValueTypes = std::variant<Keyword, Identifier, Operator, Literal, ValueType, Separator>;
Token(Type type, auto value, u32 lineNumber) : type(type), value(value), lineNumber(lineNumber) { 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) { static u128 literalToUnsigned(const pl::Token::Literal &literal) {
return std::visit(overloaded { return std::visit(overloaded {
[](const std::string &) -> u128 { LogConsole::abortEvaluation("expected integral type, got string"); }, [](const std::string &) -> u128 { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](Pattern *) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> u128 { return result; } }, [](auto &&result) -> u128 { return result; } },
literal); literal);
} }
@ -172,7 +172,7 @@ namespace hex::pl {
static i128 literalToSigned(const pl::Token::Literal &literal) { static i128 literalToSigned(const pl::Token::Literal &literal) {
return std::visit(overloaded { return std::visit(overloaded {
[](const std::string &) -> i128 { LogConsole::abortEvaluation("expected integral type, got string"); }, [](const std::string &) -> i128 { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](Pattern *) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> i128 { return result; } }, [](auto &&result) -> i128 { return result; } },
literal); literal);
} }
@ -180,7 +180,7 @@ namespace hex::pl {
static double literalToFloatingPoint(const pl::Token::Literal &literal) { static double literalToFloatingPoint(const pl::Token::Literal &literal) {
return std::visit(overloaded { return std::visit(overloaded {
[](const std::string &) -> double { LogConsole::abortEvaluation("expected integral type, got string"); }, [](const std::string &) -> double { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); }, [](Pattern *) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> double { return result; } }, [](auto &&result) -> double { return result; } },
literal); literal);
} }
@ -188,7 +188,7 @@ namespace hex::pl {
static bool literalToBoolean(const pl::Token::Literal &literal) { static bool literalToBoolean(const pl::Token::Literal &literal) {
return std::visit(overloaded { return std::visit(overloaded {
[](const std::string &) -> bool { LogConsole::abortEvaluation("expected integral type, got string"); }, [](const std::string &) -> bool { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::unique_ptr<Pattern> &) -> 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; } }, [](auto &&result) -> bool { return result != 0; } },
literal); literal);
} }
@ -203,7 +203,7 @@ namespace hex::pl {
[](i128 result) -> std::string { return hex::to_string(result); }, [](i128 result) -> std::string { return hex::to_string(result); },
[](bool result) -> std::string { return result ? "true" : "false"; }, [](bool result) -> std::string { return result ? "true" : "false"; },
[](char result) -> std::string { return { 1, result }; }, [](char result) -> std::string { return { 1, result }; },
[](const std::shared_ptr<Pattern> &) -> 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); } }, [](auto &&result) -> std::string { return std::to_string(result); } },
literal); literal);
} }

View File

@ -15,6 +15,8 @@
#include <hex/pattern_language/patterns/pattern_string.hpp> #include <hex/pattern_language/patterns/pattern_string.hpp>
#include <hex/pattern_language/patterns/pattern_enum.hpp> #include <hex/pattern_language/patterns/pattern_enum.hpp>
#include <hex/helpers/logger.hpp>
namespace hex::pl { namespace hex::pl {
void Evaluator::createParameterPack(const std::string &name, const std::vector<Token::Literal> &values) { void Evaluator::createParameterPack(const std::string &name, const std::vector<Token::Literal> &values) {
@ -56,7 +58,7 @@ namespace hex::pl {
pattern = std::unique_ptr<Pattern>(new PatternCharacter(this, 0)); pattern = std::unique_ptr<Pattern>(new PatternCharacter(this, 0));
else if (std::get_if<std::string>(&value.value()) != nullptr) else if (std::get_if<std::string>(&value.value()) != nullptr)
pattern = std::unique_ptr<Pattern>(new PatternString(this, 0, 1)); pattern = std::unique_ptr<Pattern>(new PatternString(this, 0, 1));
else if (auto patternValue = std::get_if<std::shared_ptr<Pattern>>(&value.value()); patternValue != nullptr) { else if (auto patternValue = std::get_if<Pattern *>(&value.value()); patternValue != nullptr) {
pattern = (*patternValue)->clone(); pattern = (*patternValue)->clone();
referenceType = true; referenceType = true;
} else } else
@ -127,7 +129,7 @@ namespace hex::pl {
else else
LogConsole::abortEvaluation(hex::format("cannot cast type 'string' to type '{}'", pattern->getTypeName())); LogConsole::abortEvaluation(hex::format("cannot cast type 'string' to type '{}'", pattern->getTypeName()));
}, },
[&](const std::shared_ptr<Pattern> &value) -> Token::Literal { [&](Pattern *value) -> Token::Literal {
if (value->getTypeName() == pattern->getTypeName()) if (value->getTypeName() == pattern->getTypeName())
return value; return value;
else else

View File

@ -25,7 +25,7 @@ namespace hex::plugin::builtin {
auto &param = params[i]; auto &param = params[i];
std::visit(overloaded { std::visit(overloaded {
[&](const std::shared_ptr<pl::Pattern> &value) { [&](pl::Pattern *value) {
formatArgs.push_back(value->toString(ctx->getProvider())); formatArgs.push_back(value->toString(ctx->getProvider()));
}, },
[&](auto &&value) { [&](auto &&value) {