2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
|
|
|
|
#define PORYGONLANG_BOUNDEXPRESSION_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2019-06-01 17:20:31 +00:00
|
|
|
#include <memory>
|
2019-06-09 18:15:09 +00:00
|
|
|
#include <utility>
|
2019-05-21 18:59:26 +00:00
|
|
|
#include "../../ScriptType.hpp"
|
2019-05-21 20:15:51 +00:00
|
|
|
#include "../BoundOperators.hpp"
|
2019-05-30 13:23:48 +00:00
|
|
|
#include "../BoundVariables/BoundVariableKey.hpp"
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
enum class BoundExpressionKind{
|
|
|
|
Bad,
|
|
|
|
|
|
|
|
LiteralInteger,
|
|
|
|
LiteralFloat,
|
|
|
|
LiteralString,
|
|
|
|
LiteralBool,
|
2019-05-30 13:23:48 +00:00
|
|
|
Variable,
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
Unary,
|
|
|
|
Binary,
|
2019-06-01 17:20:31 +00:00
|
|
|
FunctionCall,
|
2019-06-06 15:35:51 +00:00
|
|
|
Index,
|
2019-06-09 18:15:09 +00:00
|
|
|
NumericalTable,
|
2019-06-12 13:19:28 +00:00
|
|
|
Table,
|
2019-05-21 18:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const unsigned int _start;
|
|
|
|
const unsigned int _length;
|
|
|
|
const shared_ptr<ScriptType> _type;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
2019-06-13 15:37:23 +00:00
|
|
|
BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
|
2019-06-13 15:12:46 +00:00
|
|
|
: _start(start),
|
|
|
|
_length(length),
|
|
|
|
_type(std::move(type))
|
|
|
|
{
|
2019-05-21 18:59:26 +00:00
|
|
|
}
|
2019-06-13 15:12:46 +00:00
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual ~BoundExpression() = default;
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
virtual const BoundExpressionKind GetKind() const = 0;
|
2019-06-13 15:37:23 +00:00
|
|
|
virtual const std::shared_ptr<ScriptType>& GetType() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _type;
|
|
|
|
};
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const unsigned int GetStartPosition() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _start;
|
|
|
|
}
|
2019-06-13 15:12:46 +00:00
|
|
|
const unsigned int GetLength() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _length;
|
|
|
|
}
|
2019-06-13 15:12:46 +00:00
|
|
|
const unsigned int GetEndPosition() const{
|
2019-05-21 20:15:51 +00:00
|
|
|
return _start + _length - 1;
|
|
|
|
}
|
2019-05-21 18:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BoundBadExpression : public BoundExpression{
|
|
|
|
public:
|
2019-06-01 17:20:31 +00:00
|
|
|
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Error)){}
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 18:59:26 +00:00
|
|
|
return BoundExpressionKind ::Bad;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralIntegerExpression : public BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const long _value;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
|
|
|
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)),
|
|
|
|
_value(value)
|
|
|
|
{
|
2019-05-21 18:59:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 18:59:26 +00:00
|
|
|
return BoundExpressionKind ::LiteralInteger;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const long GetValue() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralFloatExpression : public BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const double _value;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
|
|
|
BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)),
|
|
|
|
_value(value)
|
|
|
|
{
|
2019-05-21 18:59:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 18:59:26 +00:00
|
|
|
return BoundExpressionKind ::LiteralFloat;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const double GetValue() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralStringExpression : public BoundExpression{
|
2019-06-15 15:20:27 +00:00
|
|
|
const u16string _value;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
2019-06-15 15:20:27 +00:00
|
|
|
BoundLiteralStringExpression(u16string value, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, make_shared<StringScriptType>(true, HashedString::ConstHash(value.c_str()))),
|
|
|
|
_value(value)
|
|
|
|
{
|
2019-05-21 18:59:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 18:59:26 +00:00
|
|
|
return BoundExpressionKind ::LiteralString;
|
|
|
|
}
|
|
|
|
|
2019-06-15 15:20:27 +00:00
|
|
|
const u16string GetValue() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralBoolExpression : public BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const bool _value;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
|
|
|
BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)),
|
|
|
|
_value(value)
|
|
|
|
{
|
2019-05-21 18:59:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 18:59:26 +00:00
|
|
|
return BoundExpressionKind ::LiteralBool;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const bool GetValue() const{
|
2019-05-21 18:59:26 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-30 13:23:48 +00:00
|
|
|
class BoundVariableExpression : public BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundVariableKey* _key;
|
2019-05-30 13:23:48 +00:00
|
|
|
public:
|
2019-06-13 13:16:41 +00:00
|
|
|
BoundVariableExpression(BoundVariableKey* key, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, std::move(type)),
|
|
|
|
_key(key)
|
|
|
|
{
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 13:18:20 +00:00
|
|
|
~BoundVariableExpression() override{
|
|
|
|
delete _key;
|
|
|
|
}
|
2019-05-30 13:23:48 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-30 13:23:48 +00:00
|
|
|
return BoundExpressionKind ::Variable;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundVariableKey* GetKey() const{
|
2019-06-13 13:16:41 +00:00
|
|
|
return _key;
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-21 20:15:51 +00:00
|
|
|
class BoundBinaryExpression : public BoundExpression {
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* _left;
|
|
|
|
const BoundExpression* _right;
|
|
|
|
const BoundBinaryOperation _operation;
|
2019-05-21 20:15:51 +00:00
|
|
|
public:
|
2019-06-01 17:20:31 +00:00
|
|
|
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr<ScriptType> result,
|
2019-05-22 10:29:29 +00:00
|
|
|
unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, std::move(result)),
|
|
|
|
_left(left),
|
|
|
|
_right(right),
|
|
|
|
_operation(op)
|
|
|
|
{
|
2019-05-21 20:15:51 +00:00
|
|
|
}
|
2019-06-13 15:12:46 +00:00
|
|
|
|
2019-05-21 20:15:51 +00:00
|
|
|
~BoundBinaryExpression() final{
|
|
|
|
delete _left;
|
|
|
|
delete _right;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-21 20:15:51 +00:00
|
|
|
return BoundExpressionKind ::Binary;
|
|
|
|
}
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* GetLeft() const{
|
2019-05-23 16:50:09 +00:00
|
|
|
return _left;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* GetRight() const{
|
2019-05-23 16:50:09 +00:00
|
|
|
return _right;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundBinaryOperation GetOperation() const{
|
2019-05-23 16:50:09 +00:00
|
|
|
return _operation;
|
|
|
|
}
|
2019-05-21 20:15:51 +00:00
|
|
|
};
|
|
|
|
|
2019-05-22 10:22:52 +00:00
|
|
|
class BoundUnaryExpression : public BoundExpression {
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* _operand;
|
|
|
|
const BoundUnaryOperation _operation;
|
2019-05-22 10:22:52 +00:00
|
|
|
public:
|
2019-06-01 17:20:31 +00:00
|
|
|
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, shared_ptr<ScriptType> result, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, result),
|
|
|
|
_operand(operand),
|
|
|
|
_operation(op)
|
|
|
|
{
|
2019-05-22 10:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~BoundUnaryExpression() final{
|
|
|
|
delete _operand;
|
|
|
|
}
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-05-22 10:22:52 +00:00
|
|
|
return BoundExpressionKind ::Unary;
|
|
|
|
}
|
2019-05-25 12:59:12 +00:00
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* GetOperand() const{
|
2019-05-25 12:59:12 +00:00
|
|
|
return _operand;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundUnaryOperation GetOperation() const{
|
2019-05-25 12:59:12 +00:00
|
|
|
return _operation;
|
|
|
|
}
|
2019-05-22 10:22:52 +00:00
|
|
|
};
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
class BoundFunctionCallExpression : public BoundExpression {
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* _functionExpression;
|
|
|
|
const vector<BoundExpression*> _parameters;
|
2019-06-01 17:20:31 +00:00
|
|
|
public:
|
|
|
|
BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters, shared_ptr<ScriptType> result,
|
|
|
|
unsigned int start, unsigned int length)
|
|
|
|
: BoundExpression(start, length, result), _functionExpression(functionExpression), _parameters(std::move(parameters)) {}
|
|
|
|
|
|
|
|
~BoundFunctionCallExpression() final{
|
|
|
|
delete _functionExpression;
|
|
|
|
for (auto p : _parameters){
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-06-01 17:20:31 +00:00
|
|
|
return BoundExpressionKind ::FunctionCall;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpression* GetFunctionExpression() const{
|
2019-06-01 17:20:31 +00:00
|
|
|
return _functionExpression;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const vector<BoundExpression*>* GetParameters() const{
|
|
|
|
return &_parameters;
|
2019-06-01 17:20:31 +00:00
|
|
|
}
|
|
|
|
};
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-06-06 15:35:51 +00:00
|
|
|
class BoundIndexExpression : public BoundExpression {
|
|
|
|
BoundExpression* _indexableExpression;
|
|
|
|
BoundExpression* _indexExpression;
|
|
|
|
public:
|
|
|
|
BoundIndexExpression(BoundExpression* indexableExpression, BoundExpression* indexExpression, shared_ptr<ScriptType> result,
|
|
|
|
unsigned int start, unsigned int length)
|
|
|
|
: BoundExpression(start, length, std::move(result)), _indexableExpression(indexableExpression), _indexExpression(indexExpression) {}
|
|
|
|
|
|
|
|
~BoundIndexExpression() final{
|
|
|
|
delete _indexableExpression;
|
|
|
|
delete _indexExpression;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-06-06 15:35:51 +00:00
|
|
|
return BoundExpressionKind ::Index;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
BoundExpression* GetIndexableExpression() const{
|
2019-06-06 15:35:51 +00:00
|
|
|
return _indexableExpression;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
BoundExpression* GetIndexExpression() const{
|
2019-06-06 15:35:51 +00:00
|
|
|
return _indexExpression;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-09 18:15:09 +00:00
|
|
|
class BoundNumericalTableExpression : public BoundExpression{
|
2019-06-13 15:12:46 +00:00
|
|
|
const vector<BoundExpression*> _expressions;
|
2019-06-09 18:15:09 +00:00
|
|
|
public:
|
|
|
|
BoundNumericalTableExpression(vector<BoundExpression*> expressions, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
|
2019-06-13 15:12:46 +00:00
|
|
|
: BoundExpression(start, length, std::move(type)),
|
|
|
|
_expressions(std::move(expressions))
|
|
|
|
{}
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-12 13:19:28 +00:00
|
|
|
~BoundNumericalTableExpression() final{
|
2019-06-09 18:15:09 +00:00
|
|
|
for (auto e: _expressions){
|
|
|
|
delete e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const BoundExpressionKind GetKind() const final{
|
2019-06-09 18:15:09 +00:00
|
|
|
return BoundExpressionKind ::NumericalTable;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:12:46 +00:00
|
|
|
const vector<BoundExpression*>* GetExpressions() const{
|
|
|
|
return &_expressions;
|
2019-06-09 18:15:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
#endif //PORYGONLANG_BOUNDEXPRESSION_HPP
|