Implements variable usage, tweaks and fixes for variable assignment

This commit is contained in:
2019-05-30 15:23:48 +02:00
parent 257eb942c7
commit 6fad5a0a7d
17 changed files with 145 additions and 4 deletions

View File

@@ -72,6 +72,8 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
return new BoundLiteralStringExpression(((LiteralStringExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
case ParsedExpressionKind ::LiteralBool:
return new BoundLiteralBoolExpression(((LiteralBoolExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
case ParsedExpressionKind ::Variable:
return this -> BindVariableExpression((VariableExpression*)expression);
case ParsedExpressionKind ::Binary:
return this -> BindBinaryOperator((BinaryExpression*)expression);
@@ -86,6 +88,18 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
}
}
BoundExpression* Binder::BindVariableExpression(VariableExpression* expression){
auto key = expression->GetValue();
auto scope = this->_scope->Exists(key.GetHash());
if (scope == -1){
this -> _scriptData -> Diagnostics->LogError(DiagnosticCode::VariableNotFound, expression->GetStartPosition(), expression->GetLength());
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
}
auto var = this->_scope->GetVariable(scope, key.GetHash());
auto type = var->GetType();
return new BoundVariableExpression(scope, key.GetHash(), type, expression->GetStartPosition(), expression->GetLength());
}
BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
auto boundLeft = this -> BindExpression(expression->GetLeft());
auto boundRight = this -> BindExpression(expression->GetRight());