134 lines
2.9 KiB
C++
134 lines
2.9 KiB
C++
|
#include <utility>
|
||
|
|
||
|
|
||
|
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
|
||
|
#define PORYGONLANG_BOUNDEXPRESSION_HPP
|
||
|
|
||
|
#include <string>
|
||
|
#include "../../ScriptType.hpp"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
enum class BoundExpressionKind{
|
||
|
Bad,
|
||
|
|
||
|
LiteralInteger,
|
||
|
LiteralFloat,
|
||
|
LiteralString,
|
||
|
LiteralBool,
|
||
|
|
||
|
Unary,
|
||
|
Binary,
|
||
|
Parenthesized,
|
||
|
};
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#endif //PORYGONLANG_BOUNDEXPRESSION_HPP
|