aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-02 21:01:38 +0800
committerGitHub <noreply@github.com>2018-08-02 21:01:38 +0800
commit90a5928b883dc9bbc889269a4e86d3d32c79d8ca (patch)
treec5f1c13acbd203ae5cf3ef5f97717c72d6a80e9e /libsolidity/ast
parentf7c96c8dee43652e5c9c52078db524c27bc29aec (diff)
parent7a8a243eef5551189c51c753463683097cf92f94 (diff)
downloaddexon-solidity-90a5928b883dc9bbc889269a4e86d3d32c79d8ca.tar.gz
dexon-solidity-90a5928b883dc9bbc889269a4e86d3d32c79d8ca.tar.zst
dexon-solidity-90a5928b883dc9bbc889269a4e86d3d32c79d8ca.zip
Merge pull request #4522 from ethereum/fullEncodingType
Isolate determining the encoding type into its own function.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/Types.cpp21
-rw-r--r--libsolidity/ast/Types.h5
2 files changed, 26 insertions, 0 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index c85e0522..0954fdf3 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -390,6 +390,27 @@ MemberList const& Type::members(ContractDefinition const* _currentScope) const
return *m_members[_currentScope];
}
+TypePointer Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool _packed) const
+{
+ TypePointer encodingType = mobileType();
+ if (encodingType)
+ encodingType = encodingType->interfaceType(_inLibraryCall);
+ if (encodingType)
+ encodingType = encodingType->encodingType();
+ if (auto structType = dynamic_cast<StructType const*>(encodingType.get()))
+ {
+ // Structs are fine in the following circumstances:
+ // - ABIv2 without packed encoding or,
+ // - storage struct for a library
+ if (!(
+ (_encoderV2 && !_packed) ||
+ (structType->location() == DataLocation::Storage && _inLibraryCall)
+ ))
+ return TypePointer();
+ }
+ return encodingType;
+}
+
MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition const& _scope)
{
// Normalise data location of type.
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 474a6f33..12029a4e 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -280,6 +280,11 @@ public:
/// This for example returns address for contract types.
/// If there is no such type, returns an empty shared pointer.
virtual TypePointer encodingType() const { return TypePointer(); }
+ /// @returns the encoding type used under the given circumstances for the type of an expression
+ /// when used for e.g. abi.encode(...) or the empty pointer if the object
+ /// cannot be encoded.
+ /// This is different from encodingType since it takes implicit conversions into account.
+ TypePointer fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool _packed) const;
/// @returns a (simpler) type that is used when decoding this type in calldata.
virtual TypePointer decodingType() const { return encodingType(); }
/// @returns a type that will be used outside of Solidity for e.g. function signatures.