#pragma once #include #include #include #include #include #include #include #include #include #include namespace hex::lang { class Evaluator { public: Evaluator() = default; std::optional> evaluate(const std::vector& ast); LogConsole& getConsole() { return this->m_console; } void setDefaultEndian(std::endian endian) { this->m_defaultDataEndian = endian; } void setRecursionLimit(u32 limit) { this->m_recursionLimit = limit; } void setProvider(prv::Provider *provider) { this->m_provider = provider; } [[nodiscard]] std::endian getCurrentEndian() const { return this->m_endianStack.back(); } PatternData* patternFromName(const std::vector &name); template T* asType(ASTNode *param) { if (auto evaluatedParam = dynamic_cast(param); evaluatedParam != nullptr) return evaluatedParam; else this->getConsole().abortEvaluation("function got wrong type of parameter"); } private: std::map m_types; prv::Provider* m_provider = nullptr; std::endian m_defaultDataEndian = std::endian::native; u64 m_currOffset = 0; std::vector m_endianStack; std::vector m_globalMembers; std::vector*> m_currMembers; std::vector m_currMemberScope; LogConsole m_console; u32 m_recursionLimit; u32 m_currRecursionDepth; ASTNodeIntegerLiteral* evaluateScopeResolution(ASTNodeScopeResolution *node); ASTNodeIntegerLiteral* evaluateRValue(ASTNodeRValue *node); ASTNode* evaluateFunctionCall(ASTNodeFunctionCall *node); ASTNodeIntegerLiteral* evaluateOperator(ASTNodeIntegerLiteral *left, ASTNodeIntegerLiteral *right, Token::Operator op); ASTNodeIntegerLiteral* evaluateOperand(ASTNode *node); ASTNodeIntegerLiteral* evaluateTernaryExpression(ASTNodeTernaryExpression *node); ASTNodeIntegerLiteral* evaluateMathematicalExpression(ASTNodeNumericExpression *node); PatternData* findPattern(std::vector currMembers, const std::vector &path); PatternData* evaluateAttributes(ASTNode *currNode, PatternData *currPattern); PatternData* evaluateBuiltinType(ASTNodeBuiltinType *node); void evaluateMember(ASTNode *node, std::vector &currMembers, bool increaseOffset); PatternData* evaluateStruct(ASTNodeStruct *node); PatternData* evaluateUnion(ASTNodeUnion *node); PatternData* evaluateEnum(ASTNodeEnum *node); PatternData* evaluateBitfield(ASTNodeBitfield *node); PatternData* evaluateType(ASTNodeTypeDecl *node); PatternData* evaluateVariable(ASTNodeVariableDecl *node); PatternData* evaluateArray(ASTNodeArrayVariableDecl *node); PatternData* evaluatePointer(ASTNodePointerVariableDecl *node); }; }