From 49b11121179040d438dd8795a710f3d9de3de789 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 1 Jun 2017 14:16:12 +0200 Subject: For loops analysis. --- libsolidity/inlineasm/AsmAnalysis.cpp | 26 ++++++++++++++++++++++++-- libsolidity/inlineasm/AsmScopeFiller.cpp | 19 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 68c940e7..548f1a74 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -310,9 +310,31 @@ bool AsmAnalyzer::operator()(Switch const& _switch) return success; } -bool AsmAnalyzer::operator()(assembly::ForLoop const&) +bool AsmAnalyzer::operator()(assembly::ForLoop const& _for) { - solAssert(false, "For loop not supported."); + Scope* originalScope = m_currentScope; + + bool success = true; + if (!(*this)(_for.pre)) + success = false; + // The block was closed already, but we re-open it again and stuff the + // condition, the body and the post part inside. + m_stackHeight += scope(&_for.pre).numberOfVariables(); + m_currentScope = &scope(&_for.pre); + + if (!expectExpression(*_for.condition)) + success = false; + m_stackHeight--; + if (!(*this)(_for.body)) + success = false; + if (!(*this)(_for.post)) + success = false; + + m_stackHeight -= scope(&_for.pre).numberOfVariables(); + m_info.stackHeightInfo[&_for] = m_stackHeight; + m_currentScope = originalScope; + + return success; } bool AsmAnalyzer::operator()(Block const& _block) diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index 1aac902a..3bef9cec 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -111,9 +111,24 @@ bool ScopeFiller::operator()(Switch const& _switch) return success; } -bool ScopeFiller::operator()(ForLoop const&) +bool ScopeFiller::operator()(ForLoop const& _forLoop) { - solAssert(false, "For loop not supported."); + Scope* originalScope = m_currentScope; + + bool success = true; + if (!(*this)(_forLoop.pre)) + success = false; + m_currentScope = &scope(&_forLoop.pre); + if (!boost::apply_visitor(*this, *_forLoop.condition)) + success = false; + if (!(*this)(_forLoop.body)) + success = false; + if (!(*this)(_forLoop.post)) + success = false; + + m_currentScope = originalScope; + + return success; } bool ScopeFiller::operator()(Block const& _block) -- cgit v1.2.3