1
0
mirror of synced 2024-12-12 07:51:05 +01:00
ImHex/plugins/libimhex/include/hex/pattern_language/pattern_language.hpp
WerWolv c051f5d3e7
patterns: Rewrite evaluation engine (#306)
* patterns: Rewrite most of the evaluator to mainly use polymorphism instead of just RTTI

* patterns: Fixed a couple of AST memory leaks

* patterns: Parse string operations correctly

* patterns: Various fixes and cleanup

* patterns: Implement primitive function definitions

Function parameters now need to provide their type in the definition

* patterns: Added function variable definition and assignment

* patterns: Added remaining function statements

* patterns: Added unsized and while-sized arrays

* patterns: Added multi variable declarations to functions

* patterns: Added std::format built-in function

* patterns: Allow passing custom types to functions

* patterns: Added attributes and new "format" attribute

* patterns: Use libfmt for std::print instead of custom version

* patterns: Remove unnecessary string compare function

* pattern: Fix preprocessor directives

* patterns: Fix unit tests

* patterns: Added cast expression

* patterns: Handle endianess in function parameters

* patterns: Added casting to different endian

* patterns: Added 'str' type for functions
2021-09-21 21:29:18 +02:00

53 lines
1.3 KiB
C++

#pragma once
#include <hex.hpp>
#include <bit>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include <hex/pattern_language/log_console.hpp>
namespace hex::prv { class Provider; }
namespace hex::pl {
class Preprocessor;
class Lexer;
class Parser;
class Validator;
class Evaluator;
class PatternData;
class ASTNode;
class PatternLanguage {
public:
PatternLanguage();
~PatternLanguage();
std::optional<std::vector<PatternData*>> executeString(prv::Provider *provider, const std::string &string);
std::optional<std::vector<PatternData*>> executeFile(prv::Provider *provider, const std::string &path);
const std::vector<std::pair<LogConsole::Level, std::string>>& getConsoleLog();
const std::optional<std::pair<u32, std::string>>& getError();
private:
Preprocessor *m_preprocessor;
Lexer *m_lexer;
Parser *m_parser;
Validator *m_validator;
Evaluator *m_evaluator;
std::vector<ASTNode*> m_currAST;
prv::Provider *m_provider = nullptr;
std::endian m_defaultEndian = std::endian::native;
u32 m_recursionLimit = 32;
std::optional<std::pair<u32, std::string>> m_currError;
};
}