From 039b2a764f3944768bb253102f4c4b788f2dca9c Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 14 Oct 2015 15:19:50 +0200 Subject: Destructuring assignments. --- libsolidity/ExpressionCompiler.cpp | 41 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'libsolidity/ExpressionCompiler.cpp') diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 85302afc..8109c03b 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -177,20 +177,18 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& bool ExpressionCompiler::visit(Assignment const& _assignment) { +// cout << "-----Assignment" << endl; CompilerContext::LocationSetter locationSetter(m_context, _assignment); _assignment.rightHandSide().accept(*this); - TypePointer type = _assignment.rightHandSide().annotation().type; - if (!_assignment.annotation().type->dataStoredIn(DataLocation::Storage)) - { - utils().convertType(*type, *_assignment.annotation().type); - type = _assignment.annotation().type; - } - else - { - utils().convertType(*type, *type->mobileType()); - type = type->mobileType(); - } + // Perform some conversion already. This will convert storage types to memory and literals + // to their actual type, but will not convert e.g. memory to storage. + TypePointer type = _assignment.rightHandSide().annotation().type->closestTemporaryType( + _assignment.leftHandSide().annotation().type + ); +// cout << "-----Type conversion" << endl; + utils().convertType(*_assignment.rightHandSide().annotation().type, *type); +// cout << "-----LHS" << endl; _assignment.leftHandSide().accept(*this); solAssert(!!m_currentLValue, "LValue not retrieved."); @@ -216,11 +214,32 @@ bool ExpressionCompiler::visit(Assignment const& _assignment) m_context << eth::swapInstruction(itemSize + lvalueSize) << eth::Instruction::POP; } } +// cout << "-----Store" << endl; m_currentLValue->storeValue(*type, _assignment.location()); m_currentLValue.reset(); return false; } +bool ExpressionCompiler::visit(TupleExpression const& _tuple) +{ + vector> lvalues; + for (auto const& component: _tuple.components()) + if (component) + { + component->accept(*this); + if (_tuple.annotation().lValueRequested) + { + solAssert(!!m_currentLValue, ""); + lvalues.push_back(move(m_currentLValue)); + } + } + else if (_tuple.annotation().lValueRequested) + lvalues.push_back(unique_ptr()); + if (_tuple.annotation().lValueRequested) + m_currentLValue.reset(new TupleObject(m_context, move(lvalues))); + return false; +} + bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation) { CompilerContext::LocationSetter locationSetter(m_context, _unaryOperation); -- cgit v1.2.3 From 029b8194892b6b08ce70075bd66f43f66c40e301 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 15 Oct 2015 00:42:36 +0200 Subject: Wildcards. --- libsolidity/ExpressionCompiler.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'libsolidity/ExpressionCompiler.cpp') diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 8109c03b..909d3fe5 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -177,7 +177,6 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& bool ExpressionCompiler::visit(Assignment const& _assignment) { -// cout << "-----Assignment" << endl; CompilerContext::LocationSetter locationSetter(m_context, _assignment); _assignment.rightHandSide().accept(*this); // Perform some conversion already. This will convert storage types to memory and literals @@ -185,10 +184,8 @@ bool ExpressionCompiler::visit(Assignment const& _assignment) TypePointer type = _assignment.rightHandSide().annotation().type->closestTemporaryType( _assignment.leftHandSide().annotation().type ); -// cout << "-----Type conversion" << endl; utils().convertType(*_assignment.rightHandSide().annotation().type, *type); -// cout << "-----LHS" << endl; _assignment.leftHandSide().accept(*this); solAssert(!!m_currentLValue, "LValue not retrieved."); @@ -214,7 +211,6 @@ bool ExpressionCompiler::visit(Assignment const& _assignment) m_context << eth::swapInstruction(itemSize + lvalueSize) << eth::Instruction::POP; } } -// cout << "-----Store" << endl; m_currentLValue->storeValue(*type, _assignment.location()); m_currentLValue.reset(); return false; -- cgit v1.2.3 From 1d4219d43d2839c41e56307f9db04cc23d4741e5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 15 Oct 2015 18:14:14 +0200 Subject: Some fixes taking other pull requests into account. --- libsolidity/ExpressionCompiler.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libsolidity/ExpressionCompiler.cpp') diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 909d3fe5..fde88a00 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -664,9 +664,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // stack: newLength storageSlot slotOffset arguments[0]->accept(*this); // stack: newLength storageSlot slotOffset argValue - TypePointer type = arguments[0]->annotation().type; - utils().convertType(*type, *arrayType->baseType()); - type = arrayType->baseType(); + TypePointer type = arguments[0]->annotation().type->closestTemporaryType(arrayType->baseType()); + utils().convertType(*arguments[0]->annotation().type, *type); utils().moveToStackTop(1 + type->sizeOnStack()); utils().moveToStackTop(1 + type->sizeOnStack()); // stack: newLength argValue storageSlot slotOffset -- cgit v1.2.3