From 3d18c02f3697d4399d50962f31fd11c2523c0371 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 19 Mar 2015 16:48:54 +0100 Subject: [PATCH] added externalType for ArrayType --- libsolidity/Types.cpp | 17 +++++++++++++++++ libsolidity/Types.h | 13 +++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 016f0b236..6fe8a6410 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -742,6 +742,23 @@ string ArrayType::toString() const 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(m_baseType.get()) && m_baseType->isDynamicallySized()) + return TypePointer(); + + if (m_baseType->isDynamicallySized()) + return std::make_shared(Location::CallData, m_baseType->externalType()); + else + return std::make_shared(Location::CallData, m_baseType->externalType(), m_length); +} + shared_ptr ArrayType::copyForLocation(ArrayType::Location _location) const { auto copy = make_shared(_location); diff --git a/libsolidity/Types.h b/libsolidity/Types.h index 3d3a263d5..013c65893 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -188,7 +188,7 @@ public: } /// Returns address of type for ABI interface - virtual TypePointer ABIType() const { return TypePointer(); } + virtual TypePointer externalType() const { return TypePointer(); } protected: /// Convenience object used when returning an empty member list. @@ -224,7 +224,7 @@ public: 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; } bool isAddress() const { return m_modifier == Modifier::Address; } @@ -263,7 +263,7 @@ public: virtual std::string toString() const override; virtual u256 literalValue(Literal const* _literal) 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. std::shared_ptr getIntegerType() const; @@ -367,7 +367,8 @@ public: virtual unsigned getSizeOnStack() const override; virtual std::string toString() const override; 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; } bool isByteArray() const { return m_isByteArray; } TypePointer const& getBaseType() const { solAssert(!!m_baseType, ""); return m_baseType;} @@ -406,7 +407,7 @@ public: virtual std::string toString() const override; virtual MemberList const& getMembers() const override; - virtual TypePointer ABIType() const override { return std::make_shared(160, IntegerType::Modifier::Address); } + virtual TypePointer externalType() const override { return std::make_shared(160, IntegerType::Modifier::Address); } bool isSuper() const { return m_super; } ContractDefinition const& getContractDefinition() const { return m_contract; } @@ -475,7 +476,7 @@ public: virtual bool isValueType() const override { return true; } virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; - virtual TypePointer ABIType() const override { return std::make_shared(8 * int(getStorageBytes())); } + virtual TypePointer externalType() const override { return std::make_shared(8 * int(getStorageBytes())); } EnumDefinition const& getEnumDefinition() const { return m_enum; } /// @returns the value that the string has in the Enum