PorygonLang/src/Evaluator/EvalValues/EvalValue.hpp

85 lines
2.3 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;
2019-06-17 15:43:54 +00:00
virtual const TypeClass GetTypeClass() const = 0;
2019-06-17 15:43:54 +00:00
virtual const bool operator ==(EvalValue* b) const = 0;
2019-06-17 15:43:54 +00:00
virtual const bool operator !=(EvalValue*b) const{
return ! (this->operator==(b));
}
2019-06-17 15:43:54 +00:00
virtual const shared_ptr<EvalValue> Clone() const = 0;
2019-06-17 15:43:54 +00:00
virtual const long EvaluateInteger() const{
throw EvaluationException("Can't evaluate this EvalValue as integer.");
}
2019-06-17 15:43:54 +00:00
virtual const double EvaluateFloat() const{
throw EvaluationException("Can't evaluate this EvalValue as float.");
}
2019-06-17 15:43:54 +00:00
virtual const bool EvaluateBool() const{
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
virtual const std::u16string* EvaluateString() const {
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
2019-06-17 15:43:54 +00:00
virtual const std::size_t GetHashCode() const = 0;
2019-06-09 18:15:09 +00:00
2019-06-17 15:43:54 +00:00
virtual const shared_ptr<EvalValue> IndexValue(EvalValue* val) const{
throw EvaluationException("Can't index this EvalValue");
}
2019-06-14 15:12:27 +00:00
2019-06-17 15:43:54 +00:00
virtual const shared_ptr<EvalValue> IndexValue(uint32_t hash) const{
throw EvaluationException("Can't index this EvalValue");
}
2019-06-17 15:43:54 +00:00
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue>& value) const{
2019-06-14 15:12:27 +00:00
throw EvaluationException("Can't index this EvalValue");
}
};
class BooleanEvalValue : public EvalValue{
2019-06-13 14:26:10 +00:00
const bool _value;
public:
2019-06-13 14:26:10 +00:00
explicit BooleanEvalValue(bool val)
: _value(val)
{
}
2019-06-17 15:43:54 +00:00
const shared_ptr<EvalValue> Clone() const final{
return make_shared<BooleanEvalValue>(_value);
}
2019-06-17 15:43:54 +00:00
const TypeClass GetTypeClass() const final{
2019-06-13 14:26:10 +00:00
return TypeClass ::Bool;
}
2019-06-17 15:43:54 +00:00
const bool EvaluateBool() const final{
return _value;
}
2019-06-17 15:43:54 +00:00
const bool operator ==(EvalValue* b) const final{
2019-06-13 14:26:10 +00:00
if (b->GetTypeClass() != TypeClass::Bool)
return false;
return this->EvaluateBool() == b->EvaluateBool();
};
2019-06-09 18:15:09 +00:00
2019-06-17 15:43:54 +00:00
const std::size_t GetHashCode() const final{
2019-06-09 18:15:09 +00:00
return _value;
}
};
#endif //PORYGONLANG_EVALVALUE_HPP