PorygonLang/src/Binder/BoundExpressions/BoundExpression.hpp

196 lines
4.5 KiB
C++
Raw Normal View History

#include <utility>
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
#define PORYGONLANG_BOUNDEXPRESSION_HPP
#include <string>
#include "../../ScriptType.hpp"
2019-05-21 20:15:51 +00:00
#include "../BoundOperators.hpp"
using namespace std;
enum class BoundExpressionKind{
Bad,
LiteralInteger,
LiteralFloat,
LiteralString,
LiteralBool,
Unary,
Binary,
};
class BoundExpression{
unsigned int _start;
unsigned int _length;
ScriptType* _type;
public:
BoundExpression(unsigned int start, unsigned int length, ScriptType* type){
_start = start;
_length = length;
_type = type;
}
virtual ~BoundExpression(){
delete _type;
};
virtual BoundExpressionKind GetKind() = 0;
virtual ScriptType* GetType(){
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;
}
};
class BoundBadExpression : public BoundExpression{
public:
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, new ScriptType(TypeClass::Error)){}
BoundExpressionKind GetKind() final{
return BoundExpressionKind ::Bad;
}
};
class BoundLiteralIntegerExpression : public BoundExpression{
long _value;
public:
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
: BoundExpression(start, length, new NumericScriptType(true, false)){
_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)
: BoundExpression(start, length, new NumericScriptType(true, true)){
_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)
: BoundExpression(start, length, new ScriptType(TypeClass::String)){
_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)
: BoundExpression(start, length, new ScriptType(TypeClass::Bool)){
_value = value;
}
BoundExpressionKind GetKind() final{
return BoundExpressionKind ::LiteralBool;
}
bool GetValue(){
return _value;
}
};
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-05-22 10:29:29 +00:00
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result,
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:
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, ScriptType* result, unsigned int start, unsigned int length)
:BoundExpression(start, length, result){
_operand = operand;
_operation = op;
}
~BoundUnaryExpression() final{
delete _operand;
}
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
};
#endif //PORYGONLANG_BOUNDEXPRESSION_HPP