Handle bound classes as constants during evaluation
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-06-13 17:12:46 +02:00
parent 1cb65f17c9
commit 10a2535c96
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
12 changed files with 225 additions and 204 deletions

View File

@ -1,3 +1,7 @@
#include <utility>
#include <utility>
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP #ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
#define PORYGONLANG_BOUNDEXPRESSION_HPP #define PORYGONLANG_BOUNDEXPRESSION_HPP
@ -29,29 +33,31 @@ enum class BoundExpressionKind{
}; };
class BoundExpression{ class BoundExpression{
unsigned int _start; const unsigned int _start;
unsigned int _length; const unsigned int _length;
std::shared_ptr<ScriptType> _type; const shared_ptr<ScriptType> _type;
public: public:
BoundExpression(unsigned int start, unsigned int length, std::shared_ptr<ScriptType> type){ BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
_start = start; : _start(start),
_length = length; _length(length),
_type = std::move(type); _type(std::move(type))
{
} }
virtual ~BoundExpression() = default; virtual ~BoundExpression() = default;
virtual BoundExpressionKind GetKind() = 0; virtual const BoundExpressionKind GetKind() const = 0;
virtual std::shared_ptr<ScriptType> GetType(){ virtual const std::shared_ptr<ScriptType> GetType() const{
return _type; return _type;
}; };
unsigned int GetStartPosition(){ const unsigned int GetStartPosition() const{
return _start; return _start;
} }
unsigned int GetLength(){ const unsigned int GetLength() const{
return _length; return _length;
} }
unsigned int GetEndPosition(){ const unsigned int GetEndPosition() const{
return _start + _length - 1; return _start + _length - 1;
} }
}; };
@ -60,164 +66,172 @@ class BoundBadExpression : public BoundExpression{
public: public:
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Error)){} BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Error)){}
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::Bad; return BoundExpressionKind ::Bad;
} }
}; };
class BoundLiteralIntegerExpression : public BoundExpression{ class BoundLiteralIntegerExpression : public BoundExpression{
long _value; const long _value;
public: public:
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length) BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)){ : BoundExpression(start, length, make_shared<NumericScriptType>(true, false)),
_value = value; _value(value)
{
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::LiteralInteger; return BoundExpressionKind ::LiteralInteger;
} }
long GetValue(){ const long GetValue() const{
return _value; return _value;
} }
}; };
class BoundLiteralFloatExpression : public BoundExpression{ class BoundLiteralFloatExpression : public BoundExpression{
double _value; const double _value;
public: public:
BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length) BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length)
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)){ : BoundExpression(start, length, make_shared<NumericScriptType>(true, true)),
_value = value; _value(value)
{
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::LiteralFloat; return BoundExpressionKind ::LiteralFloat;
} }
double GetValue(){ const double GetValue() const{
return _value; return _value;
} }
}; };
class BoundLiteralStringExpression : public BoundExpression{ class BoundLiteralStringExpression : public BoundExpression{
string _value; const string _value;
public: public:
BoundLiteralStringExpression(string value, unsigned int start, unsigned int length) BoundLiteralStringExpression(string value, unsigned int start, unsigned int length)
: BoundExpression(start, length, make_shared<StringScriptType>(true, HashedString::ConstHash(value.c_str()))){ : BoundExpression(start, length, make_shared<StringScriptType>(true, HashedString::ConstHash(value.c_str()))),
_value = std::move(value); _value(value)
{
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::LiteralString; return BoundExpressionKind ::LiteralString;
} }
string GetValue(){ const string GetValue() const{
return _value; return _value;
} }
}; };
class BoundLiteralBoolExpression : public BoundExpression{ class BoundLiteralBoolExpression : public BoundExpression{
bool _value; const bool _value;
public: public:
BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length) BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length)
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)){ : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)),
_value = value; _value(value)
{
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::LiteralBool; return BoundExpressionKind ::LiteralBool;
} }
bool GetValue(){ const bool GetValue() const{
return _value; return _value;
} }
}; };
class BoundVariableExpression : public BoundExpression{ class BoundVariableExpression : public BoundExpression{
BoundVariableKey* _key; const BoundVariableKey* _key;
public: public:
BoundVariableExpression(BoundVariableKey* key, shared_ptr<ScriptType> type, unsigned int start, unsigned int length) BoundVariableExpression(BoundVariableKey* key, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
: BoundExpression(start, length, std::move(type)){ : BoundExpression(start, length, std::move(type)),
_key = key; _key(key)
{
} }
~BoundVariableExpression() override{ ~BoundVariableExpression() override{
delete _key; delete _key;
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::Variable; return BoundExpressionKind ::Variable;
} }
BoundVariableKey* GetKey(){ const BoundVariableKey* GetKey() const{
return _key; return _key;
} }
}; };
class BoundBinaryExpression : public BoundExpression { class BoundBinaryExpression : public BoundExpression {
BoundExpression* _left; const BoundExpression* _left;
BoundExpression* _right; const BoundExpression* _right;
BoundBinaryOperation _operation; const BoundBinaryOperation _operation;
public: public:
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr<ScriptType> result, BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr<ScriptType> result,
unsigned int start, unsigned int length) unsigned int start, unsigned int length)
: BoundExpression(start, length, result){ : BoundExpression(start, length, std::move(result)),
_left = left; _left(left),
_right = right; _right(right),
_operation = op; _operation(op)
{
} }
~BoundBinaryExpression() final{ ~BoundBinaryExpression() final{
delete _left; delete _left;
delete _right; delete _right;
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::Binary; return BoundExpressionKind ::Binary;
} }
BoundExpression* GetLeft(){ const BoundExpression* GetLeft() const{
return _left; return _left;
} }
BoundExpression* GetRight(){ const BoundExpression* GetRight() const{
return _right; return _right;
} }
BoundBinaryOperation GetOperation(){ const BoundBinaryOperation GetOperation() const{
return _operation; return _operation;
} }
}; };
class BoundUnaryExpression : public BoundExpression { class BoundUnaryExpression : public BoundExpression {
BoundExpression* _operand; const BoundExpression* _operand;
BoundUnaryOperation _operation; const BoundUnaryOperation _operation;
public: public:
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, shared_ptr<ScriptType> result, unsigned int start, unsigned int length) BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, shared_ptr<ScriptType> result, unsigned int start, unsigned int length)
:BoundExpression(start, length, result){ : BoundExpression(start, length, result),
_operand = operand; _operand(operand),
_operation = op; _operation(op)
{
} }
~BoundUnaryExpression() final{ ~BoundUnaryExpression() final{
delete _operand; delete _operand;
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::Unary; return BoundExpressionKind ::Unary;
} }
BoundExpression* GetOperand(){ const BoundExpression* GetOperand() const{
return _operand; return _operand;
} }
BoundUnaryOperation GetOperation(){ const BoundUnaryOperation GetOperation() const{
return _operation; return _operation;
} }
}; };
class BoundFunctionCallExpression : public BoundExpression { class BoundFunctionCallExpression : public BoundExpression {
BoundExpression* _functionExpression; const BoundExpression* _functionExpression;
vector<BoundExpression*> _parameters; const vector<BoundExpression*> _parameters;
public: public:
BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters, shared_ptr<ScriptType> result, BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters, shared_ptr<ScriptType> result,
unsigned int start, unsigned int length) unsigned int start, unsigned int length)
@ -230,16 +244,16 @@ public:
} }
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::FunctionCall; return BoundExpressionKind ::FunctionCall;
} }
BoundExpression* GetFunctionExpression(){ const BoundExpression* GetFunctionExpression() const{
return _functionExpression; return _functionExpression;
} }
vector<BoundExpression*> GetParameters(){ const vector<BoundExpression*>* GetParameters() const{
return _parameters; return &_parameters;
} }
}; };
@ -256,26 +270,26 @@ public:
delete _indexExpression; delete _indexExpression;
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::Index; return BoundExpressionKind ::Index;
} }
BoundExpression* GetIndexableExpression(){ BoundExpression* GetIndexableExpression() const{
return _indexableExpression; return _indexableExpression;
} }
BoundExpression* GetIndexExpression(){ BoundExpression* GetIndexExpression() const{
return _indexExpression; return _indexExpression;
} }
}; };
class BoundNumericalTableExpression : public BoundExpression{ class BoundNumericalTableExpression : public BoundExpression{
vector<BoundExpression*> _expressions; const vector<BoundExpression*> _expressions;
public: public:
BoundNumericalTableExpression(vector<BoundExpression*> expressions, shared_ptr<ScriptType> type, unsigned int start, unsigned int length) BoundNumericalTableExpression(vector<BoundExpression*> expressions, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
: BoundExpression(start, length, std::move(type)){ : BoundExpression(start, length, std::move(type)),
_expressions = std::move(expressions); _expressions(std::move(expressions))
} {}
~BoundNumericalTableExpression() final{ ~BoundNumericalTableExpression() final{
for (auto e: _expressions){ for (auto e: _expressions){
@ -283,12 +297,12 @@ public:
} }
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final{
return BoundExpressionKind ::NumericalTable; return BoundExpressionKind ::NumericalTable;
} }
vector<BoundExpression*> GetExpressions(){ const vector<BoundExpression*>* GetExpressions() const{
return _expressions; return &_expressions;
} }
}; };

View File

@ -18,7 +18,7 @@ public:
delete _block; delete _block;
} }
BoundExpressionKind GetKind() final{ const BoundExpressionKind GetKind() const final {
return BoundExpressionKind ::Table; return BoundExpressionKind ::Table;
} }

