Implements indexing, currently can only be used with strings
This commit is contained in:
@@ -128,6 +128,9 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
|
||||
case ParsedExpressionKind ::FunctionCall:
|
||||
return this->BindFunctionCall((FunctionCallExpression*)expression);
|
||||
|
||||
case ParsedExpressionKind ::Indexer:
|
||||
return this->BindIndexExpression((IndexExpression*)expression);
|
||||
|
||||
case ParsedExpressionKind ::Bad:
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
|
||||
}
|
||||
@@ -308,4 +311,17 @@ BoundExpression* Binder::BindFunctionCall(FunctionCallExpression* expression){
|
||||
|
||||
return new BoundFunctionCallExpression(functionExpression, boundParameters, functionType.get()->GetReturnType(),
|
||||
expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
}
|
||||
|
||||
BoundExpression *Binder::BindIndexExpression(IndexExpression *expression) {
|
||||
auto indexer = this->BindExpression(expression->GetIndexer());
|
||||
auto index = this->BindExpression(expression->GetIndex());
|
||||
|
||||
if (!indexer->GetType()->CanBeIndexedWith(index->GetType().get())){
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantIndex, index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
auto resultType = shared_ptr<ScriptType>(indexer->GetType()->GetIndexedType(index->GetType().get()));
|
||||
return new BoundIndexExpression(indexer, index, resultType, expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user