aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/Types.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-10-13 05:02:35 +0800
committerchriseth <c@ethdev.com>2015-10-15 23:38:42 +0800
commit7ebd536e79215f06f5ce7e14591aa494d06032b6 (patch)
treecca1f7597e4c6ddd674db92337424b0fd412b501 /libsolidity/Types.cpp
parent7ba42f470753f9af25531017f319cf94eb26d3f2 (diff)
downloaddexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.tar.gz
dexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.tar.zst
dexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.zip
Tuple expressions.
Diffstat (limited to 'libsolidity/Types.cpp')
-rw-r--r--libsolidity/Types.cpp39
1 files changed, 30 insertions, 9 deletions
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<TupleType const*>(&_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<string> 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<FunctionType>(
parameterTypes,
returnParameterTypes,