Rework of memory handling in Evaluation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Porygon::Evaluation{
|
||||
class Iterator;
|
||||
}
|
||||
#include "../Iterator/Iterator.hpp"
|
||||
#include "../../Binder/BoundOperators.hpp"
|
||||
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
@@ -33,7 +34,7 @@ namespace Porygon::Evaluation {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual shared_ptr<const EvalValue> Clone() const = 0;
|
||||
virtual EvalValue* Clone() const = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual long EvaluateInteger() const {
|
||||
@@ -59,16 +60,16 @@ namespace Porygon::Evaluation {
|
||||
virtual std::size_t GetHashCode() const = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual shared_ptr<const EvalValue> IndexValue(const EvalValue *val) const {
|
||||
virtual const EvalValue* IndexValue(const EvalValue *val) const {
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual shared_ptr<const EvalValue> IndexValue(uint32_t hash) const {
|
||||
virtual const EvalValue* IndexValue(uint32_t hash) const {
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
|
||||
virtual void SetIndexValue(const EvalValue *key, const shared_ptr<const EvalValue> &value) const {
|
||||
virtual void SetIndexValue(const EvalValue *key, const EvalValue* value) const {
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
|
||||
@@ -76,6 +77,16 @@ namespace Porygon::Evaluation {
|
||||
virtual Iterator * GetKeyIterator() const{
|
||||
throw EvaluationException("Can't iterate over this EvalValue");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual EvalValue* BinaryOperation(Binder::BoundBinaryOperation operation, const EvalValue* b) const{
|
||||
throw EvaluationException("Binary operations are not implemented for this type.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual EvalValue* UnaryOperation(Binder::BoundUnaryOperation operation) const{
|
||||
throw EvaluationException("Unary operations are not implemented for this type.");
|
||||
}
|
||||
};
|
||||
|
||||
class BooleanEvalValue : public EvalValue {
|
||||
@@ -86,8 +97,8 @@ namespace Porygon::Evaluation {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<const EvalValue> Clone() const final {
|
||||
return make_shared<BooleanEvalValue>(_value);
|
||||
inline EvalValue* Clone() const final {
|
||||
return new BooleanEvalValue(_value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -111,6 +122,25 @@ namespace Porygon::Evaluation {
|
||||
inline std::size_t GetHashCode() const final {
|
||||
return _value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline EvalValue* BinaryOperation(Binder::BoundBinaryOperation operation, const EvalValue* b) const final{
|
||||
auto bVal = b -> EvaluateBool();
|
||||
switch (operation){
|
||||
case Binder::BoundBinaryOperation::LogicalAnd: return new BooleanEvalValue(_value && bVal);
|
||||
case Binder::BoundBinaryOperation::LogicalOr: return new BooleanEvalValue(_value || bVal);
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
EvalValue* UnaryOperation(Binder::BoundUnaryOperation operation) const final{
|
||||
switch (operation){
|
||||
case Binder::BoundUnaryOperation::LogicalNegation: return new BooleanEvalValue(!_value);
|
||||
default: throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user