2019-05-21 16:09:08 +00:00
|
|
|
|
|
|
|
#include "Binder.hpp"
|
|
|
|
|
|
|
|
BoundScriptStatement *Binder::Bind(ParsedScriptStatement *s) {
|
2019-05-21 18:59:26 +00:00
|
|
|
auto binder = Binder();
|
|
|
|
auto statements = s->GetStatements();
|
|
|
|
vector<BoundStatement*> boundStatements (statements.size());
|
|
|
|
for (int i = 0; i < statements.size(); i++){
|
|
|
|
boundStatements[i] = binder.BindStatement(statements[i]);
|
|
|
|
}
|
|
|
|
return new BoundScriptStatement(boundStatements);
|
2019-05-21 16:09:08 +00:00
|
|
|
}
|
2019-05-21 18:59:26 +00:00
|
|
|
|
|
|
|
BoundStatement* Binder::BindStatement(ParsedStatement* statement){
|
|
|
|
switch (statement -> GetKind()) {
|
|
|
|
case ParsedStatementKind ::Script: throw; // This shouldn't happen.
|
|
|
|
case ParsedStatementKind ::Block: return this -> BindBlockStatement(statement);
|
|
|
|
case ParsedStatementKind ::Expression: return this -> BindExpressionStatement(statement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundStatement *Binder::BindBlockStatement(ParsedStatement *statement) {
|
|
|
|
auto statements = ((ParsedBlockStatement*)statement)->GetStatements();
|
|
|
|
vector<BoundStatement*> boundStatements (statements.size());
|
|
|
|
for (int i = 0; i < statements.size(); i++){
|
|
|
|
boundStatements[i] = this -> BindStatement(statements[i]);
|
|
|
|
}
|
|
|
|
return new BoundBlockStatement(boundStatements);
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundStatement *Binder::BindExpressionStatement(ParsedStatement *statement) {
|
|
|
|
auto exp = ((ParsedExpressionStatement*)statement)->GetExpression();
|
|
|
|
return new BoundExpressionStatement(this -> BindExpression(exp));
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundExpression* Binder::BindExpression(ParsedExpression* expression){
|
|
|
|
switch (expression -> GetKind()){
|
|
|
|
case ParsedExpressionKind ::LiteralInteger:
|
|
|
|
return new BoundLiteralIntegerExpression(((LiteralIntegerExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
|
|
|
|
case ParsedExpressionKind ::LiteralFloat:
|
|
|
|
return new BoundLiteralFloatExpression(((LiteralFloatExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
|
|
|
|
case ParsedExpressionKind ::LiteralBool:
|
|
|
|
return new BoundLiteralBoolExpression(((LiteralBoolExpression*)expression)->GetValue(), expression->GetStartPosition(), expression->GetLength());
|
|
|
|
|
2019-05-21 19:00:56 +00:00
|
|
|
case ParsedExpressionKind ::Parenthesized:
|
|
|
|
return BindExpression(((ParenthesizedExpression*)expression)->GetInnerExpression());
|
|
|
|
|
2019-05-21 18:59:26 +00:00
|
|
|
case ParsedExpressionKind ::Bad:
|
|
|
|
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|