2019-05-21 18:59:26 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
#include <utility>
|
|
|
|
|
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-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-05-21 18:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BoundExpression{
|
|
|
|
unsigned int _start;
|
|
|
|
unsigned int _length;
|
2019-06-01 17:20:31 +00:00
|
|
|
std::shared_ptr<ScriptType> _type;
|
2019-05-21 18:59:26 +00:00
|
|
|
public:
|
2019-06-01 17:20:31 +00:00
|
|
|
BoundExpression(unsigned int start, unsigned int length, std::shared_ptr<ScriptType> type){
|
2019-05-21 18:59:26 +00:00
|
|
|
_start = start;
|
|
|
|
_length = length;
|
|
|
|
_type = type;
|
|
|
|
}
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual ~BoundExpression() = default;
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
virtual BoundExpressionKind GetKind() = 0;
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual std::shared_ptr<ScriptType> GetType(){
|
2019-05-21 18:59:26 +00:00
|
|
|
return _type;
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int GetStartPosition(){
|
|
|
|
return _start;
|
|
|
|
}
|
|
|
|
unsigned int GetLength(){
|
|
|
|
return _length;
|
|
|
|
}
|
2019-05-21 20:15:51 +00:00
|
|
|
unsigned int GetEndPosition(){
|
|
|
|
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
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::Bad;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralIntegerExpression : public BoundExpression{
|
|
|
|
long _value;
|
|
|
|
public:
|
|
|
|
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
|
2019-06-01 17:20:31 +00:00
|
|
|
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)){
|
2019-05-21 18:59:26 +00:00
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::LiteralInteger;
|
|
|
|
}
|
|
|
|
|
|
|
|
long GetValue(){
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralFloatExpression : public BoundExpression{
|
|
|
|
double _value;
|
|
|
|
public:
|
|
|
|
BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length)
|
2019-06-01 17:20:31 +00:00
|
|
|
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)){
|
2019-05-21 18:59:26 +00:00
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::LiteralFloat;
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetValue(){
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralStringExpression : public BoundExpression{
|
|
|
|
string _value;
|
|
|
|
public:
|
|
|
|
BoundLiteralStringExpression(string value, unsigned int start, unsigned int length)
|
2019-06-01 17:20:31 +00:00
|
|
|
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::String)){
|
2019-05-21 18:59:26 +00:00
|
|
|
_value = std::move(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::LiteralString;
|
|
|
|
}
|
|
|
|
|
|
|
|
string GetValue(){
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoundLiteralBoolExpression : public BoundExpression{
|
|
|
|
bool _value;
|
|
|
|
public:
|
|
|
|
BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length)
|
2019-06-01 17:20:31 +00:00
|
|
|
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)){
|
2019-05-21 18:59:26 +00:00
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::LiteralBool;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetValue(){
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-30 13:23:48 +00:00
|
|
|
class BoundVariableExpression : public BoundExpression{
|
|
|
|
int _scope;
|
|
|
|
int _id;
|
|
|
|
public:
|
2019-06-01 17:20:31 +00:00
|
|
|
BoundVariableExpression(int scope, int id, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
|
|
|
|
: BoundExpression(start, length, std::move(type)){
|
2019-05-30 13:23:48 +00:00
|
|
|
_scope = scope;
|
|
|
|
_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
~BoundVariableExpression() override = default;
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::Variable;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetScope(){
|
|
|
|
return _scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetId(){
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-21 20:15:51 +00:00
|
|
|
class BoundBinaryExpression : public BoundExpression {
|
|
|
|
BoundExpression* _left;
|
|
|
|
BoundExpression* _right;
|
2019-05-22 10:22:52 +00:00
|
|
|
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)
|
|
|
|
: BoundExpression(start, length, result){
|
2019-05-21 20:15:51 +00:00
|
|
|
_left = left;
|
|
|
|
_right = right;
|
2019-05-22 10:22:52 +00:00
|
|
|
_operation = op;
|
2019-05-21 20:15:51 +00:00
|
|
|
}
|
|
|
|
~BoundBinaryExpression() final{
|
|
|
|
delete _left;
|
|
|
|
delete _right;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::Binary;
|
|
|
|
}
|
2019-05-23 16:50:09 +00:00
|
|
|
|
|
|
|
BoundExpression* GetLeft(){
|
|
|
|
return _left;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpression* GetRight(){
|
|
|
|
return _right;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundBinaryOperation GetOperation(){
|
|
|
|
return _operation;
|
|
|
|
}
|
2019-05-21 20:15:51 +00:00
|
|
|
};
|
|
|
|
|
2019-05-22 10:22:52 +00:00
|
|
|
class BoundUnaryExpression : public BoundExpression {
|
|
|
|
BoundExpression* _operand;
|
|
|
|
BoundUnaryOperation _operation;
|
|
|
|
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-05-22 10:22:52 +00:00
|
|
|
:BoundExpression(start, length, result){
|
|
|
|
_operand = operand;
|
|
|
|
_operation = op;
|
|
|
|
}
|
|
|
|
|
|
|
|
~BoundUnaryExpression() final{
|
|
|
|
delete _operand;
|
|
|
|
}
|
2019-05-21 18:59:26 +00:00
|
|
|
|
2019-05-22 10:22:52 +00:00
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::Unary;
|
|
|
|
}
|
2019-05-25 12:59:12 +00:00
|
|
|
|
|
|
|
BoundExpression* GetOperand(){
|
|
|
|
return _operand;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundUnaryOperation GetOperation(){
|
|
|
|
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 {
|
|
|
|
BoundExpression* _functionExpression;
|
|
|
|
vector<BoundExpression*> _parameters;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpressionKind GetKind() final{
|
|
|
|
return BoundExpressionKind ::FunctionCall;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpression* GetFunctionExpression(){
|
|
|
|
return _functionExpression;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<BoundExpression*> GetParameters(){
|
|
|
|
return _parameters;
|
|
|
|
}
|
|
|
|
};
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_BOUNDEXPRESSION_HPP
|