Even better exception handling when we can't index an evalvalue

This commit is contained in:
Deukhoofd 2019-09-07 13:21:35 +02:00
parent 2e1bdcf3a4
commit d8c67f2dde
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 9 additions and 9 deletions

View File

@ -67,9 +67,9 @@ namespace Porygon::Evaluation {
} }
[[nodiscard]] [[nodiscard]]
virtual const EvalValue* IndexValue(uint32_t hash) const { virtual const EvalValue* IndexValue(const Utilities::HashedString* hash) const {
std::stringstream err; std::stringstream err;
err << "Can't index this EvalValue: " << ToString() << " with key hash: " << hash; err << "Can't index this EvalValue: " << ToString() << " with key hash: " << hash->GetDebugString();
throw EvaluationException(err.str()); throw EvaluationException(err.str());
} }

View File

@ -50,8 +50,8 @@ namespace Porygon::Evaluation {
} }
[[nodiscard]] [[nodiscard]]
inline EvalValue* IndexValue(uint32_t hash) const final { inline EvalValue* IndexValue(const Utilities::HashedString* hash) const final {
return this->_table->at(hash - 1)-> Clone(); return this->_table->at(hash->GetHash() - 1)-> Clone();
} }
inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final { inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final {

View File

@ -54,8 +54,8 @@ namespace Porygon::Evaluation {
} }
[[nodiscard]] [[nodiscard]]
inline EvalValue* IndexValue(uint32_t hash) const final { inline EvalValue* IndexValue(const Utilities::HashedString* hash) const final {
return this->_table->at(Utilities::HashedString::CreateLookup(hash))->Clone(); return this->_table->at(*hash)->Clone();
} }
[[nodiscard]] [[nodiscard]]

View File

@ -372,7 +372,7 @@ namespace Porygon::Evaluation {
EvalValuePointer Evaluator::EvaluatePeriodIndexExpression(const BoundExpression *expression) { EvalValuePointer Evaluator::EvaluatePeriodIndexExpression(const BoundExpression *expression) {
auto indexExpression = (BoundPeriodIndexExpression *) expression; auto indexExpression = (BoundPeriodIndexExpression *) expression;
auto index = indexExpression->GetIndex()->GetHash(); auto index = indexExpression->GetIndex();
auto indexable = this->EvaluateExpression(indexExpression->GetIndexableExpression()); auto indexable = this->EvaluateExpression(indexExpression->GetIndexableExpression());
return indexable->IndexValue(index); return indexable->IndexValue(index);
} }

View File

@ -58,8 +58,8 @@ namespace Porygon::UserData {
} }
[[nodiscard]] [[nodiscard]]
inline const EvalValue* IndexValue(uint32_t hash) const final { inline const EvalValue* IndexValue(const Utilities::HashedString* hash) const final {
auto field = _userData->Get()->GetField(hash); auto field = _userData->Get()->GetField(hash->GetHash());
return field->Get(_obj); return field->Get(_obj);
} }