View File

@ -1,3 +1,5 @@
#include <utility>
#ifndef PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP #ifndef PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP
#define PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP #define PORYGONLANG_BOUNDFUNCTIONDECLARATIONSTATEMENT_HPP
@ -6,33 +8,32 @@
#include "BoundStatement.hpp" #include "BoundStatement.hpp"
class BoundFunctionDeclarationStatement : public BoundStatement{ class BoundFunctionDeclarationStatement : public BoundStatement{
BoundVariableKey* _key; const BoundVariableKey* _key;
std::shared_ptr<BoundBlockStatement> _block; const std::shared_ptr<BoundBlockStatement> _block;
std::shared_ptr<FunctionScriptType> _type; const std::shared_ptr<FunctionScriptType> _type;
public: public:
BoundFunctionDeclarationStatement(std::shared_ptr<FunctionScriptType> type, BoundVariableKey* key, BoundBlockStatement* block){ BoundFunctionDeclarationStatement(std::shared_ptr<FunctionScriptType> type, BoundVariableKey* key, BoundBlockStatement* block)
_key = key; :_key(key), _block(block), _type(std::move(type))
_block = shared_ptr<BoundBlockStatement>(block); {
_type = type;
} }
~BoundFunctionDeclarationStatement() final{ ~BoundFunctionDeclarationStatement() final{
delete _key; delete _key;
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::FunctionDeclaration; return BoundStatementKind ::FunctionDeclaration;
} }
BoundVariableKey* GetKey(){ const BoundVariableKey* GetKey() const{
return _key; return _key;
} }
std::shared_ptr<BoundBlockStatement> GetBlock(){ const std::shared_ptr<BoundBlockStatement> GetBlock() const{
return _block; return _block;
} }
std::shared_ptr<FunctionScriptType> GetType(){ const std::shared_ptr<FunctionScriptType> GetType() const{
return _type; return _type;
} }
}; };

