added externalType for ArrayType

This commit is contained in:
Liana Husikyan 2015-03-19 16:48:54 +01:00
parent a69d59ae71
commit 607f397234
2 changed files with 24 additions and 6 deletions

View File

@ -742,6 +742,23 @@ string ArrayType::toString() const
return ret + "]"; return ret + "]";
} }
TypePointer ArrayType::externalType() const
{
if (m_location != Location::CallData)
return TypePointer();
if (m_isByteArray)
return shared_from_this();
if (!(m_baseType->externalType()))
return TypePointer();
if (dynamic_cast<ArrayType const*>(m_baseType.get()) && m_baseType->isDynamicallySized())
return TypePointer();
if (m_baseType->isDynamicallySized())
return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType());
else
return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType(), m_length);
}
shared_ptr<ArrayType> ArrayType::copyForLocation(ArrayType::Location _location) const shared_ptr<ArrayType> ArrayType::copyForLocation(ArrayType::Location _location) const
{ {
auto copy = make_shared<ArrayType>(_location); auto copy = make_shared<ArrayType>(_location);

13
Types.h
View File

@ -188,7 +188,7 @@ public:
} }
/// Returns address of type for ABI interface /// Returns address of type for ABI interface
virtual TypePointer ABIType() const { return TypePointer(); } virtual TypePointer externalType() const { return TypePointer(); }
protected: protected:
/// Convenience object used when returning an empty member list. /// Convenience object used when returning an empty member list.
@ -224,7 +224,7 @@ public:
virtual std::string toString() const override; virtual std::string toString() const override;
virtual TypePointer ABIType() const override { return shared_from_this(); } virtual TypePointer externalType() const override { return shared_from_this(); }
int getNumBits() const { return m_bits; } int getNumBits() const { return m_bits; }
bool isAddress() const { return m_modifier == Modifier::Address; } bool isAddress() const { return m_modifier == Modifier::Address; }
@ -263,7 +263,7 @@ public:
virtual std::string toString() const override; virtual std::string toString() const override;
virtual u256 literalValue(Literal const* _literal) const override; virtual u256 literalValue(Literal const* _literal) const override;
virtual TypePointer getRealType() const override; virtual TypePointer getRealType() const override;
virtual TypePointer ABIType() const override { return shared_from_this(); } virtual TypePointer externalType() const override { return shared_from_this(); }
/// @returns the smallest integer type that can hold the value or an empty pointer if not possible. /// @returns the smallest integer type that can hold the value or an empty pointer if not possible.
std::shared_ptr<IntegerType const> getIntegerType() const; std::shared_ptr<IntegerType const> getIntegerType() const;
@ -367,7 +367,8 @@ public:
virtual unsigned getSizeOnStack() const override; virtual unsigned getSizeOnStack() const override;
virtual std::string toString() const override; virtual std::string toString() const override;
virtual MemberList const& getMembers() const override { return s_arrayTypeMemberList; } virtual MemberList const& getMembers() const override { return s_arrayTypeMemberList; }
virtual TypePointer ABIType() const override { return (m_baseType->ABIType() ? m_baseType->ABIType() : ABIType()); } virtual TypePointer externalType() const override;
Location getLocation() const { return m_location; } Location getLocation() const { return m_location; }
bool isByteArray() const { return m_isByteArray; } bool isByteArray() const { return m_isByteArray; }
TypePointer const& getBaseType() const { solAssert(!!m_baseType, ""); return m_baseType;} TypePointer const& getBaseType() const { solAssert(!!m_baseType, ""); return m_baseType;}
@ -406,7 +407,7 @@ public:
virtual std::string toString() const override; virtual std::string toString() const override;
virtual MemberList const& getMembers() const override; virtual MemberList const& getMembers() const override;
virtual TypePointer ABIType() const override { return std::make_shared<IntegerType>(160, IntegerType::Modifier::Address); } virtual TypePointer externalType() const override { return std::make_shared<IntegerType>(160, IntegerType::Modifier::Address); }
bool isSuper() const { return m_super; } bool isSuper() const { return m_super; }
ContractDefinition const& getContractDefinition() const { return m_contract; } ContractDefinition const& getContractDefinition() const { return m_contract; }
@ -475,7 +476,7 @@ public:
virtual bool isValueType() const override { return true; } virtual bool isValueType() const override { return true; }
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual TypePointer ABIType() const override { return std::make_shared<IntegerType>(8 * int(getStorageBytes())); } virtual TypePointer externalType() const override { return std::make_shared<IntegerType>(8 * int(getStorageBytes())); }
EnumDefinition const& getEnumDefinition() const { return m_enum; } EnumDefinition const& getEnumDefinition() const { return m_enum; }
/// @returns the value that the string has in the Enum /// @returns the value that the string has in the Enum