mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement for loops.
This commit is contained in:
parent
c1ca16cd33
commit
597d37b731
@ -22,6 +22,7 @@
|
||||
|
||||
#include <libsolidity/codegen/ir/IRGenerationContext.h>
|
||||
#include <libsolidity/codegen/YulUtilFunctions.h>
|
||||
#include <libsolidity/ast/TypeProvider.h>
|
||||
|
||||
#include <libyul/AsmPrinter.h>
|
||||
#include <libyul/AsmData.h>
|
||||
@ -126,6 +127,42 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(ForStatement const& _for)
|
||||
{
|
||||
m_code << "for {\n";
|
||||
if (_for.initializationExpression())
|
||||
_for.initializationExpression()->accept(*this);
|
||||
m_code << "} return_flag {\n";
|
||||
if (_for.loopExpression())
|
||||
_for.loopExpression()->accept(*this);
|
||||
m_code << "}\n";
|
||||
if (_for.condition())
|
||||
{
|
||||
_for.condition()->accept(*this);
|
||||
m_code <<
|
||||
"if iszero(" <<
|
||||
expressionAsType(*_for.condition(), *TypeProvider::boolean()) <<
|
||||
") { break }\n";
|
||||
}
|
||||
_for.body().accept(*this);
|
||||
m_code << "}\n";
|
||||
// Bubble up the return condition.
|
||||
m_code << "if iszero(return_flag) { break }\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Continue const&)
|
||||
{
|
||||
m_code << "continue\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Break const&)
|
||||
{
|
||||
m_code << "break\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Return const& _return)
|
||||
{
|
||||
if (Expression const* value = _return.expression())
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
|
||||
bool visit(VariableDeclarationStatement const& _variableDeclaration) override;
|
||||
bool visit(Assignment const& _assignment) override;
|
||||
bool visit(ForStatement const& _forStatement) override;
|
||||
bool visit(Continue const& _continueStatement) override;
|
||||
bool visit(Break const& _breakStatement) override;
|
||||
bool visit(Return const& _return) override;
|
||||
void endVisit(BinaryOperation const& _binOp) override;
|
||||
bool visit(FunctionCall const& _funCall) override;
|
||||
|
Loading…
Reference in New Issue
Block a user