From 93c1fbd65e694e80d03702b32613f4b253a1801f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 24 Sep 2021 11:34:06 +0200 Subject: [PATCH] patterns: Fixed function parameters being set in the wrong order --- plugins/libimhex/include/hex/pattern_language/ast_node.hpp | 7 ++++--- plugins/libimhex/source/pattern_language/parser.cpp | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp index 4f5a1dc3e..e1b997cc8 100644 --- a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp @@ -1777,7 +1777,7 @@ namespace hex::pl { class ASTNodeFunctionDefinition : public ASTNode { public: // TODO: Implement this - ASTNodeFunctionDefinition(std::string name, std::map params, std::vector body) + ASTNodeFunctionDefinition(std::string name, std::vector> params, std::vector body) : m_name(std::move(name)), m_params(std::move(params)), m_body(std::move(body)) { } @@ -1787,7 +1787,7 @@ namespace hex::pl { this->m_params = other.m_params; for (const auto &[name, type] : other.m_params) { - this->m_params.emplace(name, type->clone()); + this->m_params.emplace_back(name, type->clone()); } for (auto statement : other.m_body) { @@ -1828,6 +1828,7 @@ namespace hex::pl { u32 paramIndex = 0; for (const auto &[name, type] : this->m_params) { + hex::log::info("{}", name); ctx->createVariable(name, type, params[paramIndex]); ctx->setVariable(name, params[paramIndex]); @@ -1851,7 +1852,7 @@ namespace hex::pl { private: std::string m_name; - std::map m_params; + std::vector> m_params; std::vector m_body; }; diff --git a/plugins/libimhex/source/pattern_language/parser.cpp b/plugins/libimhex/source/pattern_language/parser.cpp index d9e98aaec..2d6448448 100644 --- a/plugins/libimhex/source/pattern_language/parser.cpp +++ b/plugins/libimhex/source/pattern_language/parser.cpp @@ -424,7 +424,7 @@ namespace hex::pl { ASTNode* Parser::parseFunctionDefinition() { const auto &functionName = getValue(-2).get(); - std::map params; + std::vector> params; // Parse parameter list bool hasParams = !peek(SEPARATOR_ROUNDBRACKETCLOSE); @@ -433,9 +433,9 @@ namespace hex::pl { auto type = parseType(true); if (MATCHES(sequence(IDENTIFIER))) - params.emplace(getValue(-1).get(), type); + params.emplace_back(getValue(-1).get(), type); else { - params.emplace(std::to_string(unnamedParamCount), type); + params.emplace_back(std::to_string(unnamedParamCount), type); unnamedParamCount++; }