Rename unctionType::bound() to unctionType::boundToType()

This commit is contained in:
wechman 2022-08-30 11:53:02 +02:00
parent c5640fb125
commit 697d279165
8 changed files with 44 additions and 44 deletions

View File

@ -3246,7 +3246,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (auto funType = dynamic_cast<FunctionType const*>(annotation.type)) if (auto funType = dynamic_cast<FunctionType const*>(annotation.type))
{ {
solAssert( solAssert(
!funType->bound() || exprType->isImplicitlyConvertibleTo(*funType->selfType()), !funType->boundToType() || exprType->isImplicitlyConvertibleTo(*funType->selfType()),
"Function \"" + memberName + "\" cannot be called on an object of type " + "Function \"" + memberName + "\" cannot be called on an object of type " +
exprType->humanReadableName() + " (expected " + funType->selfType()->humanReadableName() + ")." exprType->humanReadableName() + " (expected " + funType->selfType()->humanReadableName() + ")."
); );
@ -3273,7 +3273,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
"Storage arrays with nested mappings do not support .push(<arg>)." "Storage arrays with nested mappings do not support .push(<arg>)."
); );
if (!funType->bound()) if (!funType->boundToType())
if (auto typeType = dynamic_cast<TypeType const*>(exprType)) if (auto typeType = dynamic_cast<TypeType const*>(exprType))
{ {
auto contractType = dynamic_cast<ContractType const*>(typeType->actualType()); auto contractType = dynamic_cast<ContractType const*>(typeType->actualType());

View File

@ -450,7 +450,7 @@ FunctionType const* TypeProvider::function(
) )
{ {
// Can only use this constructor for "arbitraryParameters". // Can only use this constructor for "arbitraryParameters".
solAssert(!_options.valueSet && !_options.gasSet && !_options.saltSet && !_options.bound); solAssert(!_options.valueSet && !_options.gasSet && !_options.saltSet && !_options.boundToType);
return createAndGet<FunctionType>( return createAndGet<FunctionType>(
_parameterTypes, _parameterTypes,
_returnParameterTypes, _returnParameterTypes,

View File

@ -3004,7 +3004,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
vector<string> FunctionType::parameterNames() const vector<string> FunctionType::parameterNames() const
{ {
if (!bound()) if (!boundToType())
return m_parameterNames; return m_parameterNames;
return vector<string>(m_parameterNames.cbegin() + 1, m_parameterNames.cend()); return vector<string>(m_parameterNames.cbegin() + 1, m_parameterNames.cend());
} }
@ -3033,7 +3033,7 @@ TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const
TypePointers FunctionType::parameterTypes() const TypePointers FunctionType::parameterTypes() const
{ {
if (!bound()) if (!boundToType())
return m_parameterTypes; return m_parameterTypes;
return TypePointers(m_parameterTypes.cbegin() + 1, m_parameterTypes.cend()); return TypePointers(m_parameterTypes.cbegin() + 1, m_parameterTypes.cend());
} }
@ -3098,7 +3098,7 @@ string FunctionType::richIdentifier() const
id += "value"; id += "value";
if (saltSet()) if (saltSet())
id += "salt"; id += "salt";
if (bound()) if (boundToType())
id += "bound_to" + identifierList(selfType()); id += "bound_to" + identifierList(selfType());
return id; return id;
} }
@ -3133,7 +3133,7 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const
FunctionType const& convertTo = dynamic_cast<FunctionType const&>(_convertTo); FunctionType const& convertTo = dynamic_cast<FunctionType const&>(_convertTo);
// These two checks are duplicated in equalExcludingStateMutability, but are added here for error reporting. // These two checks are duplicated in equalExcludingStateMutability, but are added here for error reporting.
if (convertTo.bound() != bound()) if (convertTo.boundToType() != boundToType())
return BoolResult::err("Bound functions can not be converted to non-bound functions."); return BoolResult::err("Bound functions can not be converted to non-bound functions.");
if (convertTo.kind() != kind()) if (convertTo.kind() != kind())
@ -3174,10 +3174,10 @@ TypeResult FunctionType::binaryOperatorResult(Token _operator, Type const* _othe
else if ( else if (
kind() == Kind::External && kind() == Kind::External &&
sizeOnStack() == 2 && sizeOnStack() == 2 &&
!bound() && !boundToType() &&
other.kind() == Kind::External && other.kind() == Kind::External &&
other.sizeOnStack() == 2 && other.sizeOnStack() == 2 &&
!other.bound() !other.boundToType()
) )
return commonType(this, _other); return commonType(this, _other);
@ -3262,7 +3262,7 @@ bool FunctionType::nameable() const
{ {
return return
(m_kind == Kind::Internal || m_kind == Kind::External) && (m_kind == Kind::Internal || m_kind == Kind::External) &&
!bound() && !boundToType() &&
!takesArbitraryParameters() && !takesArbitraryParameters() &&
!gasSet() && !gasSet() &&
!valueSet() && !valueSet() &&
@ -3301,7 +3301,7 @@ vector<tuple<string, Type const*>> FunctionType::makeStackItems() const
break; break;
case Kind::ArrayPush: case Kind::ArrayPush:
case Kind::ArrayPop: case Kind::ArrayPop:
solAssert(bound(), ""); solAssert(boundToType(), "");
slots = {}; slots = {};
break; break;
default: default:
@ -3314,7 +3314,7 @@ vector<tuple<string, Type const*>> FunctionType::makeStackItems() const
slots.emplace_back("value", TypeProvider::uint256()); slots.emplace_back("value", TypeProvider::uint256());
if (saltSet()) if (saltSet())
slots.emplace_back("salt", TypeProvider::fixedBytes(32)); slots.emplace_back("salt", TypeProvider::fixedBytes(32));
if (bound()) if (boundToType())
slots.emplace_back("self", m_parameterTypes.front()); slots.emplace_back("self", m_parameterTypes.front());
return slots; return slots;
} }
@ -3475,7 +3475,7 @@ TypeResult FunctionType::interfaceType(bool /*_inLibrary*/) const
Type const* FunctionType::mobileType() const Type const* FunctionType::mobileType() const
{ {
if (valueSet() || gasSet() || saltSet() || bound()) if (valueSet() || gasSet() || saltSet() || boundToType())
return nullptr; return nullptr;
// return function without parameter names // return function without parameter names
@ -3496,8 +3496,8 @@ bool FunctionType::canTakeArguments(
Type const* _selfType Type const* _selfType
) const ) const
{ {
solAssert(!bound() || _selfType, ""); solAssert(!boundToType() || _selfType, "");
if (bound() && !_selfType->isImplicitlyConvertibleTo(*selfType())) if (boundToType() && !_selfType->isImplicitlyConvertibleTo(*selfType()))
return false; return false;
TypePointers paramTypes = parameterTypes(); TypePointers paramTypes = parameterTypes();
std::vector<std::string> const paramNames = parameterNames(); std::vector<std::string> const paramNames = parameterNames();
@ -3576,10 +3576,10 @@ bool FunctionType::equalExcludingStateMutability(FunctionType const& _other) con
if (gasSet() != _other.gasSet() || valueSet() != _other.valueSet() || saltSet() != _other.saltSet()) if (gasSet() != _other.gasSet() || valueSet() != _other.valueSet() || saltSet() != _other.saltSet())
return false; return false;
if (bound() != _other.bound()) if (boundToType() != _other.boundToType())
return false; return false;
solAssert(!bound() || *selfType() == *_other.selfType(), ""); solAssert(!boundToType() || *selfType() == *_other.selfType(), "");
return true; return true;
} }
@ -3707,7 +3707,7 @@ FunctionTypePointer FunctionType::asBoundFunction() const
solAssert(!valueSet(), ""); solAssert(!valueSet(), "");
solAssert(!saltSet(), ""); solAssert(!saltSet(), "");
Options options = Options::fromFunctionType(*this); Options options = Options::fromFunctionType(*this);
options.bound = true; options.boundToType = true;
return TypeProvider::function( return TypeProvider::function(
m_parameterTypes, m_parameterTypes,
m_returnParameterTypes, m_returnParameterTypes,
@ -3762,7 +3762,7 @@ FunctionTypePointer FunctionType::asExternallyCallableFunction(bool _inLibrary)
Type const* FunctionType::selfType() const Type const* FunctionType::selfType() const
{ {
solAssert(bound(), "Function is not bound."); solAssert(boundToType(), "Function is not bound.");
solAssert(m_parameterTypes.size() > 0, "Function has no self type."); solAssert(m_parameterTypes.size() > 0, "Function has no self type.");
return m_parameterTypes.at(0); return m_parameterTypes.at(0);
} }

View File

@ -1274,7 +1274,7 @@ public:
bool saltSet = false; bool saltSet = false;
/// true iff the function is called as arg1.fun(arg2, ..., argn). /// true iff the function is called as arg1.fun(arg2, ..., argn).
/// This is achieved through the "using for" directive. /// This is achieved through the "using for" directive.
bool bound = false; bool boundToType = false;
static Options withArbitraryParameters() static Options withArbitraryParameters()
{ {
@ -1289,7 +1289,7 @@ public:
result.gasSet = _type.gasSet(); result.gasSet = _type.gasSet();
result.valueSet = _type.valueSet(); result.valueSet = _type.valueSet();
result.saltSet = _type.saltSet(); result.saltSet = _type.saltSet();
result.bound = _type.bound(); result.boundToType = _type.boundToType();
return result; return result;
} }
}; };
@ -1324,7 +1324,7 @@ public:
) )
{ {
// In this constructor, only the "arbitrary Parameters" option should be used. // In this constructor, only the "arbitrary Parameters" option should be used.
solAssert(!bound() && !gasSet() && !valueSet() && !saltSet()); solAssert(!boundToType() && !gasSet() && !valueSet() && !saltSet());
} }
/// Detailed constructor, use with care. /// Detailed constructor, use with care.
@ -1356,7 +1356,7 @@ public:
"Return parameter names list must match return parameter types list!" "Return parameter names list must match return parameter types list!"
); );
solAssert( solAssert(
!bound() || !m_parameterTypes.empty(), !boundToType() || !m_parameterTypes.empty(),
"Attempted construction of bound function without self type" "Attempted construction of bound function without self type"
); );
} }
@ -1473,7 +1473,7 @@ public:
bool gasSet() const { return m_options.gasSet; } bool gasSet() const { return m_options.gasSet; }
bool valueSet() const { return m_options.valueSet; } bool valueSet() const { return m_options.valueSet; }
bool saltSet() const { return m_options.saltSet; } bool saltSet() const { return m_options.saltSet; }
bool bound() const { return m_options.bound; } bool boundToType() const { return m_options.boundToType; }
/// @returns a copy of this type, where gas or value are set manually. This will never set one /// @returns a copy of this type, where gas or value are set manually. This will never set one
/// of the parameters to false. /// of the parameters to false.

