[libsolidity] remove ReferenceType::copyForLocationIfReference (use TypeProvider instead)

This commit is contained in:
Christian Parpart 2019-04-17 13:25:03 +02:00
parent b83097bdc6
commit 862b65d6e3
No known key found for this signature in database
GPG Key ID: 19BC8DD20312C929
5 changed files with 9 additions and 21 deletions

View File

@ -231,9 +231,9 @@ void ReferencesResolver::endVisit(Mapping const& _typeName)
TypePointer keyType = _typeName.keyType().annotation().type; TypePointer keyType = _typeName.keyType().annotation().type;
TypePointer valueType = _typeName.valueType().annotation().type; TypePointer valueType = _typeName.valueType().annotation().type;
// Convert key type to memory. // Convert key type to memory.
keyType = ReferenceType::copyForLocationIfReference(DataLocation::Memory, keyType); keyType = TypeProvider::withLocationIfReference(DataLocation::Memory, keyType);
// Convert value type to storage reference. // Convert value type to storage reference.
valueType = ReferenceType::copyForLocationIfReference(DataLocation::Storage, valueType); valueType = TypeProvider::withLocationIfReference(DataLocation::Storage, valueType);
_typeName.annotation().type = TypeProvider::mappingType(keyType, valueType); _typeName.annotation().type = TypeProvider::mappingType(keyType, valueType);
} }

View File

@ -1997,7 +1997,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
_newExpression.typeName().location(), _newExpression.typeName().location(),
"Length has to be placed in parentheses after the array type for new expression." "Length has to be placed in parentheses after the array type for new expression."
); );
type = ReferenceType::copyForLocationIfReference(DataLocation::Memory, type); type = TypeProvider::withLocationIfReference(DataLocation::Memory, type);
_newExpression.annotation().type = TypeProvider::functionType( _newExpression.annotation().type = TypeProvider::functionType(
TypePointers{TypeProvider::uint256()}, TypePointers{TypeProvider::uint256()},
TypePointers{type}, TypePointers{type},
@ -2043,7 +2043,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (initialMemberCount == 0) if (initialMemberCount == 0)
{ {
// Try to see if the member was removed because it is only available for storage types. // Try to see if the member was removed because it is only available for storage types.
auto storageType = ReferenceType::copyForLocationIfReference( auto storageType = TypeProvider::withLocationIfReference(
DataLocation::Storage, DataLocation::Storage,
exprType exprType
); );

View File

@ -343,13 +343,13 @@ TypePointer Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool) c
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.
TypePointer type = ReferenceType::copyForLocationIfReference(DataLocation::Storage, &_type); TypePointer type = TypeProvider::withLocationIfReference(DataLocation::Storage, &_type);
set<Declaration const*> seenFunctions; set<Declaration const*> seenFunctions;
MemberList::MemberMap members; MemberList::MemberMap members;
for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts) for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts)
for (UsingForDirective const* ufd: contract->usingForDirectives()) for (UsingForDirective const* ufd: contract->usingForDirectives())
{ {
if (ufd->typeName() && *type != *ReferenceType::copyForLocationIfReference( if (ufd->typeName() && *type != *TypeProvider::withLocationIfReference(
DataLocation::Storage, DataLocation::Storage,
ufd->typeName()->annotation().type ufd->typeName()->annotation().type
)) ))
@ -1479,16 +1479,9 @@ TypeResult ReferenceType::unaryOperatorResult(Token _operator) const
return nullptr; return nullptr;
} }
TypePointer ReferenceType::copyForLocationIfReference(DataLocation _location, Type const* _type)
{
if (auto type = dynamic_cast<ReferenceType const*>(_type))
return TypeProvider::withLocation(type, _location, false);
return _type;
}
TypePointer ReferenceType::copyForLocationIfReference(Type const* _type) const TypePointer ReferenceType::copyForLocationIfReference(Type const* _type) const
{ {
return copyForLocationIfReference(m_location, _type); return TypeProvider::withLocationIfReference(m_location, _type);
} }
string ReferenceType::stringForReferencePart() const string ReferenceType::stringForReferencePart() const
@ -2202,7 +2195,7 @@ FunctionTypePointer StructType::constructorType() const
if (!member.type->canLiveOutsideStorage()) if (!member.type->canLiveOutsideStorage())
continue; continue;
paramNames.push_back(member.name); paramNames.push_back(member.name);
paramTypes.push_back(copyForLocationIfReference(DataLocation::Memory, member.type)); paramTypes.push_back(TypeProvider::withLocationIfReference(DataLocation::Memory, member.type));
} }
return TypeProvider::functionType( return TypeProvider::functionType(
paramTypes, paramTypes,

View File

@ -654,11 +654,6 @@ public:
return location() == _other.location() && isPointer() == _other.isPointer(); return location() == _other.location() && isPointer() == _other.isPointer();
} }
/// @returns a copy of @a _type having the same location as this (and is not a pointer type)
/// if _type is a reference type and an unmodified copy of _type otherwise.
/// This function is mostly useful to modify inner types appropriately.
static Type const* copyForLocationIfReference(DataLocation _location, Type const* _type);
Type const* withLocation(DataLocation _location, bool _isPointer) const; Type const* withLocation(DataLocation _location, bool _isPointer) const;
protected: protected:

View File

@ -1524,7 +1524,7 @@ void SMTChecker::resetVariables(function<bool(VariableDeclaration const&)> const
TypePointer SMTChecker::typeWithoutPointer(TypePointer const& _type) TypePointer SMTChecker::typeWithoutPointer(TypePointer const& _type)
{ {
if (auto refType = dynamic_cast<ReferenceType const*>(_type)) if (auto refType = dynamic_cast<ReferenceType const*>(_type))
return ReferenceType::copyForLocationIfReference(refType->location(), _type); return TypeProvider::withLocationIfReference(refType->location(), _type);
return _type; return _type;
} }