#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP #define PORYGONLANG_BOUNDEXPRESSION_HPP #include #include #include #include "../../ScriptType.hpp" #include "../BoundOperators.hpp" #include "../BoundVariables/BoundVariableKey.hpp" using namespace std; enum class BoundExpressionKind{ Bad, LiteralInteger, LiteralFloat, LiteralString, LiteralBool, Variable, Unary, Binary, FunctionCall, Index, NumericalTable, Table, }; class BoundExpression{ unsigned int _start; unsigned int _length; std::shared_ptr _type; public: BoundExpression(unsigned int start, unsigned int length, std::shared_ptr type){ _start = start; _length = length; _type = std::move(type); } virtual ~BoundExpression() = default; virtual BoundExpressionKind GetKind() = 0; virtual std::shared_ptr 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, make_shared(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, make_shared(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, make_shared(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, make_shared(true, HashedString::ConstHash(value.c_str()))){ _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, make_shared(TypeClass::Bool)){ _value = value; } BoundExpressionKind GetKind() final{ return BoundExpressionKind ::LiteralBool; } bool GetValue(){ return _value; } }; class BoundVariableExpression : public BoundExpression{ BoundVariableKey* _key; public: BoundVariableExpression(BoundVariableKey* key, shared_ptr type, unsigned int start, unsigned int length) : BoundExpression(start, length, std::move(type)){ _key = key; } ~BoundVariableExpression() override = default; BoundExpressionKind GetKind() final{ return BoundExpressionKind ::Variable; } BoundVariableKey* GetKey(){ return _key; } }; class BoundBinaryExpression : public BoundExpression { BoundExpression* _left; BoundExpression* _right; BoundBinaryOperation _operation; public: BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr 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, shared_ptr 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; } }; class BoundFunctionCallExpression : public BoundExpression { BoundExpression* _functionExpression; vector _parameters; public: BoundFunctionCallExpression(BoundExpression *functionExpression, vector parameters, shared_ptr 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 GetParameters(){ return _parameters; } }; class BoundIndexExpression : public BoundExpression { BoundExpression* _indexableExpression; BoundExpression* _indexExpression; public: BoundIndexExpression(BoundExpression* indexableExpression, BoundExpression* indexExpression, shared_ptr result, unsigned int start, unsigned int length) : BoundExpression(start, length, std::move(result)), _indexableExpression(indexableExpression), _indexExpression(indexExpression) {} ~BoundIndexExpression() final{ delete _indexableExpression; delete _indexExpression; } BoundExpressionKind GetKind() final{ return BoundExpressionKind ::Index; } BoundExpression* GetIndexableExpression(){ return _indexableExpression; } BoundExpression* GetIndexExpression(){ return _indexExpression; } }; class BoundNumericalTableExpression : public BoundExpression{ vector _expressions; public: BoundNumericalTableExpression(vector expressions, shared_ptr type, unsigned int start, unsigned int length) : BoundExpression(start, length, std::move(type)){ _expressions = std::move(expressions); } ~BoundNumericalTableExpression() final{ for (auto e: _expressions){ delete e; } } BoundExpressionKind GetKind() final{ return BoundExpressionKind ::NumericalTable; } vector GetExpressions(){ return _expressions; } }; #endif //PORYGONLANG_BOUNDEXPRESSION_HPP