View File

@ -683,7 +683,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
else else
{ {
FunctionType const& function = *functionType; FunctionType const& function = *functionType;
if (function.bound()) if (function.boundToType())
solAssert( solAssert(
function.kind() == FunctionType::Kind::DelegateCall || function.kind() == FunctionType::Kind::DelegateCall ||
function.kind() == FunctionType::Kind::Internal || function.kind() == FunctionType::Kind::Internal ||
@ -708,7 +708,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
bool shortcutTaken = false; bool shortcutTaken = false;
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression())) if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
{ {
solAssert(!function.bound(), ""); solAssert(!function.boundToType(), "");
if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration)) if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration))
{ {
// Do not directly visit the identifier, because this way, we can avoid // Do not directly visit the identifier, because this way, we can avoid
@ -728,7 +728,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
} }
unsigned parameterSize = CompilerUtils::sizeOnStack(function.parameterTypes()); unsigned parameterSize = CompilerUtils::sizeOnStack(function.parameterTypes());
if (function.bound()) if (function.boundToType())
{ {
// stack: arg2, ..., argn, label, arg1 // stack: arg2, ..., argn, label, arg1
unsigned depth = parameterSize + 1; unsigned depth = parameterSize + 1;
@ -977,7 +977,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
argumentType && argumentType &&
functionType->kind() == FunctionType::Kind::External && functionType->kind() == FunctionType::Kind::External &&
argumentType->kind() == FunctionType::Kind::External && argumentType->kind() == FunctionType::Kind::External &&
!argumentType->bound(), !argumentType->boundToType(),
"" ""
); );
@ -1100,7 +1100,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
} }
case FunctionType::Kind::ArrayPush: case FunctionType::Kind::ArrayPush:
{ {
solAssert(function.bound(), ""); solAssert(function.boundToType(), "");
_functionCall.expression().accept(*this); _functionCall.expression().accept(*this);
if (function.parameterTypes().size() == 0) if (function.parameterTypes().size() == 0)
@ -1166,7 +1166,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
case FunctionType::Kind::ArrayPop: case FunctionType::Kind::ArrayPop:
{ {
_functionCall.expression().accept(*this); _functionCall.expression().accept(*this);
solAssert(function.bound(), ""); solAssert(function.boundToType(), "");
solAssert(function.parameterTypes().empty(), ""); solAssert(function.parameterTypes().empty(), "");
ArrayType const* arrayType = dynamic_cast<ArrayType const*>(function.selfType()); ArrayType const* arrayType = dynamic_cast<ArrayType const*>(function.selfType());
solAssert(arrayType && arrayType->dataStoredIn(DataLocation::Storage), ""); solAssert(arrayType && arrayType->dataStoredIn(DataLocation::Storage), "");
@ -1550,7 +1550,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
// Check whether the member is a bound function. // Check whether the member is a bound function.
ASTString const& member = _memberAccess.memberName(); ASTString const& member = _memberAccess.memberName();
if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type)) if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type))
if (funType->bound()) if (funType->boundToType())
{ {
acceptAndConvert(_memberAccess.expression(), *funType->selfType(), true); acceptAndConvert(_memberAccess.expression(), *funType->selfType(), true);
if (funType->kind() == FunctionType::Kind::Internal) if (funType->kind() == FunctionType::Kind::Internal)
@ -2641,14 +2641,14 @@ void ExpressionCompiler::appendExternalFunctionCall(
// function identifier [unless bare] // function identifier [unless bare]
// contract address // contract address
unsigned selfSize = _functionType.bound() ? _functionType.selfType()->sizeOnStack() : 0; unsigned selfSize = _functionType.boundToType() ? _functionType.selfType()->sizeOnStack() : 0;
unsigned gasValueSize = (_functionType.gasSet() ? 1u : 0u) + (_functionType.valueSet() ? 1u : 0u); unsigned gasValueSize = (_functionType.gasSet() ? 1u : 0u) + (_functionType.valueSet() ? 1u : 0u);
unsigned contractStackPos = m_context.currentToBaseStackOffset(1 + gasValueSize + selfSize + (_functionType.isBareCall() ? 0 : 1)); unsigned contractStackPos = m_context.currentToBaseStackOffset(1 + gasValueSize + selfSize + (_functionType.isBareCall() ? 0 : 1));
unsigned gasStackPos = m_context.currentToBaseStackOffset(gasValueSize); unsigned gasStackPos = m_context.currentToBaseStackOffset(gasValueSize);
unsigned valueStackPos = m_context.currentToBaseStackOffset(1); unsigned valueStackPos = m_context.currentToBaseStackOffset(1);
// move self object to top // move self object to top
if (_functionType.bound()) if (_functionType.boundToType())
utils().moveToStackTop(gasValueSize, _functionType.selfType()->sizeOnStack()); utils().moveToStackTop(gasValueSize, _functionType.selfType()->sizeOnStack());
auto funKind = _functionType.kind(); auto funKind = _functionType.kind();
@ -2676,7 +2676,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
// Evaluate arguments. // Evaluate arguments.
TypePointers argumentTypes; TypePointers argumentTypes;
TypePointers parameterTypes = _functionType.parameterTypes(); TypePointers parameterTypes = _functionType.parameterTypes();
if (_functionType.bound()) if (_functionType.boundToType())
{ {
argumentTypes.push_back(_functionType.selfType()); argumentTypes.push_back(_functionType.selfType());
parameterTypes.insert(parameterTypes.begin(), _functionType.selfType()); parameterTypes.insert(parameterTypes.begin(), _functionType.selfType());

View File

@ -321,7 +321,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
_sourceType.isImplicitlyConvertibleTo(*m_dataType), _sourceType.isImplicitlyConvertibleTo(*m_dataType),
"function item stored but target is not implicitly convertible to source" "function item stored but target is not implicitly convertible to source"
); );
solAssert(!fun->bound(), ""); solAssert(!fun->boundToType(), "");
if (fun->kind() == FunctionType::Kind::External) if (fun->kind() == FunctionType::Kind::External)
{ {
solAssert(fun->sizeOnStack() == 2, ""); solAssert(fun->sizeOnStack() == 2, "");

View File

@ -1039,7 +1039,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
solAssert(!functionType->takesArbitraryParameters()); solAssert(!functionType->takesArbitraryParameters());
vector<string> args; vector<string> args;
if (functionType->bound()) if (functionType->boundToType())
args += IRVariable(_functionCall.expression()).part("self").stackSlots(); args += IRVariable(_functionCall.expression()).part("self").stackSlots();
for (size_t i = 0; i < arguments.size(); ++i) for (size_t i = 0; i < arguments.size(); ++i)
@ -1110,7 +1110,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
solAssert( solAssert(
IRVariable(arg).type() == *functionType && IRVariable(arg).type() == *functionType &&
functionType->kind() == FunctionType::Kind::External && functionType->kind() == FunctionType::Kind::External &&
!functionType->bound(), !functionType->boundToType(),
"" ""
); );
define(indexedArgs.emplace_back(m_context.newYulVariable(), *TypeProvider::fixedBytes(32))) << define(indexedArgs.emplace_back(m_context.newYulVariable(), *TypeProvider::fixedBytes(32))) <<
@ -1439,7 +1439,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
} }
case FunctionType::Kind::ArrayPop: case FunctionType::Kind::ArrayPop:
{ {
solAssert(functionType->bound()); solAssert(functionType->boundToType());
solAssert(functionType->parameterTypes().empty()); solAssert(functionType->parameterTypes().empty());
ArrayType const* arrayType = dynamic_cast<ArrayType const*>(functionType->selfType()); ArrayType const* arrayType = dynamic_cast<ArrayType const*>(functionType->selfType());
solAssert(arrayType); solAssert(arrayType);
@ -1643,7 +1643,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
solAssert(!_functionCall.annotation().tryCall); solAssert(!_functionCall.annotation().tryCall);
solAssert(!functionType->valueSet()); solAssert(!functionType->valueSet());
solAssert(!functionType->gasSet()); solAssert(!functionType->gasSet());
solAssert(!functionType->bound()); solAssert(!functionType->boundToType());
static map<FunctionType::Kind, std::tuple<unsigned, size_t>> precompiles = { static map<FunctionType::Kind, std::tuple<unsigned, size_t>> precompiles = {
{FunctionType::Kind::ECRecover, std::make_tuple(1, 0)}, {FunctionType::Kind::ECRecover, std::make_tuple(1, 0)},
@ -1709,7 +1709,7 @@ void IRGeneratorForStatements::endVisit(FunctionCallOptions const& _options)
setLocation(_options); setLocation(_options);
FunctionType const& previousType = dynamic_cast<FunctionType const&>(*_options.expression().annotation().type); FunctionType const& previousType = dynamic_cast<FunctionType const&>(*_options.expression().annotation().type);
solUnimplementedAssert(!previousType.bound()); solUnimplementedAssert(!previousType.boundToType());
// Copy over existing values. // Copy over existing values.
for (auto const& item: previousType.stackItems()) for (auto const& item: previousType.stackItems())
@ -1754,7 +1754,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
auto memberFunctionType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type); auto memberFunctionType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type);
Type::Category objectCategory = _memberAccess.expression().annotation().type->category(); Type::Category objectCategory = _memberAccess.expression().annotation().type->category();
if (memberFunctionType && memberFunctionType->bound()) if (memberFunctionType && memberFunctionType->boundToType())
{ {
define(IRVariable(_memberAccess).part("self"), _memberAccess.expression()); define(IRVariable(_memberAccess).part("self"), _memberAccess.expression());
solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static); solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static);
@ -2592,7 +2592,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
TypePointers parameterTypes = funType.parameterTypes(); TypePointers parameterTypes = funType.parameterTypes();
TypePointers argumentTypes; TypePointers argumentTypes;
vector<string> argumentStrings; vector<string> argumentStrings;
if (funType.bound()) if (funType.boundToType())
{ {
parameterTypes.insert(parameterTypes.begin(), funType.selfType()); parameterTypes.insert(parameterTypes.begin(), funType.selfType());
argumentTypes.emplace_back(funType.selfType()); argumentTypes.emplace_back(funType.selfType());
@ -2741,7 +2741,7 @@ void IRGeneratorForStatements::appendBareCall(
{ {
FunctionType const& funType = dynamic_cast<FunctionType const&>(type(_functionCall.expression())); FunctionType const& funType = dynamic_cast<FunctionType const&>(type(_functionCall.expression()));
solAssert( solAssert(
!funType.bound() && !funType.boundToType() &&
!funType.takesArbitraryParameters() && !funType.takesArbitraryParameters() &&
_arguments.size() == 1 && _arguments.size() == 1 &&
funType.parameterTypes().size() == 1, "" funType.parameterTypes().size() == 1, ""

View File

@ -3118,7 +3118,7 @@ vector<smtutil::Expression> SMTEncoder::symbolicArguments(FunctionCall const& _f
vector<ASTPointer<Expression const>> arguments = _funCall.sortedArguments(); vector<ASTPointer<Expression const>> arguments = _funCall.sortedArguments();
auto functionParams = funDef->parameters(); auto functionParams = funDef->parameters();
unsigned firstParam = 0; unsigned firstParam = 0;
if (funType->bound()) if (funType->boundToType())
{ {
calledExpr = innermostTuple(*calledExpr); calledExpr = innermostTuple(*calledExpr);
auto const& boundFunction = dynamic_cast<MemberAccess const*>(calledExpr); auto const& boundFunction = dynamic_cast<MemberAccess const*>(calledExpr);