2020-11-19 11:36:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2020-11-21 20:19:33 +01:00
|
|
|
#include "providers/provider.hpp"
|
2020-11-19 11:36:52 +01:00
|
|
|
#include "lang/pattern_data.hpp"
|
|
|
|
#include "ast_node.hpp"
|
|
|
|
|
2020-11-22 16:22:02 +01:00
|
|
|
#include <bit>
|
2020-11-19 11:36:52 +01:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace hex::lang {
|
|
|
|
|
|
|
|
class Evaluator {
|
|
|
|
public:
|
2020-12-06 21:40:57 +01:00
|
|
|
Evaluator(prv::Provider* &provider, std::endian defaultDataEndianess);
|
2020-11-19 11:36:52 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::optional<std::vector<PatternData*>> evaluate(const std::vector<ASTNode*>& ast);
|
2020-11-19 11:36:52 +01:00
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
const std::pair<u32, std::string>& getError() { return this->m_error; }
|
|
|
|
|
2020-11-19 11:36:52 +01:00
|
|
|
private:
|
|
|
|
std::unordered_map<std::string, ASTNode*> m_types;
|
2020-11-21 20:19:33 +01:00
|
|
|
prv::Provider* &m_provider;
|
2020-12-06 21:40:57 +01:00
|
|
|
std::endian m_defaultDataEndianess;
|
2020-11-22 16:22:02 +01:00
|
|
|
|
2020-11-27 21:20:23 +01:00
|
|
|
std::pair<u32, std::string> m_error;
|
2020-11-19 11:36:52 +01:00
|
|
|
|
|
|
|
std::pair<PatternData*, size_t> createStructPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
2020-11-20 21:29:28 +01:00
|
|
|
std::pair<PatternData*, size_t> createUnionPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
2020-11-19 11:36:52 +01:00
|
|
|
std::pair<PatternData*, size_t> createEnumPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
2020-11-20 20:26:19 +01:00
|
|
|
std::pair<PatternData*, size_t> createBitfieldPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
2020-11-19 11:36:52 +01:00
|
|
|
std::pair<PatternData*, size_t> createArrayPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
|
|
|
std::pair<PatternData*, size_t> createStringPattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
|
|
|
std::pair<PatternData*, size_t> createCustomTypePattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
|
|
|
std::pair<PatternData*, size_t> createBuiltInTypePattern(ASTNodeVariableDecl *varDeclNode, u64 offset);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|