2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_EVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_EVALVALUE_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2019-05-25 14:15:20 +00:00
|
|
|
#include <sstream>
|
2019-06-01 17:20:31 +00:00
|
|
|
#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"
|
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon::Evaluation {
|
|
|
|
class EvalValue {
|
|
|
|
public:
|
|
|
|
EvalValue() = default;
|
|
|
|
|
|
|
|
virtual ~EvalValue() = default;
|
|
|
|
|
|
|
|
virtual const TypeClass GetTypeClass() const = 0;
|
|
|
|
|
|
|
|
virtual const bool operator==(EvalValue *b) const = 0;
|
|
|
|
|
|
|
|
virtual const bool operator!=(EvalValue *b) const {
|
|
|
|
return !(this->operator==(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const shared_ptr<EvalValue> Clone() const = 0;
|
|
|
|
|
|
|
|
virtual const long EvaluateInteger() const {
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as integer.");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const double EvaluateFloat() const {
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as float.");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const bool EvaluateBool() const {
|
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
|
|
|
}
|
|
|
|
|
2019-06-23 13:58:14 +00:00
|
|
|
virtual const std::u16string EvaluateString() const {
|
2019-06-17 16:35:12 +00:00
|
|
|
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const std::size_t GetHashCode() const = 0;
|
|
|
|
|
|
|
|
virtual const shared_ptr<EvalValue> IndexValue(EvalValue *val) const {
|
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const shared_ptr<EvalValue> IndexValue(uint32_t hash) const {
|
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const {
|
|
|
|
throw EvaluationException("Can't index this EvalValue");
|
|
|
|
}
|
2019-06-26 14:19:34 +00:00
|
|
|
|
|
|
|
virtual Iterator * GetKeyIterator() const{
|
|
|
|
throw EvaluationException("Can't iterate over this EvalValue");
|
|
|
|
}
|
2019-05-25 11:57:43 +00:00
|
|
|
};
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
class BooleanEvalValue : public EvalValue {
|
|
|
|
const bool _value;
|
|
|
|
public:
|
|
|
|
explicit BooleanEvalValue(bool val)
|
|
|
|
: _value(val) {
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const shared_ptr<EvalValue> Clone() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return make_shared<BooleanEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const TypeClass GetTypeClass() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return TypeClass::Bool;
|
|
|
|
}
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const bool EvaluateBool() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool operator==(EvalValue *b) const final {
|
|
|
|
if (b->GetTypeClass() != TypeClass::Bool)
|
|
|
|
return false;
|
|
|
|
return this->EvaluateBool() == b->EvaluateBool();
|
|
|
|
};
|
|
|
|
|
2019-07-04 17:08:13 +00:00
|
|
|
inline const std::size_t GetHashCode() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-05-25 11:30:20 +00:00
|
|
|
|
2019-05-24 17:14:30 +00:00
|
|
|
#endif //PORYGONLANG_EVALVALUE_HPP
|