aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-07-18 21:46:23 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-08-01 18:55:57 +0800
commit7a8a243eef5551189c51c753463683097cf92f94 (patch)
treec5baedf38e2de673ad532279937bd20b143e875c /libsolidity/ast
parentef269bf40d3c6fc044c27654473353c556402b77 (diff)
downloaddexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar.gz
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar.bz2
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar.lz
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar.xz
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.tar.zst
dexon-solidity-7a8a243eef5551189c51c753463683097cf92f94.zip
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 7b079f45..abc76c9f 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.