Merge pull request #2504 from ethereum/inlineasm-decl-empty

Support variable declarations without an assignment in assembly
This commit is contained in:
Alex Beregszaszi
2017-07-13 16:58:24 +02:00
committed by GitHub
9 changed files with 68 additions and 16 deletions
+12 -6
View File
@@ -174,14 +174,20 @@ bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl)
{
int const expectedItems = _varDecl.variables.size();
int const stackHeight = m_stackHeight;
bool success = boost::apply_visitor(*this, *_varDecl.value);
if ((m_stackHeight - stackHeight) != expectedItems)
bool success = true;
int const numVariables = _varDecl.variables.size();
if (_varDecl.value)
{
m_errorReporter.declarationError(_varDecl.location, "Variable count mismatch.");
return false;
int const stackHeight = m_stackHeight;
success = boost::apply_visitor(*this, *_varDecl.value);
if ((m_stackHeight - stackHeight) != numVariables)
{
m_errorReporter.declarationError(_varDecl.location, "Variable count mismatch.");
return false;
}
}
else
m_stackHeight += numVariables;
for (auto const& variable: _varDecl.variables)
{
+9 -4
View File
@@ -347,10 +347,15 @@ assembly::VariableDeclaration Parser::parseVariableDeclaration()
else
break;
}
expectToken(Token::Colon);
expectToken(Token::Assign);
varDecl.value.reset(new Statement(parseExpression()));
varDecl.location.end = locationOf(*varDecl.value).end;
if (currentToken() == Token::Colon)
{
expectToken(Token::Colon);
expectToken(Token::Assign);
varDecl.value.reset(new Statement(parseExpression()));
varDecl.location.end = locationOf(*varDecl.value).end;
}
else
varDecl.location.end = varDecl.variables.back().location.end;
return varDecl;
}
+5 -2
View File
@@ -128,8 +128,11 @@ string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDecl
),
", "
);
out += " := ";
out += boost::apply_visitor(*this, *_variableDeclaration.value);
if (_variableDeclaration.value)
{
out += " := ";
out += boost::apply_visitor(*this, *_variableDeclaration.value);
}
return out;
}