aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-26 19:34:43 +0800
committerGitHub <noreply@github.com>2018-11-26 19:34:43 +0800
commitbc137c2eeb6920cf33eea1ceaab49df3dfddad07 (patch)
tree9060bcb1897956e25ba0341a3a6619906bc5d67a /libsolidity/ast
parent9e0e1ee6c229cd904d87ff8c2aba8f56e9da4515 (diff)
parenta781bda5958d2632306118965747fe79cc86f34d (diff)
downloaddexon-solidity-bc137c2eeb6920cf33eea1ceaab49df3dfddad07.tar.gz
dexon-solidity-bc137c2eeb6920cf33eea1ceaab49df3dfddad07.tar.zst
dexon-solidity-bc137c2eeb6920cf33eea1ceaab49df3dfddad07.zip
Merge pull request #5485 from ethereum/refactorCallableFunction
Refactor callable function
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/Types.cpp19
-rw-r--r--libsolidity/ast/Types.h13
2 files changed, 16 insertions, 16 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 0eab75aa..102e43e9 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -442,10 +442,11 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition
if (!function->isVisibleAsLibraryMember() || seenFunctions.count(function))
continue;
seenFunctions.insert(function);
- FunctionType funType(*function, false);
- if (auto fun = funType.asMemberFunction(true, true))
- if (_type.isImplicitlyConvertibleTo(*fun->selfType()))
- members.push_back(MemberList::Member(function->name(), fun, function));
+ if (function->parameters().empty())
+ continue;
+ FunctionTypePointer fun = FunctionType(*function, false).asCallableFunction(true, true);
+ if (_type.isImplicitlyConvertibleTo(*fun->selfType()))
+ members.push_back(MemberList::Member(function->name(), fun, function));
}
}
return members;
@@ -1970,7 +1971,7 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const* _con
for (auto const& it: m_contract.interfaceFunctions())
members.push_back(MemberList::Member(
it.second->declaration().name(),
- it.second->asMemberFunction(m_contract.isLibrary()),
+ it.second->asCallableFunction(m_contract.isLibrary()),
&it.second->declaration()
));
}
@@ -3059,10 +3060,10 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con
);
}
-FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound) const
+FunctionTypePointer FunctionType::asCallableFunction(bool _inLibrary, bool _bound) const
{
- if (_bound && m_parameterTypes.empty())
- return FunctionTypePointer();
+ if (_bound)
+ solAssert(!m_parameterTypes.empty(), "");
TypePointers parameterTypes;
for (auto const& t: m_parameterTypes)
@@ -3201,7 +3202,7 @@ MemberList::MemberMap TypeType::nativeMembers(ContractDefinition const* _current
if (function->isVisibleAsLibraryMember())
members.push_back(MemberList::Member(
function->name(),
- FunctionType(*function).asMemberFunction(true),
+ FunctionType(*function).asCallableFunction(true),
function
));
if (isBase)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 482d6735..953aa557 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -1154,14 +1154,13 @@ public:
/// of the parameters to false.
TypePointer copyAndSetGasOrValue(bool _setGas, bool _setValue) const;
- /// @returns a copy of this function type where all return parameters of dynamic size are
- /// removed and the location of reference types is changed from CallData to Memory.
- /// This is needed if external functions are called on other contracts, as they cannot return
- /// dynamic values.
- /// Returns empty shared pointer on a failure. Namely, if a bound function has no parameters.
+ /// @returns a copy of this function type where the location of reference types is changed
+ /// from CallData to Memory. This is the type that would be used when the function is
+ /// called, as opposed to the parameter types that are available inside the function body.
+ /// Also supports variants to be used for library or bound calls.
/// @param _inLibrary if true, uses DelegateCall as location.
- /// @param _bound if true, the arguments are placed as `arg1.functionName(arg2, ..., argn)`.
- FunctionTypePointer asMemberFunction(bool _inLibrary, bool _bound = false) const;
+ /// @param _bound if true, the function type is set to be bound.
+ FunctionTypePointer asCallableFunction(bool _inLibrary, bool _bound = false) const;
private:
static TypePointers parseElementaryTypeVector(strings const& _types);