mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Consistent terminology for attached/bound functions
This commit is contained in:
+30
-30
@@ -305,7 +305,7 @@ MemberList const& Type::members(ASTNode const* _currentScope) const
|
||||
"");
|
||||
MemberList::MemberMap members = nativeMembers(_currentScope);
|
||||
if (_currentScope)
|
||||
members += boundFunctions(*this, *_currentScope);
|
||||
members += attachedFunctions(*this, *_currentScope);
|
||||
m_members[_currentScope] = make_unique<MemberList>(std::move(members));
|
||||
}
|
||||
return *m_members[_currentScope];
|
||||
@@ -383,7 +383,7 @@ vector<UsingForDirective const*> usingForDirectivesForType(Type const& _type, AS
|
||||
|
||||
}
|
||||
|
||||
MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _scope)
|
||||
MemberList::MemberMap Type::attachedFunctions(Type const& _type, ASTNode const& _scope)
|
||||
{
|
||||
MemberList::MemberMap members;
|
||||
|
||||
@@ -395,13 +395,13 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ASTNode const& _sc
|
||||
Type const* functionType =
|
||||
_function.libraryFunction() ? _function.typeViaContractName() : _function.type();
|
||||
solAssert(functionType, "");
|
||||
FunctionType const* asBoundFunction =
|
||||
dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
|
||||
solAssert(asBoundFunction, "");
|
||||
FunctionType const* withBoundFirstArgument =
|
||||
dynamic_cast<FunctionType const&>(*functionType).withBoundFirstArgument();
|
||||
solAssert(withBoundFirstArgument, "");
|
||||
|
||||
if (_type.isImplicitlyConvertibleTo(*asBoundFunction->selfType()))
|
||||
if (_type.isImplicitlyConvertibleTo(*withBoundFirstArgument->selfType()))
|
||||
if (seenFunctions.insert(make_pair(*_name, &_function)).second)
|
||||
members.emplace_back(&_function, asBoundFunction, *_name);
|
||||
members.emplace_back(&_function, withBoundFirstArgument, *_name);
|
||||
};
|
||||
|
||||
for (UsingForDirective const* ufd: usingForDirectivesForType(_type, _scope))
|
||||
@@ -1879,21 +1879,21 @@ MemberList::MemberMap ArrayType::nativeMembers(ASTNode const*) const
|
||||
strings{string()},
|
||||
strings{string()},
|
||||
FunctionType::Kind::ArrayPush
|
||||
)->asBoundFunction());
|
||||
)->withBoundFirstArgument());
|
||||
members.emplace_back("push", TypeProvider::function(
|
||||
TypePointers{thisAsPointer, baseType()},
|
||||
TypePointers{},
|
||||
strings{string(),string()},
|
||||
strings{},
|
||||
FunctionType::Kind::ArrayPush
|
||||
)->asBoundFunction());
|
||||
)->withBoundFirstArgument());
|
||||
members.emplace_back("pop", TypeProvider::function(
|
||||
TypePointers{thisAsPointer},
|
||||
TypePointers{},
|
||||
strings{string()},
|
||||
strings{},
|
||||
FunctionType::Kind::ArrayPop
|
||||
)->asBoundFunction());
|
||||
)->withBoundFirstArgument());
|
||||
}
|
||||
}
|
||||
return members;
|
||||
@@ -2952,7 +2952,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
|
||||
|
||||
vector<string> FunctionType::parameterNames() const
|
||||
{
|
||||
if (!bound())
|
||||
if (!hasBoundFirstArgument())
|
||||
return m_parameterNames;
|
||||
return vector<string>(m_parameterNames.cbegin() + 1, m_parameterNames.cend());
|
||||
}
|
||||
@@ -2981,7 +2981,7 @@ TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const
|
||||
|
||||
TypePointers FunctionType::parameterTypes() const
|
||||
{
|
||||
if (!bound())
|
||||
if (!hasBoundFirstArgument())
|
||||
return m_parameterTypes;
|
||||
return TypePointers(m_parameterTypes.cbegin() + 1, m_parameterTypes.cend());
|
||||
}
|
||||
@@ -3046,8 +3046,8 @@ string FunctionType::richIdentifier() const
|
||||
id += "value";
|
||||
if (saltSet())
|
||||
id += "salt";
|
||||
if (bound())
|
||||
id += "bound_to" + identifierList(selfType());
|
||||
if (hasBoundFirstArgument())
|
||||
id += "attached_to" + identifierList(selfType());
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -3081,11 +3081,11 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
FunctionType const& convertTo = dynamic_cast<FunctionType const&>(_convertTo);
|
||||
|
||||
// These two checks are duplicated in equalExcludingStateMutability, but are added here for error reporting.
|
||||
if (convertTo.bound() != bound())
|
||||
return BoolResult::err("Bound functions can not be converted to non-bound functions.");
|
||||
if (convertTo.hasBoundFirstArgument() != hasBoundFirstArgument())
|
||||
return BoolResult::err("Attached functions cannot be converted into unattached functions.");
|
||||
|
||||
if (convertTo.kind() != kind())
|
||||
return BoolResult::err("Special functions can not be converted to function types.");
|
||||
return BoolResult::err("Special functions cannot be converted to function types.");
|
||||
|
||||
if (!equalExcludingStateMutability(convertTo))
|
||||
return false;
|
||||
@@ -3122,10 +3122,10 @@ TypeResult FunctionType::binaryOperatorResult(Token _operator, Type const* _othe
|
||||
else if (
|
||||
kind() == Kind::External &&
|
||||
sizeOnStack() == 2 &&
|
||||
!bound() &&
|
||||
!hasBoundFirstArgument() &&
|
||||
other.kind() == Kind::External &&
|
||||
other.sizeOnStack() == 2 &&
|
||||
!other.bound()
|
||||
!other.hasBoundFirstArgument()
|
||||
)
|
||||
return commonType(this, _other);
|
||||
|
||||
@@ -3210,7 +3210,7 @@ bool FunctionType::nameable() const
|
||||
{
|
||||
return
|
||||
(m_kind == Kind::Internal || m_kind == Kind::External) &&
|
||||
!bound() &&
|
||||
!hasBoundFirstArgument() &&
|
||||
!takesArbitraryParameters() &&
|
||||
!gasSet() &&
|
||||
!valueSet() &&
|
||||
@@ -3249,7 +3249,7 @@ vector<tuple<string, Type const*>> FunctionType::makeStackItems() const
|
||||
break;
|
||||
case Kind::ArrayPush:
|
||||
case Kind::ArrayPop:
|
||||
solAssert(bound(), "");
|
||||
solAssert(hasBoundFirstArgument(), "");
|
||||
slots = {};
|
||||
break;
|
||||
default:
|
||||
@@ -3262,7 +3262,7 @@ vector<tuple<string, Type const*>> FunctionType::makeStackItems() const
|
||||
slots.emplace_back("value", TypeProvider::uint256());
|
||||
if (saltSet())
|
||||
slots.emplace_back("salt", TypeProvider::fixedBytes(32));
|
||||
if (bound())
|
||||
if (hasBoundFirstArgument())
|
||||
slots.emplace_back("self", m_parameterTypes.front());
|
||||
return slots;
|
||||
}
|
||||
@@ -3423,7 +3423,7 @@ TypeResult FunctionType::interfaceType(bool /*_inLibrary*/) const
|
||||
|
||||
Type const* FunctionType::mobileType() const
|
||||
{
|
||||
if (valueSet() || gasSet() || saltSet() || bound())
|
||||
if (valueSet() || gasSet() || saltSet() || hasBoundFirstArgument())
|
||||
return nullptr;
|
||||
|
||||
// return function without parameter names
|
||||
@@ -3444,8 +3444,8 @@ bool FunctionType::canTakeArguments(
|
||||
Type const* _selfType
|
||||
) const
|
||||
{
|
||||
solAssert(!bound() || _selfType, "");
|
||||
if (bound() && !_selfType->isImplicitlyConvertibleTo(*selfType()))
|
||||
solAssert(!hasBoundFirstArgument() || _selfType, "");
|
||||
if (hasBoundFirstArgument() && !_selfType->isImplicitlyConvertibleTo(*selfType()))
|
||||
return false;
|
||||
TypePointers paramTypes = parameterTypes();
|
||||
std::vector<std::string> const paramNames = parameterNames();
|
||||
@@ -3524,10 +3524,10 @@ bool FunctionType::equalExcludingStateMutability(FunctionType const& _other) con
|
||||
if (gasSet() != _other.gasSet() || valueSet() != _other.valueSet() || saltSet() != _other.saltSet())
|
||||
return false;
|
||||
|
||||
if (bound() != _other.bound())
|
||||
if (hasBoundFirstArgument() != _other.hasBoundFirstArgument())
|
||||
return false;
|
||||
|
||||
solAssert(!bound() || *selfType() == *_other.selfType(), "");
|
||||
solAssert(!hasBoundFirstArgument() || *selfType() == *_other.selfType(), "");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -3648,14 +3648,14 @@ Type const* FunctionType::copyAndSetCallOptions(bool _setGas, bool _setValue, bo
|
||||
);
|
||||
}
|
||||
|
||||
FunctionTypePointer FunctionType::asBoundFunction() const
|
||||
FunctionTypePointer FunctionType::withBoundFirstArgument() const
|
||||
{
|
||||
solAssert(!m_parameterTypes.empty(), "");
|
||||
solAssert(!gasSet(), "");
|
||||
solAssert(!valueSet(), "");
|
||||
solAssert(!saltSet(), "");
|
||||
Options options = Options::fromFunctionType(*this);
|
||||
options.bound = true;
|
||||
options.hasBoundFirstArgument = true;
|
||||
return TypeProvider::function(
|
||||
m_parameterTypes,
|
||||
m_returnParameterTypes,
|
||||
@@ -3710,7 +3710,7 @@ FunctionTypePointer FunctionType::asExternallyCallableFunction(bool _inLibrary)
|
||||
|
||||
Type const* FunctionType::selfType() const
|
||||
{
|
||||
solAssert(bound(), "Function is not bound.");
|
||||
solAssert(hasBoundFirstArgument(), "Function is not attached to a type.");
|
||||
solAssert(m_parameterTypes.size() > 0, "Function has no self type.");
|
||||
return m_parameterTypes.at(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user