mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4522 from ethereum/fullEncodingType
Isolate determining the encoding type into its own function.
This commit is contained in:
commit
90a5928b88
@ -1742,22 +1742,8 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
m_errorReporter.typeError(arguments[i]->location(), "Invalid rational number (too large or division by zero).");
|
m_errorReporter.typeError(arguments[i]->location(), "Invalid rational number (too large or division by zero).");
|
||||||
errored = true;
|
errored = true;
|
||||||
}
|
}
|
||||||
if (!errored)
|
if (!errored && !argType->fullEncodingType(false, abiEncodeV2, !functionType->padArguments()))
|
||||||
{
|
m_errorReporter.typeError(arguments[i]->location(), "This type cannot be encoded.");
|
||||||
TypePointer encodingType;
|
|
||||||
if (
|
|
||||||
argType->mobileType() &&
|
|
||||||
argType->mobileType()->interfaceType(false) &&
|
|
||||||
argType->mobileType()->interfaceType(false)->encodingType()
|
|
||||||
)
|
|
||||||
encodingType = argType->mobileType()->interfaceType(false)->encodingType();
|
|
||||||
// Structs are fine as long as ABIV2 is activated and we do not do packed encoding.
|
|
||||||
if (!encodingType || (
|
|
||||||
dynamic_cast<StructType const*>(encodingType.get()) &&
|
|
||||||
!(abiEncodeV2 && functionType->padArguments())
|
|
||||||
))
|
|
||||||
m_errorReporter.typeError(arguments[i]->location(), "This type cannot be encoded.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
|
||||||
{
|
{
|
||||||
|
@ -390,6 +390,27 @@ MemberList const& Type::members(ContractDefinition const* _currentScope) const
|
|||||||
return *m_members[_currentScope];
|
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)
|
MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition const& _scope)
|
||||||
{
|
{
|
||||||
// Normalise data location of type.
|
// Normalise data location of type.
|
||||||
|
@ -280,6 +280,11 @@ public:
|
|||||||
/// This for example returns address for contract types.
|
/// This for example returns address for contract types.
|
||||||
/// If there is no such type, returns an empty shared pointer.
|
/// If there is no such type, returns an empty shared pointer.
|
||||||
virtual TypePointer encodingType() const { return TypePointer(); }
|
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.
|
/// @returns a (simpler) type that is used when decoding this type in calldata.
|
||||||
virtual TypePointer decodingType() const { return encodingType(); }
|
virtual TypePointer decodingType() const { return encodingType(); }
|
||||||
/// @returns a type that will be used outside of Solidity for e.g. function signatures.
|
/// @returns a type that will be used outside of Solidity for e.g. function signatures.
|
||||||
|
@ -471,13 +471,8 @@ string ABIFunctions::abiEncodingFunction(
|
|||||||
bool _fromStack
|
bool _fromStack
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(
|
TypePointer toInterface = _to.fullEncodingType(_encodeAsLibraryTypes, true, false);
|
||||||
_to.mobileType() &&
|
solUnimplementedAssert(toInterface, "Encoding type \"" + _to.toString() + "\" not yet implemented.");
|
||||||
_to.mobileType()->interfaceType(_encodeAsLibraryTypes) &&
|
|
||||||
_to.mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(),
|
|
||||||
"Encoding type \"" + _to.toString() + "\" not yet implemented."
|
|
||||||
);
|
|
||||||
TypePointer toInterface = _to.mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
|
|
||||||
Type const& to = *toInterface;
|
Type const& to = *toInterface;
|
||||||
|
|
||||||
if (_from.category() == Type::Category::StringLiteral)
|
if (_from.category() == Type::Category::StringLiteral)
|
||||||
@ -886,13 +881,8 @@ string ABIFunctions::abiEncodingFunctionStruct(
|
|||||||
solAssert(member.type, "");
|
solAssert(member.type, "");
|
||||||
if (!member.type->canLiveOutsideStorage())
|
if (!member.type->canLiveOutsideStorage())
|
||||||
continue;
|
continue;
|
||||||
solUnimplementedAssert(
|
TypePointer memberTypeTo = member.type->fullEncodingType(_encodeAsLibraryTypes, true, false);
|
||||||
member.type->mobileType() &&
|
solUnimplementedAssert(memberTypeTo, "Encoding type \"" + member.type->toString() + "\" not yet implemented.");
|
||||||
member.type->mobileType()->interfaceType(_encodeAsLibraryTypes) &&
|
|
||||||
member.type->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(),
|
|
||||||
"Encoding type \"" + member.type->toString() + "\" not yet implemented."
|
|
||||||
);
|
|
||||||
auto memberTypeTo = member.type->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
|
|
||||||
auto memberTypeFrom = _from.memberType(member.name);
|
auto memberTypeFrom = _from.memberType(member.name);
|
||||||
solAssert(memberTypeFrom, "");
|
solAssert(memberTypeFrom, "");
|
||||||
bool dynamicMember = memberTypeTo->isDynamicallyEncoded();
|
bool dynamicMember = memberTypeTo->isDynamicallyEncoded();
|
||||||
|
@ -333,26 +333,19 @@ void CompilerUtils::encodeToMemory(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// stack: <v1> <v2> ... <vn> <mem>
|
// stack: <v1> <v2> ... <vn> <mem>
|
||||||
|
bool const encoderV2 = m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2);
|
||||||
TypePointers targetTypes = _targetTypes.empty() ? _givenTypes : _targetTypes;
|
TypePointers targetTypes = _targetTypes.empty() ? _givenTypes : _targetTypes;
|
||||||
solAssert(targetTypes.size() == _givenTypes.size(), "");
|
solAssert(targetTypes.size() == _givenTypes.size(), "");
|
||||||
for (TypePointer& t: targetTypes)
|
for (TypePointer& t: targetTypes)
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(
|
TypePointer tEncoding = t->fullEncodingType(_encodeAsLibraryTypes, encoderV2, !_padToWordBoundaries);
|
||||||
t->mobileType() &&
|
solUnimplementedAssert(tEncoding, "Encoding type \"" + t->toString() + "\" not yet implemented.");
|
||||||
t->mobileType()->interfaceType(_encodeAsLibraryTypes) &&
|
t = std::move(tEncoding);
|
||||||
t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(),
|
|
||||||
"Encoding type \"" + t->toString() + "\" not yet implemented."
|
|
||||||
);
|
|
||||||
t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_givenTypes.empty())
|
if (_givenTypes.empty())
|
||||||
return;
|
return;
|
||||||
else if (
|
else if (_padToWordBoundaries && !_copyDynamicDataInPlace && encoderV2)
|
||||||
_padToWordBoundaries &&
|
|
||||||
!_copyDynamicDataInPlace &&
|
|
||||||
m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Use the new Yul-based encoding function
|
// Use the new Yul-based encoding function
|
||||||
auto stackHeightBefore = m_context.stackHeight();
|
auto stackHeightBefore = m_context.stackHeight();
|
||||||
|
Loading…
Reference in New Issue
Block a user