View File

@ -1,3 +1,5 @@
#include <utility>
#ifndef PORYGONLANG_BOUNDSTATEMENT_HPP #ifndef PORYGONLANG_BOUNDSTATEMENT_HPP
@ -23,129 +25,133 @@ enum class BoundStatementKind{
class BoundStatement{ class BoundStatement{
public: public:
virtual BoundStatementKind GetKind() = 0; virtual const BoundStatementKind GetKind() const = 0;
virtual ~BoundStatement() = default; virtual ~BoundStatement() = default;
}; };
class BoundBadStatement : public BoundStatement{ class BoundBadStatement : public BoundStatement{
public: public:
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Bad; return BoundStatementKind ::Bad;
} }
}; };
class BoundBlockStatement : public BoundStatement{ class BoundBlockStatement : public BoundStatement{
vector<BoundStatement*> _statements; const vector<BoundStatement*> _statements;
public: public:
explicit BoundBlockStatement(vector<BoundStatement*> statements){ explicit BoundBlockStatement(vector<BoundStatement*> statements)
_statements = std::move(statements); : _statements(std::move(statements))
{
} }
~BoundBlockStatement() override { ~BoundBlockStatement() override {
for (auto s : _statements){ for (auto s : _statements){
delete s; delete s;
} }
_statements.clear();
} }
BoundStatementKind GetKind() override{ const BoundStatementKind GetKind() const override {
return BoundStatementKind ::Block; return BoundStatementKind ::Block;
} }
vector<BoundStatement*> GetStatements(){ const vector<BoundStatement*>* GetStatements() const{
return _statements; return &_statements;
} }
}; };
class BoundScriptStatement : public BoundBlockStatement{ class BoundScriptStatement : public BoundBlockStatement{
int _localVariableCount; const int _localVariableCount;
public: public:
explicit BoundScriptStatement(vector<BoundStatement*> statements, int localVariableCount) explicit BoundScriptStatement(vector<BoundStatement*> statements, int localVariableCount)
: BoundBlockStatement(std::move(statements)){ : BoundBlockStatement(std::move(statements)),
_localVariableCount = localVariableCount; _localVariableCount(localVariableCount)
{
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Script; return BoundStatementKind ::Script;
} }
int GetLocalVariableCount(){ const int GetLocalVariableCount() const{
return _localVariableCount; return _localVariableCount;
} }
}; };
class BoundExpressionStatement : public BoundStatement{ class BoundExpressionStatement : public BoundStatement{
BoundExpression* _expression; const BoundExpression* _expression;
public: public:
explicit BoundExpressionStatement(BoundExpression* expression){ explicit BoundExpressionStatement(BoundExpression* expression)
: _expression(expression)
{
_expression = expression; _expression = expression;
} }
~BoundExpressionStatement() final{ ~BoundExpressionStatement() final{
delete _expression; delete _expression;
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Expression; return BoundStatementKind ::Expression;
} }
BoundExpression* GetExpression(){ const BoundExpression* GetExpression() const{
return _expression; return _expression;
} }
}; };
class BoundAssignmentStatement : public BoundStatement{ class BoundAssignmentStatement : public BoundStatement{
BoundVariableKey* _key; const BoundVariableKey* _key;
BoundExpression* _expression; const BoundExpression* _expression;
public: public:
BoundAssignmentStatement(BoundVariableKey* key, BoundExpression* expression){ BoundAssignmentStatement(BoundVariableKey* key, BoundExpression* expression)
_key = key; : _key(key), _expression(expression)
_expression = expression; {
} }
~BoundAssignmentStatement() final{ ~BoundAssignmentStatement() final{
delete _key; delete _key;
delete _expression; delete _expression;
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Assignment; return BoundStatementKind ::Assignment;
} }
BoundVariableKey* GetKey(){ const BoundVariableKey* GetKey() const {
return _key; return _key;
} }
BoundExpression* GetExpression(){ const BoundExpression* GetExpression() const {
return _expression; return _expression;
} }
}; };
class BoundReturnStatement : public BoundStatement{ class BoundReturnStatement : public BoundStatement{
BoundExpression* _expression; const BoundExpression* _expression;
public: public:
explicit BoundReturnStatement(BoundExpression* expression){ explicit BoundReturnStatement(BoundExpression* expression)
_expression = expression; : _expression(expression)
{
} }
~BoundReturnStatement() final{ ~BoundReturnStatement() final{
delete _expression; delete _expression;
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Return; return BoundStatementKind ::Return;
} }
BoundExpression* GetExpression(){ const BoundExpression* GetExpression() const{
return _expression; return _expression;
} }
}; };
class BoundConditionalStatement : public BoundStatement{ class BoundConditionalStatement : public BoundStatement{
BoundExpression* _condition; const BoundExpression* _condition;
BoundStatement* _block; const BoundStatement* _block;
BoundStatement* _elseStatement; const BoundStatement* _elseStatement;
public: public:
explicit BoundConditionalStatement(BoundExpression* condition, BoundStatement* block, BoundStatement* next){ explicit BoundConditionalStatement(BoundExpression* condition, BoundStatement* block, BoundStatement* next)
_condition = condition; :_condition(condition), _block(block), _elseStatement(next)
_block = block; {
_elseStatement = next;
} }
~BoundConditionalStatement() final{ ~BoundConditionalStatement() final{
@ -154,19 +160,19 @@ public:
delete _elseStatement; delete _elseStatement;
} }
BoundStatementKind GetKind() final{ const BoundStatementKind GetKind() const final{
return BoundStatementKind ::Conditional; return BoundStatementKind ::Conditional;
} }
BoundExpression* GetCondition(){ const BoundExpression* GetCondition() const{
return _condition; return _condition;
} }
BoundStatement* GetBlock(){ const BoundStatement* GetBlock() const{
return _block; return _block;
} }
BoundStatement* GetElseStatement(){ const BoundStatement* GetElseStatement() const{
return _elseStatement; return _elseStatement;
} }
}; };

