#include #ifndef PORYGONLANG_BOUNDEXPRESSION_HPP #define PORYGONLANG_BOUNDEXPRESSION_HPP #include #include "../../ScriptType.hpp" #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; } 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; } }; class BoundBinaryExpression : public BoundExpression { BoundExpression* _left; BoundExpression* _right; BoundBinaryOperation _operation; public: BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result, unsigned int start, unsigned int length) : BoundExpression(start, length, result){ _left = left; _right = right; _operation = op; } ~BoundBinaryExpression() final{ delete _left; delete _right; } BoundExpressionKind GetKind() final{ return BoundExpressionKind ::Binary; } BoundExpression* GetLeft(){ return _left; } BoundExpression* GetRight(){ return _right; } BoundBinaryOperation GetOperation(){ return _operation; } }; 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; } BoundExpressionKind GetKind() final{ return BoundExpressionKind ::Unary; } BoundExpression* GetOperand(){ return _operand; } BoundUnaryOperation GetOperation(){ return _operation; } }; #endif //PORYGONLANG_BOUNDEXPRESSION_HPP