Implements variable usage, tweaks and fixes for variable assignment
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user