diff options
author | chriseth <c@ethdev.com> | 2015-10-02 19:11:38 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-06 20:19:56 +0800 |
commit | 9cc7402c9583ca3bfc9fcb234443d2f90b890190 (patch) | |
tree | b69181225de53fefc5df93dd64e6885db9d85eb0 /libsolidity/Types.h | |
parent | d2332769d3e87b3500638591c23241ebd942fbb1 (diff) | |
download | dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.gz dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.zst dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.zip |
Split external type into ecoding and interface type.
Diffstat (limited to 'libsolidity/Types.h')
-rw-r--r-- | libsolidity/Types.h | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/libsolidity/Types.h b/libsolidity/Types.h index 73111e48..972876e9 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -226,9 +226,16 @@ public: ); } - /// @returns a type suitable for outside of Solidity, i.e. for contract types it returns address. + /// @returns a (simpler) type that is encoded in the same way for external function calls. + /// This for example returns address for contract types. /// If there is no such type, returns an empty shared pointer. - virtual TypePointer externalType() const { return TypePointer(); } + virtual TypePointer encodingType() const { return TypePointer(); } + /// @returns a type that will be used outside of Solidity for e.g. function signatures. + /// This for example returns address for contract types. + /// If there is no such type, returns an empty shared pointer. + /// @param _inLibrary if set, returns types as used in a library, e.g. struct and contract types + /// are returned without modification. + virtual TypePointer interfaceType(bool /*_inLibrary*/) const { return TypePointer(); } protected: /// Convenience object used when returning an empty member list. @@ -264,7 +271,8 @@ public: virtual std::string toString(bool _short) const override; - virtual TypePointer externalType() const override { return shared_from_this(); } + virtual TypePointer encodingType() const override { return shared_from_this(); } + virtual TypePointer interfaceType(bool) const override { return shared_from_this(); } int numBits() const { return m_bits; } bool isAddress() const { return m_modifier == Modifier::Address; } @@ -369,7 +377,8 @@ public: virtual bool isValueType() const override { return true; } virtual std::string toString(bool) const override { return "bytes" + dev::toString(m_bytes); } - virtual TypePointer externalType() const override { return shared_from_this(); } + virtual TypePointer encodingType() const override { return shared_from_this(); } + virtual TypePointer interfaceType(bool) const override { return shared_from_this(); } int numBytes() const { return m_bytes; } @@ -395,7 +404,8 @@ public: virtual std::string toString(bool) const override { return "bool"; } virtual u256 literalValue(Literal const* _literal) const override; - virtual TypePointer externalType() const override { return shared_from_this(); } + virtual TypePointer encodingType() const override { return shared_from_this(); } + virtual TypePointer interfaceType(bool) const override { return shared_from_this(); } }; /** @@ -493,7 +503,8 @@ public: { return isString() ? EmptyMemberList : s_arrayTypeMemberList; } - virtual TypePointer externalType() const override; + virtual TypePointer encodingType() const override; + virtual TypePointer interfaceType(bool _inLibrary) const override; /// @returns true if this is a byte array or a string bool isByteArray() const { return m_arrayKind != ArrayKind::Ordinary; } @@ -534,7 +545,7 @@ public: virtual bool operator==(Type const& _other) const override; virtual unsigned calldataEncodedSize(bool _padded ) const override { - return externalType()->calldataEncodedSize(_padded); + return encodingType()->calldataEncodedSize(_padded); } virtual unsigned storageBytes() const override { return 20; } virtual bool canLiveOutsideStorage() const override { return true; } @@ -542,10 +553,14 @@ public: virtual std::string toString(bool _short) const override; virtual MemberList const& members() const override; - virtual TypePointer externalType() const override + virtual TypePointer encodingType() const override { return std::make_shared<IntegerType>(160, IntegerType::Modifier::Address); } + virtual TypePointer interfaceType(bool _inLibrary) const override + { + return _inLibrary ? shared_from_this() : encodingType(); + } bool isSuper() const { return m_super; } ContractDefinition const& contractDefinition() const { return m_contract; } @@ -566,7 +581,7 @@ private: ContractDefinition const& m_contract; /// If true, it is the "super" type of the current contract, i.e. it contains only inherited /// members. - bool m_super; + bool m_super = false; /// Type of the constructor, @see constructorType. Lazily initialized. mutable FunctionTypePointer m_constructorType; /// List of member types, will be lazy-initialized because of recursive references. @@ -591,6 +606,11 @@ public: virtual std::string toString(bool _short) const override; virtual MemberList const& members() const override; + virtual TypePointer encodingType() const override + { + return location() == DataLocation::Storage ? std::make_shared<IntegerType>(256) : TypePointer(); + } + virtual TypePointer interfaceType(bool _inLibrary) const override; TypePointer copyForLocation(DataLocation _location, bool _isPointer) const override; @@ -624,7 +644,7 @@ public: virtual bool operator==(Type const& _other) const override; virtual unsigned calldataEncodedSize(bool _padded) const override { - return externalType()->calldataEncodedSize(_padded); + return encodingType()->calldataEncodedSize(_padded); } virtual unsigned storageBytes() const override; virtual bool canLiveOutsideStorage() const override { return true; } @@ -632,10 +652,14 @@ public: virtual bool isValueType() const override { return true; } virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; - virtual TypePointer externalType() const override + virtual TypePointer encodingType() const override { return std::make_shared<IntegerType>(8 * int(storageBytes())); } + virtual TypePointer interfaceType(bool _inLibrary) const override + { + return _inLibrary ? shared_from_this() : encodingType(); + } EnumDefinition const& enumDefinition() const { return m_enum; } /// @returns the value that the string has in the Enum @@ -684,13 +708,6 @@ public: virtual Category category() const override { return Category::Function; } - /// @returns TypePointer of a new FunctionType object. All input/return parameters are an - /// appropriate external types of input/return parameters of current function. - /// Returns an empty shared pointer if one of the input/return parameters does not have an - /// external type. - FunctionTypePointer externalFunctionType() const; - virtual TypePointer externalType() const override { return externalFunctionType(); } - /// Creates the type of a function. explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true); /// Creates the accessor function type of a state variable. @@ -749,6 +766,13 @@ public: virtual unsigned sizeOnStack() const override; virtual MemberList const& members() const override; + /// @returns TypePointer of a new FunctionType object. All input/return parameters are an + /// appropriate external types (i.e. the interfaceType()s) of input/return parameters of + /// current function. + /// Returns an empty shared pointer if one of the input/return parameters does not have an + /// external type. + FunctionTypePointer interfaceFunctionType() const; + /// @returns true if this function can take the given argument types (possibly /// after implicit conversion). bool canTakeArguments(TypePointers const& _arguments) const; @@ -823,6 +847,14 @@ public: virtual bool operator==(Type const& _other) const override; virtual std::string toString(bool _short) const override; virtual bool canLiveOutsideStorage() const override { return false; } + virtual TypePointer encodingType() const override + { + return std::make_shared<IntegerType>(256); + } + virtual TypePointer interfaceType(bool _inLibrary) const override + { + return _inLibrary ? shared_from_this() : TypePointer(); + } TypePointer const& keyType() const { return m_keyType; } TypePointer const& valueType() const { return m_valueType; } |