From b12cd66679991cffba63edc364bf05d5fed4758b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 11 Oct 2021 22:01:15 +0200 Subject: [PATCH] patterns: Make global scope available for use in custom types --- .../include/hex/pattern_language/ast_node.hpp | 13 +++++++++++-- .../include/hex/pattern_language/evaluator.hpp | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp index 88e59d370..de72e7287 100644 --- a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp @@ -1501,10 +1501,19 @@ namespace hex::pl { } [[nodiscard]] std::vector createPatterns(Evaluator *evaluator) const override { + std::vector searchScope; + PatternData *currPattern = nullptr; s32 scopeIndex = 0; - auto searchScope = *evaluator->getScope(scopeIndex).scope; - PatternData *currPattern = nullptr; + if (!evaluator->isGlobalScope()){ + auto globalScope = evaluator->getGlobalScope().scope; + std::copy(globalScope->begin(), globalScope->end(), std::back_inserter(searchScope)); + } + + { + auto currScope = evaluator->getScope(scopeIndex).scope; + std::copy(currScope->begin(), currScope->end(), std::back_inserter(searchScope)); + } for (const auto &part : this->getPath()) { diff --git a/plugins/libimhex/include/hex/pattern_language/evaluator.hpp b/plugins/libimhex/include/hex/pattern_language/evaluator.hpp index 0d5c80a91..828035272 100644 --- a/plugins/libimhex/include/hex/pattern_language/evaluator.hpp +++ b/plugins/libimhex/include/hex/pattern_language/evaluator.hpp @@ -55,6 +55,10 @@ namespace hex::pl { return this->m_scopes.front(); } + bool isGlobalScope() { + return this->m_scopes.size() == 1; + } + void setProvider(prv::Provider *provider) { this->m_provider = provider; }