This commit is contained in:
@@ -48,6 +48,8 @@ namespace Porygon::Binder {
|
||||
return this->BindNumericalForStatement(statement);
|
||||
case ParsedStatementKind::GenericFor:
|
||||
return this -> BindGenericForStatement(statement);
|
||||
case ParsedStatementKind::While:
|
||||
return this -> BindWhileStatement(statement);
|
||||
case ParsedStatementKind::Break:
|
||||
//TODO: Validate we're in a loop
|
||||
return new BoundBreakStatement();
|
||||
@@ -298,6 +300,18 @@ namespace Porygon::Binder {
|
||||
return new BoundGenericForStatement(keyVariable, valueVariable, boundIterator, boundBlock);
|
||||
}
|
||||
|
||||
BoundStatement *Binder::BindWhileStatement(const ParsedStatement *statement) {
|
||||
auto whileStatement = (ParsedWhileStatement*)statement;
|
||||
auto boundCondition = this -> BindExpression(whileStatement->GetCondition());
|
||||
if (boundCondition->GetType()->GetClass() != TypeClass::Bool){
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ConditionNotABool, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
auto boundBlock = this -> BindBlockStatement(whileStatement->GetBlock());
|
||||
return new BoundWhileStatement(boundCondition, boundBlock);
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Expressions //
|
||||
/////////////////
|
||||
@@ -674,4 +688,5 @@ namespace Porygon::Binder {
|
||||
return new BoundTableExpression((BoundBlockStatement *) block, tableType, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,30 +30,24 @@ namespace Porygon::Binder {
|
||||
BoundStatement *BindConditionalStatement(const ParsedStatement *statement);
|
||||
BoundStatement *BindNumericalForStatement(const ParsedStatement *statement);
|
||||
BoundStatement *BindGenericForStatement(const ParsedStatement *statement);
|
||||
BoundStatement *BindWhileStatement(const ParsedStatement *statement);
|
||||
|
||||
// Expressions
|
||||
|
||||
BoundExpression *BindExpression(const ParsedExpression *expression);
|
||||
|
||||
BoundExpression *BindVariableExpression(const VariableExpression *expression);
|
||||
|
||||
BoundExpression *BindBinaryOperator(const BinaryExpression *expression);
|
||||
|
||||
BoundExpression *BindUnaryOperator(const UnaryExpression *expression);
|
||||
|
||||
BoundExpression *BindFunctionCall(const FunctionCallExpression *expression);
|
||||
|
||||
BoundExpression *BindIndexExpression(const IndexExpression *expression, bool setter);
|
||||
|
||||
BoundExpression *BindNumericalTableExpression(const ParsedNumericalTableExpression *expression);
|
||||
|
||||
BoundExpression *BindTableExpression(const ParsedTableExpression *expression);
|
||||
BoundExpression *BindPeriodIndexExpression(const PeriodIndexExpression *expression, bool setter);
|
||||
|
||||
public:
|
||||
static BoundScriptStatement *
|
||||
Bind(Porygon::Script *script, const ParsedScriptStatement *s, BoundScope *scriptScope);
|
||||
|
||||
BoundExpression *BindPeriodIndexExpression(const PeriodIndexExpression *expression, bool setter);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ using namespace std;
|
||||
namespace Porygon::Binder {
|
||||
enum class BoundStatementKind {
|
||||
Bad,
|
||||
Break,
|
||||
Script,
|
||||
Block,
|
||||
Expression,
|
||||
@@ -22,7 +23,7 @@ namespace Porygon::Binder {
|
||||
Conditional,
|
||||
NumericalFor,
|
||||
GenericFor,
|
||||
Break,
|
||||
While,
|
||||
};
|
||||
|
||||
class BoundStatement {
|
||||
@@ -298,6 +299,31 @@ namespace Porygon::Binder {
|
||||
}
|
||||
};
|
||||
|
||||
class BoundWhileStatement : public BoundStatement {
|
||||
const BoundExpression* _condition;
|
||||
const BoundStatement *_block;
|
||||
public:
|
||||
explicit BoundWhileStatement(const BoundExpression *condition, const BoundStatement *block)
|
||||
: _condition(condition), _block(block) {
|
||||
}
|
||||
|
||||
~BoundWhileStatement() final {
|
||||
delete _condition;
|
||||
delete _block;
|
||||
}
|
||||
|
||||
const BoundStatementKind GetKind() const final {
|
||||
return BoundStatementKind::While;
|
||||
}
|
||||
|
||||
const BoundExpression* GetCondition() const{
|
||||
return _condition;
|
||||
}
|
||||
|
||||
const BoundStatement* GetBlock() const{
|
||||
return _block;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user