[Yul] Adds break/continue statements and some general tests for for-loop syntax.

This commit is contained in:
Christian Parpart
2019-03-11 15:05:05 +01:00
committed by Christian Parpart
parent 4704ef843d
commit 05e2d362c8
24 changed files with 277 additions and 10 deletions
+23 -2
View File
@@ -25,6 +25,7 @@
#include <libyul/AsmScope.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libyul/Utilities.h>
#include <libyul/Exceptions.h>
#include <liblangutil/ErrorReporter.h>
@@ -33,6 +34,7 @@
#include <memory>
#include <functional>
#include <utility>
using namespace std;
using namespace dev;
@@ -472,7 +474,7 @@ bool AsmAnalyzer::operator()(ForLoop const& _for)
{
solAssert(_for.condition, "");
Scope* originalScope = m_currentScope;
Scope* outerScope = m_currentScope;
bool success = true;
if (!(*this)(_for.pre))
@@ -485,18 +487,37 @@ bool AsmAnalyzer::operator()(ForLoop const& _for)
if (!expectExpression(*_for.condition))
success = false;
m_stackHeight--;
// backup outer for-loop & create new state
auto outerForLoop = m_currentForLoop;
m_currentForLoop = &_for;
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;
m_currentScope = outerScope;
m_currentForLoop = outerForLoop;
return success;
}
bool AsmAnalyzer::operator()(Break const& _break)
{
m_info.stackHeightInfo[&_break] = m_stackHeight;
return true;
}
bool AsmAnalyzer::operator()(Continue const& _continue)
{
m_info.stackHeightInfo[&_continue] = m_stackHeight;
return true;
}
bool AsmAnalyzer::operator()(Block const& _block)
{
bool success = true;