mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Solidity ForStatement Compiler part
- Work in progress
This commit is contained in:
parent
adbea47596
commit
5c05b8d725
5
AST.h
5
AST.h
@ -529,6 +529,11 @@ public:
|
|||||||
virtual void accept(ASTConstVisitor& _visitor) const override;
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
||||||
virtual void checkTypeRequirements() override;
|
virtual void checkTypeRequirements() override;
|
||||||
|
|
||||||
|
Statement const* getInitializationExpression() const { return m_initExpression.get(); }
|
||||||
|
Expression const* getCondition() const { return m_condExpression.get(); }
|
||||||
|
ExpressionStatement const* getLoopExpression() const { return m_loopExpression.get(); }
|
||||||
|
Statement const& getBody() const { return *m_body; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// For statement's initialization expresion. for(XXX; ; ). Can be empty
|
/// For statement's initialization expresion. for(XXX; ; ). Can be empty
|
||||||
ASTPointer<Statement> m_initExpression;
|
ASTPointer<Statement> m_initExpression;
|
||||||
|
31
Compiler.cpp
31
Compiler.cpp
@ -289,8 +289,35 @@ bool Compiler::visit(WhileStatement const& _whileStatement)
|
|||||||
|
|
||||||
bool Compiler::visit(ForStatement const& _forStatement)
|
bool Compiler::visit(ForStatement const& _forStatement)
|
||||||
{
|
{
|
||||||
// LTODO
|
eth::AssemblyItem loopStart = m_context.newTag();
|
||||||
(void) _forStatement;
|
eth::AssemblyItem loopEnd = m_context.newTag();
|
||||||
|
m_continueTags.push_back(loopStart);
|
||||||
|
m_breakTags.push_back(loopEnd);
|
||||||
|
|
||||||
|
if (_forStatement.getInitializationExpression())
|
||||||
|
_forStatement.getInitializationExpression()->accept(*this);
|
||||||
|
|
||||||
|
m_context << loopStart;
|
||||||
|
|
||||||
|
// if there is no terminating condition in for, default is to always be true
|
||||||
|
if (_forStatement.getCondition())
|
||||||
|
{
|
||||||
|
compileExpression(*_forStatement.getCondition());
|
||||||
|
m_context << eth::Instruction::ISZERO;
|
||||||
|
m_context.appendConditionalJumpTo(loopEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
_forStatement.getBody().accept(*this);
|
||||||
|
|
||||||
|
// for's loop expression if existing
|
||||||
|
if (_forStatement.getLoopExpression())
|
||||||
|
_forStatement.getLoopExpression()->accept(*this);
|
||||||
|
|
||||||
|
m_context.appendJumpTo(loopStart);
|
||||||
|
m_context << loopEnd;
|
||||||
|
|
||||||
|
m_continueTags.pop_back();
|
||||||
|
m_breakTags.pop_back();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user