Implements indexing, currently can only be used with strings

This commit is contained in:
2019-06-06 17:35:51 +02:00
parent b275e1fbd6
commit cb5d9e2f62
15 changed files with 140 additions and 9 deletions

View File

@@ -89,6 +89,7 @@ shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerExpression(BoundExpressio
case BoundExpressionKind ::Binary: return this -> EvaluateIntegerBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return dynamic_pointer_cast<NumericEvalValue>(this->GetVariable((BoundVariableExpression*)expression));
case BoundExpressionKind ::FunctionCall: return dynamic_pointer_cast<NumericEvalValue>(this->EvaluateFunctionCallExpression(expression));
case BoundExpressionKind ::Index: return dynamic_pointer_cast<NumericEvalValue>(this->EvaluateIndexExpression(expression));
case BoundExpressionKind ::LiteralString:
case BoundExpressionKind ::LiteralBool:
@@ -104,6 +105,7 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBoolExpression(BoundExpression *
case BoundExpressionKind::Binary: return this -> EvaluateBooleanBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return dynamic_pointer_cast<BooleanEvalValue>(this->GetVariable((BoundVariableExpression*)expression));
case BoundExpressionKind ::FunctionCall: return dynamic_pointer_cast<BooleanEvalValue>(this->EvaluateFunctionCallExpression(expression));
case BoundExpressionKind ::Index: return dynamic_pointer_cast<BooleanEvalValue>(this->EvaluateIndexExpression(expression));
case BoundExpressionKind::Bad:
case BoundExpressionKind::LiteralInteger:
@@ -122,6 +124,7 @@ shared_ptr<StringEvalValue> Evaluator::EvaluateStringExpression(BoundExpression
return this -> EvaluateStringBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return dynamic_pointer_cast<StringEvalValue>(this->GetVariable((BoundVariableExpression*)expression));
case BoundExpressionKind ::FunctionCall: return dynamic_pointer_cast<StringEvalValue>(this->EvaluateFunctionCallExpression(expression));
case BoundExpressionKind ::Index: return dynamic_pointer_cast<StringEvalValue>(this->EvaluateIndexExpression(expression));
case BoundExpressionKind::Bad:
case BoundExpressionKind::LiteralInteger:
@@ -190,4 +193,11 @@ EvalValue* Evaluator::EvaluateFunction(ScriptFunctionEvalValue *function, vector
}
this->EvaluateBlockStatement(function->GetInnerBlock().get());
return nullptr;
}
shared_ptr<EvalValue> Evaluator::EvaluateIndexExpression(BoundExpression *expression) {
auto indexExpression = (BoundIndexExpression*)expression;
auto index = this -> EvaluateExpression(indexExpression->GetIndexExpression());
auto indexable = this -> EvaluateExpression(indexExpression->GetIndexableExpression());
return shared_ptr<EvalValue>(indexable -> IndexValue(index.get()));
}