Better error handling when unable to index an eval value
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-09-07 13:04:42 +02:00
parent 5c63b15ab7
commit 2e1bdcf3a4
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 16 additions and 4 deletions

View File

@ -61,16 +61,22 @@ namespace Porygon::Evaluation {
[[nodiscard]]
virtual const EvalValue* IndexValue(const EvalValue *val) const {
throw EvaluationException("Can't index this EvalValue");
std::stringstream err;
err << "Can't index this EvalValue: " << ToString() << " with key: " << val->ToString();
throw EvaluationException(err.str());
}
[[nodiscard]]
virtual const EvalValue* IndexValue(uint32_t hash) const {
throw EvaluationException("Can't index this EvalValue");
std::stringstream err;
err << "Can't index this EvalValue: " << ToString() << " with key hash: " << hash;
throw EvaluationException(err.str());
}
virtual void SetIndexValue(const EvalValue *key, const EvalValue* value) const {
throw EvaluationException("Can't index this EvalValue");
std::stringstream err;
err << "Can't index this EvalValue: " << ToString() << " with key: " << value->ToString();
throw EvaluationException(err.str());
}
[[nodiscard]]
@ -92,6 +98,12 @@ namespace Porygon::Evaluation {
virtual EvalValue* Cast(shared_ptr<const ScriptType> castType) const{
throw new EvaluationException("Casting to invalid type.");
}
virtual std::string ToString() const{
std::stringstream s;
s << "Type: " << ScriptType::ToString(this->GetTypeClass());
return s.str();
}
};
class BooleanEvalValue : public EvalValue {

View File

@ -47,7 +47,7 @@ TEST_CASE( "Assignment Statement To String", "[BoundTreeString]" ) {
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
auto s = new BoundAssignmentStatement(keyObj, new BoundLiteralIntegerExpression(5, 0,0));
s->GetTreeString(stream, 1);
REQUIRE(stream.str() == "\tAssignment -> key\n\t\tLiteralInteger: 5 (number)");
REQUIRE(stream.str() == "\tAssignment -> global key\n\t\tLiteralInteger: 5 (number)");
delete s;
}