mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Enable a single right hand item on let
This commit is contained in:
parent
15b4d4def2
commit
cb4966046d
@ -181,32 +181,15 @@ bool AsmAnalyzer::operator()(FunctionalAssignment const& _assignment)
|
||||
|
||||
bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl)
|
||||
{
|
||||
// The number of variable names and values must match. One exception
|
||||
// is a single value, where a tuple assignment is assumed from a function.
|
||||
if (_varDecl.variables.size() != _varDecl.values.size())
|
||||
{
|
||||
if (_varDecl.values.size() != 1)
|
||||
{
|
||||
m_errors.push_back(make_shared<Error>(
|
||||
Error::Type::DeclarationError,
|
||||
"Variable declaration name and value count mismatch.",
|
||||
_varDecl.location
|
||||
));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int const expectedItems = _varDecl.variables.size();
|
||||
int const stackHeight = m_stackHeight;
|
||||
for (auto const& value: _varDecl.values)
|
||||
if (!boost::apply_visitor(*this, value))
|
||||
return false;
|
||||
bool success = boost::apply_visitor(*this, *_varDecl.value);
|
||||
solAssert(m_stackHeight - stackHeight == expectedItems, "Invalid value size.");
|
||||
|
||||
for (auto const& variable: _varDecl.variables)
|
||||
boost::get<Scope::Variable>(m_currentScope->identifiers.at(variable.name)).active = true;
|
||||
m_info.stackHeightInfo[&_varDecl] = m_stackHeight;
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool AsmAnalyzer::operator()(assembly::FunctionDefinition const& _funDef)
|
||||
|
@ -252,8 +252,7 @@ public:
|
||||
{
|
||||
int height = m_assembly.stackHeight();
|
||||
int expectedItems = _varDecl.variables.size();
|
||||
for (auto const& value: _varDecl.values)
|
||||
boost::apply_visitor(*this, value);
|
||||
boost::apply_visitor(*this, *_varDecl.value);
|
||||
expectDeposit(expectedItems, height);
|
||||
for (auto const& variable: _varDecl.variables)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ struct FunctionalAssignment { SourceLocation location; Identifier variableName;
|
||||
struct FunctionalInstruction { SourceLocation location; Instruction instruction; std::vector<Statement> arguments; };
|
||||
struct FunctionCall { SourceLocation location; Identifier functionName; std::vector<Statement> arguments; };
|
||||
/// Block-scope variable declaration ("let x:u256 := mload(20:u256)"), non-hoisted
|
||||
struct VariableDeclaration { SourceLocation location; TypedNameList variables; std::vector<Statement> values; };
|
||||
struct VariableDeclaration { SourceLocation location; TypedNameList variables; std::shared_ptr<Statement> value; };
|
||||
/// Block that creates a scope (frees declared stack variables)
|
||||
struct Block { SourceLocation location; std::vector<Statement> statements; };
|
||||
/// Function definition ("function f(a, b) -> (d, e) { ... }")
|
||||
|
@ -268,15 +268,8 @@ assembly::VariableDeclaration Parser::parseVariableDeclaration()
|
||||
}
|
||||
expectToken(Token::Colon);
|
||||
expectToken(Token::Assign);
|
||||
while (true)
|
||||
{
|
||||
varDecl.values.emplace_back(new Statement(parseExpression()));
|
||||
if (m_scanner->currentToken() == Token::Comma)
|
||||
expectToken(Token::Comma);
|
||||
else
|
||||
break;
|
||||
}
|
||||
varDecl.location.end = locationOf(varDecl.values.back()).end;
|
||||
varDecl.value.reset(new Statement(parseExpression()));
|
||||
varDecl.location.end = locationOf(*varDecl.value).end;
|
||||
return varDecl;
|
||||
}
|
||||
|
||||
|
@ -129,12 +129,7 @@ string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDecl
|
||||
", "
|
||||
);
|
||||
out += " := ";
|
||||
out += boost::algorithm::join(
|
||||
_variableDeclaration.values | boost::adaptors::transformed(
|
||||
[this](Statement statement) { return boost::apply_visitor(*this, statement); }
|
||||
),
|
||||
", "
|
||||
);
|
||||
out += boost::apply_visitor(*this, *_variableDeclaration.value);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user