From 7ebd536e79215f06f5ce7e14591aa494d06032b6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 12 Oct 2015 23:02:35 +0200 Subject: Tuple expressions. --- libsolidity/Types.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'libsolidity/Types.cpp') diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 51df5fbf..d7beab26 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -1256,8 +1256,8 @@ string TupleType::toString(bool _short) const return "tuple()"; string str = "tuple("; for (auto const& t: m_components) - str += t->toString(_short) + ", "; - str.resize(str.size() - 2); + str += (t ? t->toString(_short) : "") + ","; + str.pop_back(); return str + ")"; } @@ -1273,10 +1273,30 @@ unsigned TupleType::sizeOnStack() const { unsigned size = 0; for (auto const& t: m_components) - size += t->sizeOnStack(); + size += t ? t->sizeOnStack() : 0; return size; } +bool TupleType::isImplicitlyConvertibleTo(Type const& _other) const +{ + if (auto tupleType = dynamic_cast(&_other)) + { + if (components().size() != tupleType->components().size()) + return false; + for (size_t i = 0; i < components().size(); ++i) + if ((!components()[i]) != (!tupleType->components()[i])) + return false; + else if ( + components()[i] && + !components()[i]->isImplicitlyConvertibleTo(*tupleType->components()[i]) + ) + return false; + return true; + } + else + return false; +} + FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal): m_location(_isInternal ? Location::Internal : Location::External), m_isConstant(_function.isDeclaredConst()), @@ -1638,14 +1658,15 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary) const parameterTypes.push_back(t); } - //@todo make this more intelligent once we support destructuring assignments + // Removes dynamic types. TypePointers returnParameterTypes; vector returnParameterNames; - if (!m_returnParameterTypes.empty() && m_returnParameterTypes.front()->calldataEncodedSize() > 0) - { - returnParameterTypes.push_back(m_returnParameterTypes.front()); - returnParameterNames.push_back(m_returnParameterNames.front()); - } + for (size_t i = 0; i < m_returnParameterTypes.size(); ++i) + if (m_returnParameterTypes[i]->calldataEncodedSize() > 0) + { + returnParameterTypes.push_back(m_returnParameterTypes[i]); + returnParameterNames.push_back(m_returnParameterNames[i]); + } return make_shared( parameterTypes, returnParameterTypes, -- cgit