From ef8e9a83bbf78516ae1b4e02b83d15906353d1c8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 21 Feb 2022 20:00:54 +0100 Subject: [PATCH] patterns: Properly treat arrays and custom types as references --- .../source/pattern_language/evaluator.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libimhex/source/pattern_language/evaluator.cpp b/lib/libimhex/source/pattern_language/evaluator.cpp index 4da578ddf..53e6e7ec0 100644 --- a/lib/libimhex/source/pattern_language/evaluator.cpp +++ b/lib/libimhex/source/pattern_language/evaluator.cpp @@ -23,6 +23,8 @@ namespace hex::pl { auto pattern = type == nullptr ? nullptr : type->createPatterns(this).front(); this->dataOffset() = startOffset; + bool referenceType = false; + if (pattern == nullptr) { // Handle auto variables if (!value.has_value()) @@ -38,19 +40,23 @@ namespace hex::pl { pattern = new PatternDataBoolean(this, 0); else if (std::get_if(&value.value()) != nullptr) pattern = new PatternDataCharacter(this, 0); - else if (std::get_if(&value.value()) != nullptr) - pattern = std::get(value.value())->clone(); else if (std::get_if(&value.value()) != nullptr) pattern = new PatternDataString(this, 0, 1); - else + else if (std::get_if(&value.value()) != nullptr) { + pattern = std::get(value.value())->clone(); + referenceType = true; + } else LogConsole::abortEvaluation("cannot determine type of auto variable", type); } pattern->setVariableName(name); - pattern->setLocal(true); - pattern->setOffset(this->getStack().size()); - this->getStack().emplace_back(); + if (!referenceType) { + pattern->setOffset(this->getStack().size()); + pattern->setLocal(true); + this->getStack().emplace_back(); + } + variables.push_back(pattern); if (outVariable) @@ -86,6 +92,8 @@ namespace hex::pl { if (pattern == nullptr) LogConsole::abortEvaluation(hex::format("no variable with name '{}' found", name)); + if (!pattern->isLocal()) return; + Token::Literal castedLiteral = std::visit(overloaded { [&](double &value) -> Token::Literal { if (dynamic_cast(pattern))