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-11-22 16:22:02 +01:00
|
|
|
Evaluator(prv::Provider* &provider, std::endian dataEndianess);
|
2020-11-19 11:36:52 +01:00
|
|
|
|
|
|
|
std::pair<Result, std::vector<PatternData*>> evaluate(const std::vector<ASTNode*>& ast);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unordered_map<std::string, ASTNode*> m_types;
|
2020-11-21 20:19:33 +01:00
|
|
|
prv::Provider* &m_provider;
|
2020-11-22 16:22:02 +01:00
|
|
|
std::endian m_dataEndianess;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|