[Sol -> Yul] Implement if statements

This commit is contained in:
Daniel Kirchner
2019-05-09 14:52:20 +02:00
parent 0852ccc318
commit b83f6d8d46
3 changed files with 102 additions and 0 deletions
@@ -152,6 +152,25 @@ bool IRGeneratorForStatements::visit(TupleExpression const& _tuple)
return false;
}
bool IRGeneratorForStatements::visit(IfStatement const& _ifStatement)
{
_ifStatement.condition().accept(*this);
string condition = expressionAsType(_ifStatement.condition(), *TypeProvider::boolean());
if (_ifStatement.falseStatement())
{
m_code << "switch " << condition << "\n" "case 0 {\n";
_ifStatement.falseStatement()->accept(*this);
m_code << "}\n" "default {\n";
}
else
m_code << "if " << condition << " {\n";
_ifStatement.trueStatement().accept(*this);
m_code << "}\n";
return false;
}
bool IRGeneratorForStatements::visit(ForStatement const& _forStatement)
{
generateLoop(
@@ -48,6 +48,7 @@ public:
void endVisit(VariableDeclarationStatement const& _variableDeclaration) override;
bool visit(Assignment const& _assignment) override;
bool visit(TupleExpression const& _tuple) override;
bool visit(IfStatement const& _ifStatement) override;
bool visit(ForStatement const& _forStatement) override;
bool visit(WhileStatement const& _whileStatement) override;
bool visit(Continue const& _continueStatement) override;