diff options
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 60 |
1 files changed, 55 insertions, 5 deletions
@@ -561,6 +561,21 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal m_location = _isInternal ? Location::INTERNAL : Location::EXTERNAL; } +FunctionType::FunctionType(TypePointers const& _parameterTypes, TypePointers const& _returnParameterTypes, + FunctionType::Location _location, bool _gasSet, bool _valueSet): + m_parameterTypes(_parameterTypes), m_returnParameterTypes(_returnParameterTypes), + m_location(_location), m_gasSet(_gasSet), m_valueSet(_valueSet) +{ + if (m_location == Location::EXTERNAL) + m_sizeOnStack = 2; + else if (m_location == Location::INTERNAL || m_location == Location::BARE) + m_sizeOnStack = 1; + if (m_gasSet) + m_sizeOnStack++; + if (m_valueSet) + m_sizeOnStack++; +} + bool FunctionType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) @@ -580,6 +595,9 @@ bool FunctionType::operator==(Type const& _other) const if (!equal(m_returnParameterTypes.cbegin(), m_returnParameterTypes.cend(), other.m_returnParameterTypes.cbegin(), typeCompare)) return false; + //@todo this is ugly, but cannot be prevented right now + if (m_gasSet != other.m_gasSet || m_valueSet != other.m_valueSet) + return false; return true; } @@ -596,16 +614,41 @@ string FunctionType::toString() const unsigned FunctionType::getSizeOnStack() const { + unsigned size = 0; + if (m_location == Location::EXTERNAL) + size = 2; + else if (m_location == Location::INTERNAL || m_location == Location::BARE) + size = 1; + if (m_gasSet) + size++; + if (m_valueSet) + size++; + return size; +} + +MemberList const& FunctionType::getMembers() const +{ switch (m_location) { - case Location::INTERNAL: - return 1; case Location::EXTERNAL: - return 2; + case Location::ECRECOVER: + case Location::SHA256: + case Location::RIPEMD160: case Location::BARE: - return 1; + if (!m_members) + { + map<string, TypePointer> members{ + {"gas", make_shared<FunctionType>(parseElementaryTypeVector({"uint"}), + TypePointers{copyAndSetGasOrValue(true, false)}, + Location::SET_GAS, m_gasSet, m_valueSet)}, + {"value", make_shared<FunctionType>(parseElementaryTypeVector({"uint"}), + TypePointers{copyAndSetGasOrValue(false, true)}, + Location::SET_VALUE, m_gasSet, m_valueSet)}}; + m_members.reset(new MemberList(members)); + } + return *m_members; default: - return 0; + return EmptyMemberList; } } @@ -628,6 +671,13 @@ TypePointers FunctionType::parseElementaryTypeVector(strings const& _types) return pointers; } +TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const +{ + return make_shared<FunctionType>(m_parameterTypes, m_returnParameterTypes, m_location, + m_gasSet || _setGas, m_valueSet || _setValue); +} + + bool MappingType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) |