Change return type for interfaceType() to ResultType

This commit is contained in:
Mathias Baumann 2019-03-18 13:22:42 +01:00
parent 56f2912e61
commit 0fbea8a1a0
5 changed files with 34 additions and 34 deletions

View File

@ -213,7 +213,7 @@ void ReferencesResolver::endVisit(FunctionTypeName const& _typeName)
for (auto const& t: _typeName.parameterTypes() + _typeName.returnParameterTypes())
{
solAssert(t->annotation().type, "Type not set for parameter.");
if (!t->annotation().type->interfaceType(false))
if (!t->annotation().type->interfaceType(false).get())
{
fatalTypeError(t->location(), "Internal type cannot be used for external function type.");
return;

View File

@ -355,7 +355,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
{
if (!type(var)->canLiveOutsideStorage() && _function.isPublic())
m_errorReporter.typeError(var.location(), "Type is required to live outside storage.");
if (_function.isPublic() && !(type(var)->interfaceType(isLibraryFunction)))
if (_function.isPublic() && !(type(var)->interfaceType(isLibraryFunction).get()))
m_errorReporter.fatalTypeError(var.location(), "Internal or recursive type is not allowed for public or external functions.");
}
if (
@ -576,7 +576,7 @@ bool TypeChecker::visit(EventDefinition const& _eventDef)
numIndexed++;
if (!type(*var)->canLiveOutsideStorage())
m_errorReporter.typeError(var->location(), "Type is required to live outside storage.");
if (!type(*var)->interfaceType(false))
if (!type(*var)->interfaceType(false).get())
m_errorReporter.typeError(var->location(), "Internal or recursive type is not allowed as event parameter type.");
if (
!_eventDef.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
@ -599,7 +599,7 @@ void TypeChecker::endVisit(FunctionTypeName const& _funType)
{
FunctionType const& fun = dynamic_cast<FunctionType const&>(*_funType.annotation().type);
if (fun.kind() == FunctionType::Kind::External)
solAssert(fun.interfaceType(false), "External function type uses internal types.");
solAssert(fun.interfaceType(false).get(), "External function type uses internal types.");
}
bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)

View File

@ -1869,7 +1869,7 @@ TypePointer ArrayType::decodingType() const
return shared_from_this();
}
TypePointer ArrayType::interfaceType(bool _inLibrary) const
TypeResult ArrayType::interfaceType(bool _inLibrary) const
{
if (_inLibrary && m_interfaceType_library.is_initialized())
return *m_interfaceType_library;
@ -2135,7 +2135,7 @@ MemberList::MemberMap StructType::nativeMembers(ContractDefinition const*) const
return members;
}
TypePointer StructType::interfaceType(bool _inLibrary) const
TypeResult StructType::interfaceType(bool _inLibrary) const
{
if (_inLibrary && m_interfaceType_library.is_initialized())
return *m_interfaceType_library;
@ -2168,7 +2168,7 @@ TypePointer StructType::interfaceType(bool _inLibrary) const
allOkay = false;
break;
}
if (!var->annotation().type->interfaceType(false))
if (!var->annotation().type->interfaceType(false).get())
{
allOkay = false;
break;
@ -2204,8 +2204,8 @@ string StructType::signatureInExternalFunction(bool _structsByName) const
{
solAssert(_t, "Parameter should have external type.");
auto t = _t->interfaceType(_structsByName);
solAssert(t, "");
return t->signatureInExternalFunction(_structsByName);
solAssert(t.get(), "");
return t.get()->signatureInExternalFunction(_structsByName);
});
return "(" + boost::algorithm::join(memberTypeStrings, ",") + ")";
}
@ -2574,7 +2574,7 @@ FunctionType::FunctionType(FunctionTypeName const& _typeName):
solAssert(t->annotation().type, "Type not set for parameter.");
if (m_kind == Kind::External)
solAssert(
t->annotation().type->interfaceType(false),
t->annotation().type->interfaceType(false).get(),
"Internal type used as parameter for external function."
);
m_parameterTypes.push_back(t->annotation().type);
@ -2584,7 +2584,7 @@ FunctionType::FunctionType(FunctionTypeName const& _typeName):
solAssert(t->annotation().type, "Type not set for return parameter.");
if (m_kind == Kind::External)
solAssert(
t->annotation().type->interfaceType(false),
t->annotation().type->interfaceType(false).get(),
"Internal type used as return parameter for external function."
);
m_returnParameterTypes.push_back(t->annotation().type);
@ -2885,14 +2885,14 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
for (auto type: m_parameterTypes)
{
if (auto ext = type->interfaceType(isLibraryFunction))
if (auto ext = type->interfaceType(isLibraryFunction).get())
paramTypes.push_back(ext);
else
return FunctionTypePointer();
}
for (auto type: m_returnParameterTypes)
{
if (auto ext = type->interfaceType(isLibraryFunction))
if (auto ext = type->interfaceType(isLibraryFunction).get())
retParamTypes.push_back(ext);
else
return FunctionTypePointer();
@ -2978,7 +2978,7 @@ TypePointer FunctionType::encodingType() const
return TypePointer();
}
TypePointer FunctionType::interfaceType(bool /*_inLibrary*/) const
TypeResult FunctionType::interfaceType(bool /*_inLibrary*/) const
{
if (m_kind == Kind::External)
return shared_from_this();

View File

@ -304,7 +304,7 @@ public:
/// 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(); }
virtual TypeResult interfaceType(bool /*_inLibrary*/) const { return TypePointer(); }
private:
/// @returns a member list containing all members added to this type by `using for` directives.
@ -355,7 +355,7 @@ public:
u256 literalValue(Literal const* _literal) const override;
TypePointer encodingType() const override { return shared_from_this(); }
TypePointer interfaceType(bool) const override { return shared_from_this(); }
TypeResult interfaceType(bool) const override { return shared_from_this(); }
StateMutability stateMutability(void) const { return m_stateMutability; }
@ -395,7 +395,7 @@ public:
std::string toString(bool _short) const override;
TypePointer encodingType() const override { return shared_from_this(); }
TypePointer interfaceType(bool) const override { return shared_from_this(); }
TypeResult interfaceType(bool) const override { return shared_from_this(); }
unsigned numBits() const { return m_bits; }
bool isSigned() const { return m_modifier == Modifier::Signed; }
@ -437,7 +437,7 @@ public:
std::string toString(bool _short) const override;
TypePointer encodingType() const override { return shared_from_this(); }
TypePointer interfaceType(bool) const override { return shared_from_this(); }
TypeResult interfaceType(bool) const override { return shared_from_this(); }
/// Number of bits used for this type in total.
unsigned numBits() const { return m_totalBits; }
@ -583,7 +583,7 @@ public:
std::string toString(bool) const override { return "bytes" + dev::toString(m_bytes); }
MemberList::MemberMap nativeMembers(ContractDefinition const*) const override;
TypePointer encodingType() const override { return shared_from_this(); }
TypePointer interfaceType(bool) const override { return shared_from_this(); }
TypeResult interfaceType(bool) const override { return shared_from_this(); }
unsigned numBytes() const { return m_bytes; }
@ -609,7 +609,7 @@ public:
std::string toString(bool) const override { return "bool"; }
u256 literalValue(Literal const* _literal) const override;
TypePointer encodingType() const override { return shared_from_this(); }
TypePointer interfaceType(bool) const override { return shared_from_this(); }
TypeResult interfaceType(bool) const override { return shared_from_this(); }
};
/**
@ -716,7 +716,7 @@ public:
MemberList::MemberMap nativeMembers(ContractDefinition const* _currentScope) const override;
TypePointer encodingType() const override;
TypePointer decodingType() const override;
TypePointer interfaceType(bool _inLibrary) const override;
TypeResult interfaceType(bool _inLibrary) const override;
/// @returns true if this is valid to be stored in calldata
bool validForCalldata() const;
@ -749,8 +749,8 @@ private:
TypePointer m_baseType;
bool m_hasDynamicLength = true;
u256 m_length;
mutable boost::optional<TypePointer> m_interfaceType;
mutable boost::optional<TypePointer> m_interfaceType_library;
mutable boost::optional<TypeResult> m_interfaceType;
mutable boost::optional<TypeResult> m_interfaceType_library;
};
/**
@ -788,7 +788,7 @@ public:
return TypePointer{};
return std::make_shared<AddressType>(isPayable() ? StateMutability::Payable : StateMutability::NonPayable);
}
TypePointer interfaceType(bool _inLibrary) const override
TypeResult interfaceType(bool _inLibrary) const override
{
if (isSuper())
return TypePointer{};
@ -842,7 +842,7 @@ public:
{
return location() == DataLocation::Storage ? std::make_shared<IntegerType>(256) : shared_from_this();
}
TypePointer interfaceType(bool _inLibrary) const override;
TypeResult interfaceType(bool _inLibrary) const override;
TypePointer copyForLocation(DataLocation _location, bool _isPointer) const override;
@ -872,8 +872,8 @@ private:
StructDefinition const& m_struct;
/// Cache for the recursive() function.
mutable boost::optional<bool> m_recursive;
mutable boost::optional<TypePointer> m_interfaceType;
mutable boost::optional<TypePointer> m_interfaceType_library;
mutable boost::optional<TypeResult> m_interfaceType;
mutable boost::optional<TypeResult> m_interfaceType_library;
};
/**
@ -902,7 +902,7 @@ public:
{
return std::make_shared<IntegerType>(8 * int(storageBytes()));
}
TypePointer interfaceType(bool _inLibrary) const override
TypeResult interfaceType(bool _inLibrary) const override
{
return _inLibrary ? shared_from_this() : encodingType();
}
@ -1098,7 +1098,7 @@ public:
bool hasSimpleZeroValueInMemory() const override { return false; }
MemberList::MemberMap nativeMembers(ContractDefinition const* _currentScope) const override;
TypePointer encodingType() const override;
TypePointer interfaceType(bool _inLibrary) const override;
TypeResult interfaceType(bool _inLibrary) 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
@ -1223,7 +1223,7 @@ public:
{
return std::make_shared<IntegerType>(256);
}
TypePointer interfaceType(bool _inLibrary) const override
TypeResult interfaceType(bool _inLibrary) const override
{
return _inLibrary ? shared_from_this() : TypePointer();
}

View File

@ -107,9 +107,9 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
for (auto const& p: it->parameters())
{
auto type = p->annotation().type->interfaceType(false);
solAssert(type, "");
solAssert(type.get(), "");
Json::Value input;
auto param = formatType(p->name(), *type, false);
auto param = formatType(p->name(), *type.get(), false);
param["indexed"] = p->isIndexed();
params.append(param);
}
@ -173,8 +173,8 @@ Json::Value ABI::formatType(string const& _name, Type const& _type, bool _forLib
{
solAssert(member.type, "");
auto t = member.type->interfaceType(_forLibrary);
solAssert(t, "");
ret["components"].append(formatType(member.name, *t, _forLibrary));
solAssert(t.get(), "");
ret["components"].append(formatType(member.name, *t.get(), _forLibrary));
}
}
else