Solidity ForStatement Compiler part

- Work in progress
This commit is contained in:
Lefteris Karapetsas 2014-12-16 16:52:47 +01:00
parent adbea47596
commit 5c05b8d725
2 changed files with 34 additions and 2 deletions

5
AST.h
View File

@ -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;

View File

@ -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;
} }