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]]
virtual const EvalValue* IndexValue(uint32_t hash) const {
virtual const EvalValue* IndexValue(const Utilities::HashedString* hash) const {
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());
}

View File

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

View File

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

View File

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

View File

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