Implements basic numerical tables
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Binder.hpp"
|
||||
#include <memory>
|
||||
|
||||
@@ -174,6 +176,8 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
|
||||
|
||||
case ParsedExpressionKind ::Indexer:
|
||||
return this->BindIndexExpression((IndexExpression*)expression);
|
||||
case ParsedExpressionKind::NumericalTable:
|
||||
return this -> BindNumericalTableExpression((ParsedNumericalTableExpression*)expression);
|
||||
|
||||
case ParsedExpressionKind ::Bad:
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
|
||||
@@ -386,7 +390,29 @@ BoundExpression *Binder::BindIndexExpression(IndexExpression *expression) {
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
auto resultType = shared_ptr<ScriptType>(indexer->GetType()->GetIndexedType(index->GetType().get()));
|
||||
auto resultType = indexer->GetType()->GetIndexedType(index->GetType().get());
|
||||
return new BoundIndexExpression(indexer, index, resultType, expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
||||
BoundExpression* Binder::BindNumericalTableExpression(ParsedNumericalTableExpression* expression){
|
||||
auto expressions = expression->GetExpressions();
|
||||
auto boundExpressions = vector<BoundExpression*>(expressions.size());
|
||||
shared_ptr<ScriptType> valueType = nullptr;
|
||||
if (!boundExpressions.empty()){
|
||||
boundExpressions[0] = this -> BindExpression(expressions[0]);
|
||||
valueType = boundExpressions[0] -> GetType();
|
||||
for (int i = 1; i < expressions.size(); i++){
|
||||
boundExpressions[i] = this -> BindExpression(expressions[i]);
|
||||
if (boundExpressions[i] -> GetType().get()->operator!=(valueType.get())){
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidTableValueType, boundExpressions[i]->GetStartPosition(),
|
||||
boundExpressions[i]->GetLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (valueType == nullptr){
|
||||
valueType = std::make_shared<ScriptType>(TypeClass::Nil);
|
||||
}
|
||||
auto keyType = std::make_shared<ScriptType>(TypeClass::Number);
|
||||
auto tableType = std::make_shared<TableScriptType>(keyType, valueType);
|
||||
return new BoundNumericalTableExpression(boundExpressions, tableType, expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
Reference in New Issue
Block a user