PorygonLang/src/Evaluator/EvalValues/EvalValue.hpp

118 lines
3.2 KiB
C++
Raw Normal View History

#ifndef PORYGONLANG_EVALVALUE_HPP
#define PORYGONLANG_EVALVALUE_HPP
#include <string>
#include <sstream>
#include <memory>
2019-06-26 14:19:34 +00:00
#include "../../ScriptType.hpp"
#include "../EvaluationException.hpp"
namespace Porygon::Evaluation{
class EvalValue;
class Iterator;
}
#include "../Iterator/Iterator.hpp"
namespace Porygon::Evaluation {
class EvalValue {
public:
EvalValue() = default;
virtual ~EvalValue() = default;
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual TypeClass GetTypeClass() const = 0;
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual bool operator==(const EvalValue *b) const = 0;
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual bool operator!=(const EvalValue *b) const {
return !(this->operator==(b));
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual shared_ptr<const EvalValue> Clone() const = 0;
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual long EvaluateInteger() const {
throw EvaluationException("Can't evaluate this EvalValue as integer.");
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual double EvaluateFloat() const {
throw EvaluationException("Can't evaluate this EvalValue as float.");
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual bool EvaluateBool() const {
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual std::u16string EvaluateString() const {
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual std::size_t GetHashCode() const = 0;
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual shared_ptr<const EvalValue> IndexValue(const EvalValue *val) const {
throw EvaluationException("Can't index this EvalValue");
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
virtual shared_ptr<const EvalValue> IndexValue(uint32_t hash) const {
throw EvaluationException("Can't index this EvalValue");
}
2019-07-25 15:23:54 +00:00
virtual void SetIndexValue(const EvalValue *key, const shared_ptr<const EvalValue> &value) const {
throw EvaluationException("Can't index this EvalValue");
}
2019-06-26 14:19:34 +00:00
2019-07-25 15:23:54 +00:00
[[nodiscard]]
2019-06-26 14:19:34 +00:00
virtual Iterator * GetKeyIterator() const{
throw EvaluationException("Can't iterate over this EvalValue");
}
};
2019-06-09 18:15:09 +00:00
class BooleanEvalValue : public EvalValue {
const bool _value;
public:
explicit BooleanEvalValue(bool val)
: _value(val) {
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
inline shared_ptr<const EvalValue> Clone() const final {
return make_shared<BooleanEvalValue>(_value);
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
inline TypeClass GetTypeClass() const final {
return TypeClass::Bool;
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
inline bool EvaluateBool() const final {
return _value;
}
2019-07-25 15:23:54 +00:00
[[nodiscard]]
bool operator==(const EvalValue *b) const final {
if (b->GetTypeClass() != TypeClass::Bool)
return false;
return this->EvaluateBool() == b->EvaluateBool();
};
2019-07-25 15:23:54 +00:00
[[nodiscard]]
inline std::size_t GetHashCode() const final {
return _value;
}
};
}
#endif //PORYGONLANG_EVALVALUE_HPP