Better error handling when unable to index an eval value
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5c63b15ab7
commit
2e1bdcf3a4
|
@ -61,16 +61,22 @@ namespace Porygon::Evaluation {
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual const EvalValue* IndexValue(const EvalValue *val) const {
|
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]]
|
[[nodiscard]]
|
||||||
virtual const EvalValue* IndexValue(uint32_t hash) const {
|
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 {
|
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]]
|
[[nodiscard]]
|
||||||
|
@ -92,6 +98,12 @@ namespace Porygon::Evaluation {
|
||||||
virtual EvalValue* Cast(shared_ptr<const ScriptType> castType) const{
|
virtual EvalValue* Cast(shared_ptr<const ScriptType> castType) const{
|
||||||
throw new EvaluationException("Casting to invalid type.");
|
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 {
|
class BooleanEvalValue : public EvalValue {
|
||||||
|
|
|
@ -47,7 +47,7 @@ TEST_CASE( "Assignment Statement To String", "[BoundTreeString]" ) {
|
||||||
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
||||||
auto s = new BoundAssignmentStatement(keyObj, new BoundLiteralIntegerExpression(5, 0,0));
|
auto s = new BoundAssignmentStatement(keyObj, new BoundLiteralIntegerExpression(5, 0,0));
|
||||||
s->GetTreeString(stream, 1);
|
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;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue