2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_EVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_EVALVALUE_HPP
|
|
|
|
|
|
|
|
#include "../../ScriptType.hpp"
|
|
|
|
#include "../EvaluationException.hpp"
|
|
|
|
#include <string>
|
2019-05-25 14:15:20 +00:00
|
|
|
#include <sstream>
|
2019-06-01 17:20:31 +00:00
|
|
|
#include <memory>
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
class EvalValue{
|
|
|
|
public:
|
2019-05-30 13:23:48 +00:00
|
|
|
EvalValue() = default;
|
2019-05-24 17:14:30 +00:00
|
|
|
virtual ~EvalValue() = default;
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual std::shared_ptr<ScriptType> GetType() = 0;
|
2019-05-24 17:14:30 +00:00
|
|
|
|
2019-05-25 11:57:43 +00:00
|
|
|
virtual bool operator ==(EvalValue* b) = 0;
|
|
|
|
|
|
|
|
virtual bool operator !=(EvalValue*b){
|
|
|
|
return ! (this->operator==(b));
|
|
|
|
}
|
|
|
|
|
2019-06-01 19:38:39 +00:00
|
|
|
virtual shared_ptr<EvalValue> Clone() = 0;
|
2019-05-30 13:23:48 +00:00
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
virtual long EvaluateInteger(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as integer.");
|
|
|
|
}
|
|
|
|
virtual double EvaluateFloat(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as float.");
|
|
|
|
}
|
|
|
|
virtual bool EvaluateBool(){
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
|
|
|
}
|
2019-06-05 15:46:46 +00:00
|
|
|
virtual std::string* EvaluateString(){
|
2019-05-24 17:14:30 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
|
|
|
}
|
2019-06-06 15:35:51 +00:00
|
|
|
|
2019-06-09 18:15:09 +00:00
|
|
|
virtual std::size_t GetHashCode() = 0;
|
|
|
|
|
|
|
|
virtual shared_ptr<EvalValue> IndexValue(EvalValue* val){
|
2019-06-06 15:35:51 +00:00
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
2019-05-25 11:30:20 +00:00
|
|
|
class BooleanEvalValue : public EvalValue{
|
|
|
|
bool _value;
|
2019-06-01 17:20:31 +00:00
|
|
|
std::shared_ptr<ScriptType> _type;
|
2019-05-25 11:30:20 +00:00
|
|
|
public:
|
|
|
|
explicit BooleanEvalValue(bool val){
|
|
|
|
_value = val;
|
2019-06-01 17:20:31 +00:00
|
|
|
_type = std::make_shared<ScriptType>(TypeClass::Bool);
|
2019-05-25 11:30:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 19:38:39 +00:00
|
|
|
shared_ptr<EvalValue> Clone() final{
|
|
|
|
return make_shared<BooleanEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
std::shared_ptr<ScriptType> GetType() final{
|
2019-05-25 11:30:20 +00:00
|
|
|
return _type;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool EvaluateBool() final{
|
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 11:57:43 +00:00
|
|
|
|
|
|
|
bool operator ==(EvalValue* b) final{
|
|
|
|
if (b->GetType()->GetClass() != TypeClass::Bool)
|
|
|
|
return false;
|
|
|
|
return this->EvaluateBool() == b->EvaluateBool();
|
|
|
|
};
|
2019-06-09 18:15:09 +00:00
|
|
|
|
|
|
|
std::size_t GetHashCode() final{
|
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 11:30:20 +00:00
|
|
|
};
|
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
#endif //PORYGONLANG_EVALVALUE_HPP
|