From 635f0606e088d13e762180e8eb66d90e44c77f61 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 11 Sep 2021 23:14:22 +0200 Subject: [PATCH] patterns: Fixed enums not counting properly --- plugins/builtin/source/content/pl_builtin_functions.cpp | 3 --- plugins/libimhex/include/hex/pattern_language/ast_node.hpp | 6 +++--- plugins/libimhex/include/hex/pattern_language/evaluator.hpp | 3 +++ plugins/libimhex/source/pattern_language/parser.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index 6962226ec..1afcc61da 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -11,9 +11,6 @@ namespace hex::plugin::builtin { - #define LITERAL_COMPARE(literal, cond) std::visit([&](auto &&literal) { return (cond) != 0; }, literal) - #define AS_TYPE(type, value) ctx.template asType(value) - void registerPatternLanguageFunctions() { using namespace hex::pl; diff --git a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp index b863fb634..0031dff45 100644 --- a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -381,13 +381,13 @@ namespace hex::pl { return new ASTNodeEnum(*this); } - [[nodiscard]] const std::unordered_map& getEntries() const { return this->m_entries; } + [[nodiscard]] const std::map& getEntries() const { return this->m_entries; } void addEntry(const std::string &name, ASTNode* expression) { this->m_entries.insert({ name, expression }); } [[nodiscard]] ASTNode *getUnderlyingType() { return this->m_underlyingType; } private: - std::unordered_map m_entries; + std::map m_entries; ASTNode *m_underlyingType; }; diff --git a/plugins/libimhex/include/hex/pattern_language/evaluator.hpp b/plugins/libimhex/include/hex/pattern_language/evaluator.hpp index 2f1665c9a..7487626c1 100644 --- a/plugins/libimhex/include/hex/pattern_language/evaluator.hpp +++ b/plugins/libimhex/include/hex/pattern_language/evaluator.hpp @@ -11,6 +11,9 @@ #include #include +#define LITERAL_COMPARE(literal, cond) std::visit([&](auto &&literal) { return (cond) != 0; }, literal) +#define AS_TYPE(type, value) ctx.template asType(value) + namespace hex::prv { class Provider; } namespace hex::pl { diff --git a/plugins/libimhex/source/pattern_language/parser.cpp b/plugins/libimhex/source/pattern_language/parser.cpp index 582fd06d7..5c3a9c4f4 100644 --- a/plugins/libimhex/source/pattern_language/parser.cpp +++ b/plugins/libimhex/source/pattern_language/parser.cpp @@ -808,7 +808,7 @@ namespace hex::pl { if (enumNode->getEntries().empty()) valueExpr = lastEntry = TO_NUMERIC_EXPRESSION(new ASTNodeIntegerLiteral(u8(0))); else - valueExpr = new ASTNodeNumericExpression(lastEntry->clone(), new ASTNodeIntegerLiteral(s32(1)), Token::Operator::Plus); + valueExpr = lastEntry = new ASTNodeNumericExpression(lastEntry->clone(), new ASTNodeIntegerLiteral(s32(1)), Token::Operator::Plus); enumNode->addEntry(name, valueExpr); }