PorygonLang/src/Evaluator/EvalValues/EvalValue.hpp

72 lines
1.8 KiB
C++
Raw Normal View History

#ifndef PORYGONLANG_EVALVALUE_HPP
#define PORYGONLANG_EVALVALUE_HPP
#include "../../ScriptType.hpp"
#include "../EvaluationException.hpp"
#include <string>
#include <sstream>
#include <memory>
class EvalValue{
public:
EvalValue() = default;
virtual ~EvalValue() = default;
virtual std::shared_ptr<ScriptType> GetType() = 0;
virtual bool operator ==(EvalValue* b) = 0;
virtual bool operator !=(EvalValue*b){
return ! (this->operator==(b));
}
virtual shared_ptr<EvalValue> Clone() = 0;
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.");
}
virtual std::string* EvaluateString(){
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
virtual EvalValue* IndexValue(EvalValue* val){
throw EvaluationException("Can't index this EvalValue");
}
};
class BooleanEvalValue : public EvalValue{
bool _value;
std::shared_ptr<ScriptType> _type;
public:
explicit BooleanEvalValue(bool val){
_value = val;
_type = std::make_shared<ScriptType>(TypeClass::Bool);
}
shared_ptr<EvalValue> Clone() final{
return make_shared<BooleanEvalValue>(_value);
}
std::shared_ptr<ScriptType> GetType() final{
return _type;
};
bool EvaluateBool() final{
return _value;
}
bool operator ==(EvalValue* b) final{
if (b->GetType()->GetClass() != TypeClass::Bool)
return false;
return this->EvaluateBool() == b->EvaluateBool();
};
};
#endif //PORYGONLANG_EVALVALUE_HPP