mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Support parsing let statements without a value
This commit is contained in:
parent
2b33e0bcec
commit
cee93d946d
@ -174,14 +174,20 @@ bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
|
||||
|
||||
bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl)
|
||||
{
|
||||
bool success = true;
|
||||
int const expectedItems = _varDecl.variables.size();
|
||||
int const stackHeight = m_stackHeight;
|
||||
bool success = boost::apply_visitor(*this, *_varDecl.value);
|
||||
if ((m_stackHeight - stackHeight) != expectedItems)
|
||||
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) != expectedItems)
|
||||
{
|
||||
m_errorReporter.declarationError(_varDecl.location, "Variable count mismatch.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_stackHeight += expectedItems;
|
||||
|
||||
for (auto const& variable: _varDecl.variables)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,11 @@ BOOST_AUTO_TEST_CASE(vardecl_bool)
|
||||
BOOST_CHECK(successParse("{ let x:bool := false:bool }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl_empty)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 2:u256 let y:u256 := x }"));
|
||||
|
@ -195,6 +195,11 @@ BOOST_AUTO_TEST_CASE(vardecl_bool)
|
||||
CHECK_PARSE_ERROR("{ let x := false }", ParserError, "True and false are not valid literals.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl_empty)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x := 2 7 8 add =: x }"));
|
||||
|
Loading…
Reference in New Issue
Block a user