View File

@ -25,19 +25,19 @@ public:
{} {}
const int GetIdentifier(){ const int GetIdentifier() const{
return _identifier; return _identifier;
} }
const unsigned int GetScopeId(){ const unsigned int GetScopeId() const{
return _scopeId; return _scopeId;
} }
const bool IsCreation(){ const bool IsCreation() const{
return _isCreation; return _isCreation;
} }
const uint64_t GetHash(){ const uint64_t GetHash() const{
return _hash; return _hash;
} }
}; };

View File

@ -5,7 +5,7 @@
#include "EvalValues/NumericEvalValue.hpp" #include "EvalValues/NumericEvalValue.hpp"
#include "EvalValues/StringEvalValue.hpp" #include "EvalValues/StringEvalValue.hpp"
shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(BoundBinaryExpression *expression) { shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(const BoundBinaryExpression *expression) {
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft()); auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight()); auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
@ -29,7 +29,7 @@ shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(BoundBinaryExpress
return shared_ptr<NumericEvalValue>(result); return shared_ptr<NumericEvalValue>(result);
} }
shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(BoundBinaryExpression* expression){ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryExpression* expression){
switch (expression->GetOperation()){ switch (expression->GetOperation()){
case BoundBinaryOperation::Equality: case BoundBinaryOperation::Equality:
{ {
@ -93,7 +93,7 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(BoundBinaryExpress
} }
} }
shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(BoundBinaryExpression* expression){ shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression* expression){
if (expression->GetOperation() != BoundBinaryOperation::Concatenation) if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
throw; throw;
std::ostringstream strs; std::ostringstream strs;

View File

@ -38,7 +38,7 @@ public:
_hash = rand(); _hash = rand();
} }
std::shared_ptr<ScriptType> GetType(){ std::shared_ptr<ScriptType> GetType() const{
return _type; return _type;
} }
@ -57,7 +57,7 @@ public:
return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash; return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash;
}; };
std::shared_ptr<BoundBlockStatement> GetInnerBlock(){ std::shared_ptr<BoundBlockStatement> GetInnerBlock() const{
return _innerBlock; return _innerBlock;
} }
@ -65,7 +65,7 @@ public:
return _hash; return _hash;
} }
std::shared_ptr<EvaluationScope> GetScope(){ std::shared_ptr<EvaluationScope> GetScope() const{
return _scope; return _scope;
} }
}; };

View File

@ -7,7 +7,7 @@ EvaluationScope::EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>> *s
_localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(localVariableCount); _localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(localVariableCount);
} }
void EvaluationScope::CreateVariable(BoundVariableKey* key, const shared_ptr<EvalValue> &value) { void EvaluationScope::CreateVariable(const BoundVariableKey* key, const shared_ptr<EvalValue> &value) {
if (key->GetScopeId() == 0){ if (key->GetScopeId() == 0){
_scriptScope -> at(key->GetIdentifier()) = value; _scriptScope -> at(key->GetIdentifier()) = value;
} else{ } else{
@ -18,7 +18,7 @@ void EvaluationScope::CreateVariable(BoundVariableKey* key, const shared_ptr<Eva
} }
} }
void EvaluationScope::SetVariable(BoundVariableKey* key, const shared_ptr<EvalValue> &value) { void EvaluationScope::SetVariable(const BoundVariableKey* key, const shared_ptr<EvalValue> &value) {
if (key->GetScopeId() == 0){ if (key->GetScopeId() == 0){
_scriptScope -> at(key->GetIdentifier()) = value; _scriptScope -> at(key->GetIdentifier()) = value;
} else{ } else{
@ -26,7 +26,7 @@ void EvaluationScope::SetVariable(BoundVariableKey* key, const shared_ptr<EvalVa
} }
} }
shared_ptr<EvalValue> EvaluationScope::GetVariable(BoundVariableKey* key) { shared_ptr<EvalValue> EvaluationScope::GetVariable(const BoundVariableKey* key) {
if (key->GetScopeId() == 0){ if (key->GetScopeId() == 0){
return _scriptScope -> at(key->GetIdentifier()); return _scriptScope -> at(key->GetIdentifier());
} else{ } else{

View File

@ -13,9 +13,9 @@ public:
explicit EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>>* scriptVariables, int deepestScope); explicit EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>>* scriptVariables, int deepestScope);
~EvaluationScope() = default; ~EvaluationScope() = default;
void CreateVariable(BoundVariableKey* key, const shared_ptr<EvalValue>& value); void CreateVariable(const BoundVariableKey* key, const shared_ptr<EvalValue>& value);
void SetVariable(BoundVariableKey* key, const shared_ptr<EvalValue>& value); void SetVariable(const BoundVariableKey* key, const shared_ptr<EvalValue>& value);
shared_ptr<EvalValue> GetVariable(BoundVariableKey* key); shared_ptr<EvalValue> GetVariable(const BoundVariableKey* key);
}; };

View File

@ -13,18 +13,18 @@
using namespace std; using namespace std;
EvalValue* Evaluator::Evaluate(BoundScriptStatement *statement) { EvalValue* Evaluator::Evaluate(const BoundScriptStatement *statement) {
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetLocalVariableCount()); this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetLocalVariableCount());
EvaluateBlockStatement(statement, false); EvaluateBlockStatement(statement);
return this -> _returnValue.get(); return this -> _returnValue.get();
} }
void Evaluator::EvaluateStatement(BoundStatement *statement) { void Evaluator::EvaluateStatement(const BoundStatement *statement) {
if (this->_hasReturned) if (this->_hasReturned)
return; return;
switch (statement->GetKind()){ switch (statement->GetKind()){
case BoundStatementKind ::Script: throw; // Should never happen case BoundStatementKind ::Script: throw; // Should never happen
case BoundStatementKind ::Block: return this -> EvaluateBlockStatement((BoundBlockStatement*)statement, true); case BoundStatementKind ::Block: return this->EvaluateBlockStatement((BoundBlockStatement *) statement);
case BoundStatementKind ::Expression: return this -> EvaluateExpressionStatement((BoundExpressionStatement*)statement); case BoundStatementKind ::Expression: return this -> EvaluateExpressionStatement((BoundExpressionStatement*)statement);
case BoundStatementKind ::Assignment: return this -> EvaluateAssignmentStatement((BoundAssignmentStatement*)statement); case BoundStatementKind ::Assignment: return this -> EvaluateAssignmentStatement((BoundAssignmentStatement*)statement);
case BoundStatementKind ::FunctionDeclaration: return this->EvaluateFunctionDeclarationStatement((BoundFunctionDeclarationStatement*)statement); case BoundStatementKind ::FunctionDeclaration: return this->EvaluateFunctionDeclarationStatement((BoundFunctionDeclarationStatement*)statement);
@ -36,20 +36,20 @@ void Evaluator::EvaluateStatement(BoundStatement *statement) {
} }
} }
void Evaluator::EvaluateBlockStatement(BoundBlockStatement* statement, bool clearScope) { void Evaluator::EvaluateBlockStatement(const BoundBlockStatement *statement) {
for (auto s: statement->GetStatements()){ for (auto s: *statement->GetStatements()){
this -> EvaluateStatement(s); this -> EvaluateStatement(s);
if (this->_hasReturned) if (this->_hasReturned)
break; break;
} }
} }
void Evaluator::EvaluateExpressionStatement(BoundExpressionStatement *statement) { void Evaluator::EvaluateExpressionStatement(const BoundExpressionStatement *statement) {
// Save new value // Save new value
this->_lastValue = this -> EvaluateExpression(statement->GetExpression()); this->_lastValue = this -> EvaluateExpression(statement->GetExpression());
} }
void Evaluator::EvaluateAssignmentStatement(BoundAssignmentStatement *statement) { void Evaluator::EvaluateAssignmentStatement(const BoundAssignmentStatement *statement) {
auto value = this -> EvaluateExpression(statement->GetExpression()); auto value = this -> EvaluateExpression(statement->GetExpression());
auto key = statement->GetKey(); auto key = statement->GetKey();
if (key->IsCreation()){ if (key->IsCreation()){
@ -59,7 +59,7 @@ void Evaluator::EvaluateAssignmentStatement(BoundAssignmentStatement *statement)
} }
} }
void Evaluator::EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationStatement *statement) { void Evaluator::EvaluateFunctionDeclarationStatement(const BoundFunctionDeclarationStatement *statement) {
auto type = statement->GetType(); auto type = statement->GetType();
auto key = statement->GetKey(); auto key = statement->GetKey();
auto block = statement->GetBlock(); auto block = statement->GetBlock();
@ -71,7 +71,7 @@ void Evaluator::EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationSta
} }
} }
void Evaluator::EvaluateReturnStatement(BoundReturnStatement* statement){ void Evaluator::EvaluateReturnStatement(const BoundReturnStatement* statement){
auto expression = statement->GetExpression(); auto expression = statement->GetExpression();
if (expression == nullptr){ if (expression == nullptr){
this->_hasReturned = true; this->_hasReturned = true;
@ -82,7 +82,7 @@ void Evaluator::EvaluateReturnStatement(BoundReturnStatement* statement){
this -> _returnValue = value; this -> _returnValue = value;
} }
void Evaluator::EvaluateConditionalStatement(BoundConditionalStatement *statement) { void Evaluator::EvaluateConditionalStatement(const BoundConditionalStatement *statement) {
auto condition = statement->GetCondition(); auto condition = statement->GetCondition();
if (EvaluateBoolExpression(condition) -> EvaluateBool()){ if (EvaluateBoolExpression(condition) -> EvaluateBool()){
this -> EvaluateStatement(statement->GetBlock()); this -> EvaluateStatement(statement->GetBlock());
@ -94,7 +94,7 @@ void Evaluator::EvaluateConditionalStatement(BoundConditionalStatement *statemen
} }
} }
shared_ptr<EvalValue> Evaluator::EvaluateExpression(BoundExpression *expression) { shared_ptr<EvalValue> Evaluator::EvaluateExpression(const BoundExpression *expression) {
auto type = expression -> GetType(); auto type = expression -> GetType();
switch (type->GetClass()){ switch (type->GetClass()){
case TypeClass ::Number: return this -> EvaluateIntegerExpression(expression); case TypeClass ::Number: return this -> EvaluateIntegerExpression(expression);
@ -107,7 +107,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateExpression(BoundExpression *expression)
} }
} }
shared_ptr<EvalValue> Evaluator::GetVariable(BoundVariableExpression* expression){ shared_ptr<EvalValue> Evaluator::GetVariable(const BoundVariableExpression* expression){
auto variable = this->_evaluationScope->GetVariable(expression->GetKey()); auto variable = this->_evaluationScope->GetVariable(expression->GetKey());
if (variable == nullptr){ if (variable == nullptr){
throw EvaluationException("Variable not found"); throw EvaluationException("Variable not found");
@ -115,7 +115,7 @@ shared_ptr<EvalValue> Evaluator::GetVariable(BoundVariableExpression* expression
return variable->Clone(); return variable->Clone();
} }
shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerExpression(BoundExpression *expression) { shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerExpression(const BoundExpression *expression) {
switch (expression->GetKind()){ switch (expression->GetKind()){
case BoundExpressionKind ::LiteralInteger: return make_shared<IntegerEvalValue>(((BoundLiteralIntegerExpression*)expression)->GetValue()); case BoundExpressionKind ::LiteralInteger: return make_shared<IntegerEvalValue>(((BoundLiteralIntegerExpression*)expression)->GetValue());
case BoundExpressionKind ::LiteralFloat: return make_shared<FloatEvalValue>(((BoundLiteralFloatExpression*)expression)->GetValue()); case BoundExpressionKind ::LiteralFloat: return make_shared<FloatEvalValue>(((BoundLiteralFloatExpression*)expression)->GetValue());
@ -134,7 +134,7 @@ shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerExpression(BoundExpressio
} }
} }
shared_ptr<BooleanEvalValue> Evaluator::EvaluateBoolExpression(BoundExpression *expression) { shared_ptr<BooleanEvalValue> Evaluator::EvaluateBoolExpression(const BoundExpression *expression) {
switch (expression->GetKind()) { switch (expression->GetKind()) {
case BoundExpressionKind ::LiteralBool: return make_shared<BooleanEvalValue>(((BoundLiteralBoolExpression*)expression)->GetValue()); case BoundExpressionKind ::LiteralBool: return make_shared<BooleanEvalValue>(((BoundLiteralBoolExpression*)expression)->GetValue());
case BoundExpressionKind::Unary: return this -> EvaluateBooleanUnary((BoundUnaryExpression*)expression); case BoundExpressionKind::Unary: return this -> EvaluateBooleanUnary((BoundUnaryExpression*)expression);
@ -154,7 +154,7 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBoolExpression(BoundExpression *
} }
} }
shared_ptr<StringEvalValue> Evaluator::EvaluateStringExpression(BoundExpression *expression) { shared_ptr<StringEvalValue> Evaluator::EvaluateStringExpression(const BoundExpression *expression) {
switch (expression->GetKind()) { switch (expression->GetKind()) {
case BoundExpressionKind ::LiteralString: case BoundExpressionKind ::LiteralString:
return make_shared<StringEvalValue>(((BoundLiteralStringExpression*)expression)->GetValue()); return make_shared<StringEvalValue>(((BoundLiteralStringExpression*)expression)->GetValue());
@ -176,14 +176,14 @@ shared_ptr<StringEvalValue> Evaluator::EvaluateStringExpression(BoundExpression
} }
} }
shared_ptr<EvalValue> Evaluator::EvaluateFunctionExpression(BoundExpression * expression){ shared_ptr<EvalValue> Evaluator::EvaluateFunctionExpression(const BoundExpression * expression){
switch (expression->GetKind()){ switch (expression->GetKind()){
case BoundExpressionKind ::Variable: return this->GetVariable((BoundVariableExpression*)expression); case BoundExpressionKind ::Variable: return this->GetVariable((BoundVariableExpression*)expression);
case BoundExpressionKind ::Index: return this->EvaluateIndexExpression(expression); case BoundExpressionKind ::Index: return this->EvaluateIndexExpression(expression);
default: throw; default: throw;
} }
} }
shared_ptr<EvalValue> Evaluator::EvaluateNilExpression(BoundExpression * expression){ shared_ptr<EvalValue> Evaluator::EvaluateNilExpression(const BoundExpression * expression){
switch (expression->GetKind()){ switch (expression->GetKind()){
case BoundExpressionKind ::FunctionCall: case BoundExpressionKind ::FunctionCall:
return this->EvaluateFunctionCallExpression(expression); return this->EvaluateFunctionCallExpression(expression);
@ -191,7 +191,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateNilExpression(BoundExpression * express
return nullptr; return nullptr;
} }
} }
shared_ptr<EvalValue> Evaluator::EvaluateTableExpression(BoundExpression * expression){ shared_ptr<EvalValue> Evaluator::EvaluateTableExpression(const BoundExpression * expression){
switch (expression->GetKind()){ switch (expression->GetKind()){
case BoundExpressionKind ::FunctionCall: case BoundExpressionKind ::FunctionCall:
return this->EvaluateFunctionCallExpression(expression); return this->EvaluateFunctionCallExpression(expression);
@ -207,14 +207,14 @@ shared_ptr<EvalValue> Evaluator::EvaluateTableExpression(BoundExpression * expre
shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression* expression){ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(const BoundExpression* expression){
auto functionCall = (BoundFunctionCallExpression*)expression; auto functionCall = (BoundFunctionCallExpression*)expression;
auto function = dynamic_pointer_cast<ScriptFunctionEvalValue>(this->EvaluateExpression(functionCall->GetFunctionExpression())); auto function = dynamic_pointer_cast<ScriptFunctionEvalValue>(this->EvaluateExpression(functionCall->GetFunctionExpression()));
auto boundParameters = functionCall->GetParameters(); auto boundParameters = functionCall->GetParameters();
auto parameters = vector<shared_ptr<EvalValue>>(boundParameters.size()); auto parameters = vector<shared_ptr<EvalValue>>(boundParameters->size());
for (int i = 0; i < boundParameters.size(); i++){ for (int i = 0; i < boundParameters->size(); i++){
parameters[i] = this->EvaluateExpression(boundParameters[i]); parameters[i] = this->EvaluateExpression(boundParameters->at(i));
} }
auto type = std::dynamic_pointer_cast<FunctionScriptType>(function->GetType()); auto type = std::dynamic_pointer_cast<FunctionScriptType>(function->GetType());
@ -228,7 +228,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
auto key = parameterKeys.at(i); auto key = parameterKeys.at(i);
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone()); this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
} }
this->EvaluateBlockStatement(function->GetInnerBlock().get(), true); this->EvaluateBlockStatement(function->GetInnerBlock().get());
this->_evaluationScope = originalScope; this->_evaluationScope = originalScope;
this->_hasReturned = false; this->_hasReturned = false;
@ -237,7 +237,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
return r; return r;
} }
shared_ptr<EvalValue> Evaluator::EvaluateFunction(ScriptFunctionEvalValue *function, vector<EvalValue *> parameters) { shared_ptr<EvalValue> Evaluator::EvaluateFunction(const ScriptFunctionEvalValue *function, const vector<EvalValue *>& parameters) {
auto type = std::dynamic_pointer_cast<FunctionScriptType>(function->GetType()); auto type = std::dynamic_pointer_cast<FunctionScriptType>(function->GetType());
auto parameterTypes = type->GetParameterTypes(); auto parameterTypes = type->GetParameterTypes();
auto parameterKeys = type->GetParameterKeys(); auto parameterKeys = type->GetParameterKeys();
@ -250,7 +250,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunction(ScriptFunctionEvalValue *funct
auto key = parameterKeys.at(i); auto key = parameterKeys.at(i);
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone()); this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
} }
this->EvaluateBlockStatement(function->GetInnerBlock().get(), true); this->EvaluateBlockStatement(function->GetInnerBlock().get());
this->_evaluationScope = originalScope; this->_evaluationScope = originalScope;
this->_hasReturned = false; this->_hasReturned = false;
auto r = this -> _returnValue; auto r = this -> _returnValue;
@ -258,26 +258,26 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunction(ScriptFunctionEvalValue *funct
return r; return r;
} }
shared_ptr<EvalValue> Evaluator::EvaluateIndexExpression(BoundExpression *expression) { shared_ptr<EvalValue> Evaluator::EvaluateIndexExpression(const BoundExpression *expression) {
auto indexExpression = (BoundIndexExpression*)expression; auto indexExpression = (BoundIndexExpression*)expression;
auto index = this -> EvaluateExpression(indexExpression->GetIndexExpression()); auto index = this -> EvaluateExpression(indexExpression->GetIndexExpression());
auto indexable = this -> EvaluateExpression(indexExpression->GetIndexableExpression()); auto indexable = this -> EvaluateExpression(indexExpression->GetIndexableExpression());
return indexable -> IndexValue(index.get()) -> Clone(); return indexable -> IndexValue(index.get()) -> Clone();
} }
shared_ptr<EvalValue> Evaluator::EvaluateNumericTableExpression(BoundExpression *expression) { shared_ptr<EvalValue> Evaluator::EvaluateNumericTableExpression(const BoundExpression *expression) {
auto tableExpression = (BoundNumericalTableExpression*)expression; auto tableExpression = (BoundNumericalTableExpression*)expression;
auto valueExpressions = tableExpression->GetExpressions(); auto valueExpressions = tableExpression->GetExpressions();
auto values = new unordered_map<size_t, shared_ptr<EvalValue>>(valueExpressions.size()); auto values = new unordered_map<size_t, shared_ptr<EvalValue>>(valueExpressions->size());
for (int i = 0; i < valueExpressions.size(); i++){ for (int i = 0; i < valueExpressions->size(); i++){
auto val = this -> EvaluateExpression(valueExpressions[i]); auto val = this -> EvaluateExpression(valueExpressions -> at(i));
values -> insert({i + 1, val}); values -> insert({i + 1, val});
} }
auto valuesPointer = shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>>(values); auto valuesPointer = shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>>(values);
return make_shared<TableEvalValue>(valuesPointer); return make_shared<TableEvalValue>(valuesPointer);
} }
shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression *expression) { shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(const BoundExpression *expression) {
auto tableExpression = (BoundTableExpression*)expression; auto tableExpression = (BoundTableExpression*)expression;
auto type = dynamic_pointer_cast<TableScriptType>(tableExpression->GetType()); auto type = dynamic_pointer_cast<TableScriptType>(tableExpression->GetType());
auto declaredVars = type -> GetValues(); auto declaredVars = type -> GetValues();
@ -288,7 +288,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression
auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetLocalVariableCount()); auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetLocalVariableCount());
auto currentEvaluator = this -> _evaluationScope; auto currentEvaluator = this -> _evaluationScope;
this -> _evaluationScope = evaluator; this -> _evaluationScope = evaluator;
this -> EvaluateBlockStatement(tableExpression->GetBlock(), false); this->EvaluateBlockStatement(tableExpression->GetBlock());
this -> _evaluationScope = currentEvaluator; this -> _evaluationScope = currentEvaluator;
return make_shared<TableEvalValue>(variables); return make_shared<TableEvalValue>(variables);
} }

View File

@ -22,34 +22,34 @@ class Evaluator {
Script* _scriptData; Script* _scriptData;
shared_ptr<EvaluationScope> _evaluationScope; shared_ptr<EvaluationScope> _evaluationScope;
void EvaluateStatement(BoundStatement* statement); void EvaluateStatement(const BoundStatement* statement);
void EvaluateBlockStatement(BoundBlockStatement* statement, bool clearScope); void EvaluateBlockStatement(const BoundBlockStatement *statement);
void EvaluateExpressionStatement(BoundExpressionStatement* statement); void EvaluateExpressionStatement(const BoundExpressionStatement* statement);
void EvaluateAssignmentStatement(BoundAssignmentStatement* statement); void EvaluateAssignmentStatement(const BoundAssignmentStatement* statement);
void EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationStatement *statement); void EvaluateFunctionDeclarationStatement(const BoundFunctionDeclarationStatement *statement);
void EvaluateReturnStatement(BoundReturnStatement *statement); void EvaluateReturnStatement(const BoundReturnStatement *statement);
void EvaluateConditionalStatement(BoundConditionalStatement *statement); void EvaluateConditionalStatement(const BoundConditionalStatement *statement);
shared_ptr<EvalValue> EvaluateExpression(BoundExpression* expression); shared_ptr<EvalValue> EvaluateExpression(const BoundExpression* expression);
shared_ptr<NumericEvalValue> EvaluateIntegerExpression(BoundExpression* expression); shared_ptr<NumericEvalValue> EvaluateIntegerExpression(const BoundExpression* expression);
shared_ptr<BooleanEvalValue> EvaluateBoolExpression(BoundExpression* expression); shared_ptr<BooleanEvalValue> EvaluateBoolExpression(const BoundExpression* expression);
shared_ptr<StringEvalValue> EvaluateStringExpression(BoundExpression* expression); shared_ptr<StringEvalValue> EvaluateStringExpression(const BoundExpression* expression);
shared_ptr<EvalValue> EvaluateFunctionExpression(BoundExpression *expression); shared_ptr<EvalValue> EvaluateFunctionExpression(const BoundExpression *expression);
shared_ptr<EvalValue>EvaluateNilExpression(BoundExpression *expression); shared_ptr<EvalValue>EvaluateNilExpression(const BoundExpression *expression);
shared_ptr<EvalValue>EvaluateTableExpression(BoundExpression *expression); shared_ptr<EvalValue>EvaluateTableExpression(const BoundExpression *expression);
shared_ptr<NumericEvalValue> EvaluateIntegerBinary(BoundBinaryExpression* expression); shared_ptr<NumericEvalValue> EvaluateIntegerBinary(const BoundBinaryExpression* expression);
shared_ptr<BooleanEvalValue> EvaluateBooleanBinary(BoundBinaryExpression *expression); shared_ptr<BooleanEvalValue> EvaluateBooleanBinary(const BoundBinaryExpression *expression);
shared_ptr<StringEvalValue> EvaluateStringBinary(BoundBinaryExpression *expression); shared_ptr<StringEvalValue> EvaluateStringBinary(const BoundBinaryExpression *expression);
shared_ptr<NumericEvalValue> EvaluateIntegerUnary(BoundUnaryExpression* expression); shared_ptr<NumericEvalValue> EvaluateIntegerUnary(const BoundUnaryExpression* expression);
shared_ptr<BooleanEvalValue> EvaluateBooleanUnary(BoundUnaryExpression *expression); shared_ptr<BooleanEvalValue> EvaluateBooleanUnary(const BoundUnaryExpression *expression);
shared_ptr<EvalValue> EvaluateFunctionCallExpression(BoundExpression *expression); shared_ptr<EvalValue> EvaluateFunctionCallExpression(const BoundExpression *expression);
shared_ptr<EvalValue> EvaluateIndexExpression(BoundExpression* expression); shared_ptr<EvalValue> EvaluateIndexExpression(const BoundExpression* expression);
shared_ptr<EvalValue> EvaluateNumericTableExpression(BoundExpression* expression); shared_ptr<EvalValue> EvaluateNumericTableExpression(const BoundExpression* expression);
shared_ptr<EvalValue> EvaluateComplexTableExpression(BoundExpression *expression); shared_ptr<EvalValue> EvaluateComplexTableExpression(const BoundExpression *expression);
shared_ptr<EvalValue> GetVariable(BoundVariableExpression *expression); shared_ptr<EvalValue> GetVariable(const BoundVariableExpression *expression);
public: public:
explicit Evaluator(Script* script){ explicit Evaluator(Script* script){
_scriptData = script; _scriptData = script;
@ -58,8 +58,8 @@ public:
_evaluationScope = nullptr; _evaluationScope = nullptr;
} }
EvalValue* Evaluate(BoundScriptStatement* statement); EvalValue* Evaluate(const BoundScriptStatement* statement);
shared_ptr<EvalValue> EvaluateFunction(ScriptFunctionEvalValue* func, vector<EvalValue*> parameters); shared_ptr<EvalValue> EvaluateFunction(const ScriptFunctionEvalValue *function, const vector<EvalValue *>& parameters);
EvalValue* GetLastValue(){ EvalValue* GetLastValue(){
return _lastValue.get(); return _lastValue.get();

View File

@ -4,7 +4,7 @@
#include "EvaluationException.hpp" #include "EvaluationException.hpp"
#include "../Script.hpp" #include "../Script.hpp"
shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerUnary(BoundUnaryExpression *expression) { shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerUnary(const BoundUnaryExpression *expression) {
switch (expression->GetOperation()){ switch (expression->GetOperation()){
case BoundUnaryOperation::Negation: case BoundUnaryOperation::Negation:
{ {
@ -22,7 +22,7 @@ shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerUnary(BoundUnaryExpressio
} }
} }
shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanUnary(BoundUnaryExpression *expression) { shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanUnary(const BoundUnaryExpression *expression) {
switch (expression->GetOperation()){ switch (expression->GetOperation()){
case BoundUnaryOperation::LogicalNegation: case BoundUnaryOperation::LogicalNegation:
{ {