diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 06b98d69c..7095b88b0 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3246,7 +3246,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) if (auto funType = dynamic_cast(annotation.type)) { solAssert( - !funType->bound() || exprType->isImplicitlyConvertibleTo(*funType->selfType()), + !funType->boundToType() || exprType->isImplicitlyConvertibleTo(*funType->selfType()), "Function \"" + memberName + "\" cannot be called on an object of type " + 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()." ); - if (!funType->bound()) + if (!funType->boundToType()) if (auto typeType = dynamic_cast(exprType)) { auto contractType = dynamic_cast(typeType->actualType()); diff --git a/libsolidity/ast/TypeProvider.cpp b/libsolidity/ast/TypeProvider.cpp index 91d1da4be..fb30ae97d 100644 --- a/libsolidity/ast/TypeProvider.cpp +++ b/libsolidity/ast/TypeProvider.cpp @@ -450,7 +450,7 @@ FunctionType const* TypeProvider::function( ) { // 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( _parameterTypes, _returnParameterTypes, diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index e5ce3a825..4adb1ffc7 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3004,7 +3004,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c vector FunctionType::parameterNames() const { - if (!bound()) + if (!boundToType()) return m_parameterNames; return vector(m_parameterNames.cbegin() + 1, m_parameterNames.cend()); } @@ -3033,7 +3033,7 @@ TypePointers FunctionType::returnParameterTypesWithoutDynamicTypes() const TypePointers FunctionType::parameterTypes() const { - if (!bound()) + if (!boundToType()) return m_parameterTypes; return TypePointers(m_parameterTypes.cbegin() + 1, m_parameterTypes.cend()); } @@ -3098,7 +3098,7 @@ string FunctionType::richIdentifier() const id += "value"; if (saltSet()) id += "salt"; - if (bound()) + if (boundToType()) id += "bound_to" + identifierList(selfType()); return id; } @@ -3133,7 +3133,7 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const FunctionType const& convertTo = dynamic_cast(_convertTo); // 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."); if (convertTo.kind() != kind()) @@ -3174,10 +3174,10 @@ TypeResult FunctionType::binaryOperatorResult(Token _operator, Type const* _othe else if ( kind() == Kind::External && sizeOnStack() == 2 && - !bound() && + !boundToType() && other.kind() == Kind::External && other.sizeOnStack() == 2 && - !other.bound() + !other.boundToType() ) return commonType(this, _other); @@ -3262,7 +3262,7 @@ bool FunctionType::nameable() const { return (m_kind == Kind::Internal || m_kind == Kind::External) && - !bound() && + !boundToType() && !takesArbitraryParameters() && !gasSet() && !valueSet() && @@ -3301,7 +3301,7 @@ vector> FunctionType::makeStackItems() const break; case Kind::ArrayPush: case Kind::ArrayPop: - solAssert(bound(), ""); + solAssert(boundToType(), ""); slots = {}; break; default: @@ -3314,7 +3314,7 @@ vector> FunctionType::makeStackItems() const slots.emplace_back("value", TypeProvider::uint256()); if (saltSet()) slots.emplace_back("salt", TypeProvider::fixedBytes(32)); - if (bound()) + if (boundToType()) slots.emplace_back("self", m_parameterTypes.front()); return slots; } @@ -3475,7 +3475,7 @@ TypeResult FunctionType::interfaceType(bool /*_inLibrary*/) const Type const* FunctionType::mobileType() const { - if (valueSet() || gasSet() || saltSet() || bound()) + if (valueSet() || gasSet() || saltSet() || boundToType()) return nullptr; // return function without parameter names @@ -3496,8 +3496,8 @@ bool FunctionType::canTakeArguments( Type const* _selfType ) const { - solAssert(!bound() || _selfType, ""); - if (bound() && !_selfType->isImplicitlyConvertibleTo(*selfType())) + solAssert(!boundToType() || _selfType, ""); + if (boundToType() && !_selfType->isImplicitlyConvertibleTo(*selfType())) return false; TypePointers paramTypes = parameterTypes(); std::vector const paramNames = parameterNames(); @@ -3576,10 +3576,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 (boundToType() != _other.boundToType()) return false; - solAssert(!bound() || *selfType() == *_other.selfType(), ""); + solAssert(!boundToType() || *selfType() == *_other.selfType(), ""); return true; } @@ -3707,7 +3707,7 @@ FunctionTypePointer FunctionType::asBoundFunction() const solAssert(!valueSet(), ""); solAssert(!saltSet(), ""); Options options = Options::fromFunctionType(*this); - options.bound = true; + options.boundToType = true; return TypeProvider::function( m_parameterTypes, m_returnParameterTypes, @@ -3762,7 +3762,7 @@ FunctionTypePointer FunctionType::asExternallyCallableFunction(bool _inLibrary) 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."); return m_parameterTypes.at(0); } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 0918372aa..6a482ddc6 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1274,7 +1274,7 @@ public: bool saltSet = false; /// true iff the function is called as arg1.fun(arg2, ..., argn). /// This is achieved through the "using for" directive. - bool bound = false; + bool boundToType = false; static Options withArbitraryParameters() { @@ -1289,7 +1289,7 @@ public: result.gasSet = _type.gasSet(); result.valueSet = _type.valueSet(); result.saltSet = _type.saltSet(); - result.bound = _type.bound(); + result.boundToType = _type.boundToType(); return result; } }; @@ -1324,7 +1324,7 @@ public: ) { // 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. @@ -1356,7 +1356,7 @@ public: "Return parameter names list must match return parameter types list!" ); solAssert( - !bound() || !m_parameterTypes.empty(), + !boundToType() || !m_parameterTypes.empty(), "Attempted construction of bound function without self type" ); } @@ -1473,7 +1473,7 @@ public: bool gasSet() const { return m_options.gasSet; } bool valueSet() const { return m_options.valueSet; } 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 /// of the parameters to false. diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 5767e7f13..f1fe2cac7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -683,7 +683,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) else { FunctionType const& function = *functionType; - if (function.bound()) + if (function.boundToType()) solAssert( function.kind() == FunctionType::Kind::DelegateCall || function.kind() == FunctionType::Kind::Internal || @@ -708,7 +708,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) bool shortcutTaken = false; if (auto identifier = dynamic_cast(&_functionCall.expression())) { - solAssert(!function.bound(), ""); + solAssert(!function.boundToType(), ""); if (auto functionDef = dynamic_cast(identifier->annotation().referencedDeclaration)) { // 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()); - if (function.bound()) + if (function.boundToType()) { // stack: arg2, ..., argn, label, arg1 unsigned depth = parameterSize + 1; @@ -977,7 +977,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) argumentType && functionType->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: { - solAssert(function.bound(), ""); + solAssert(function.boundToType(), ""); _functionCall.expression().accept(*this); if (function.parameterTypes().size() == 0) @@ -1166,7 +1166,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::ArrayPop: { _functionCall.expression().accept(*this); - solAssert(function.bound(), ""); + solAssert(function.boundToType(), ""); solAssert(function.parameterTypes().empty(), ""); ArrayType const* arrayType = dynamic_cast(function.selfType()); solAssert(arrayType && arrayType->dataStoredIn(DataLocation::Storage), ""); @@ -1550,7 +1550,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) // Check whether the member is a bound function. ASTString const& member = _memberAccess.memberName(); if (auto funType = dynamic_cast(_memberAccess.annotation().type)) - if (funType->bound()) + if (funType->boundToType()) { acceptAndConvert(_memberAccess.expression(), *funType->selfType(), true); if (funType->kind() == FunctionType::Kind::Internal) @@ -2641,14 +2641,14 @@ void ExpressionCompiler::appendExternalFunctionCall( // function identifier [unless bare] // 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 contractStackPos = m_context.currentToBaseStackOffset(1 + gasValueSize + selfSize + (_functionType.isBareCall() ? 0 : 1)); unsigned gasStackPos = m_context.currentToBaseStackOffset(gasValueSize); unsigned valueStackPos = m_context.currentToBaseStackOffset(1); // move self object to top - if (_functionType.bound()) + if (_functionType.boundToType()) utils().moveToStackTop(gasValueSize, _functionType.selfType()->sizeOnStack()); auto funKind = _functionType.kind(); @@ -2676,7 +2676,7 @@ void ExpressionCompiler::appendExternalFunctionCall( // Evaluate arguments. TypePointers argumentTypes; TypePointers parameterTypes = _functionType.parameterTypes(); - if (_functionType.bound()) + if (_functionType.boundToType()) { argumentTypes.push_back(_functionType.selfType()); parameterTypes.insert(parameterTypes.begin(), _functionType.selfType()); diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 2708d319d..8d6caa2c2 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -321,7 +321,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc _sourceType.isImplicitlyConvertibleTo(*m_dataType), "function item stored but target is not implicitly convertible to source" ); - solAssert(!fun->bound(), ""); + solAssert(!fun->boundToType(), ""); if (fun->kind() == FunctionType::Kind::External) { solAssert(fun->sizeOnStack() == 2, ""); diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index a373a922d..94673959c 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1039,7 +1039,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) solAssert(!functionType->takesArbitraryParameters()); vector args; - if (functionType->bound()) + if (functionType->boundToType()) args += IRVariable(_functionCall.expression()).part("self").stackSlots(); for (size_t i = 0; i < arguments.size(); ++i) @@ -1110,7 +1110,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) solAssert( IRVariable(arg).type() == *functionType && functionType->kind() == FunctionType::Kind::External && - !functionType->bound(), + !functionType->boundToType(), "" ); define(indexedArgs.emplace_back(m_context.newYulVariable(), *TypeProvider::fixedBytes(32))) << @@ -1439,7 +1439,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) } case FunctionType::Kind::ArrayPop: { - solAssert(functionType->bound()); + solAssert(functionType->boundToType()); solAssert(functionType->parameterTypes().empty()); ArrayType const* arrayType = dynamic_cast(functionType->selfType()); solAssert(arrayType); @@ -1643,7 +1643,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) solAssert(!_functionCall.annotation().tryCall); solAssert(!functionType->valueSet()); solAssert(!functionType->gasSet()); - solAssert(!functionType->bound()); + solAssert(!functionType->boundToType()); static map> precompiles = { {FunctionType::Kind::ECRecover, std::make_tuple(1, 0)}, @@ -1709,7 +1709,7 @@ void IRGeneratorForStatements::endVisit(FunctionCallOptions const& _options) setLocation(_options); FunctionType const& previousType = dynamic_cast(*_options.expression().annotation().type); - solUnimplementedAssert(!previousType.bound()); + solUnimplementedAssert(!previousType.boundToType()); // Copy over existing values. for (auto const& item: previousType.stackItems()) @@ -1754,7 +1754,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) auto memberFunctionType = dynamic_cast(_memberAccess.annotation().type); Type::Category objectCategory = _memberAccess.expression().annotation().type->category(); - if (memberFunctionType && memberFunctionType->bound()) + if (memberFunctionType && memberFunctionType->boundToType()) { define(IRVariable(_memberAccess).part("self"), _memberAccess.expression()); solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static); @@ -2592,7 +2592,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall( TypePointers parameterTypes = funType.parameterTypes(); TypePointers argumentTypes; vector argumentStrings; - if (funType.bound()) + if (funType.boundToType()) { parameterTypes.insert(parameterTypes.begin(), funType.selfType()); argumentTypes.emplace_back(funType.selfType()); @@ -2741,7 +2741,7 @@ void IRGeneratorForStatements::appendBareCall( { FunctionType const& funType = dynamic_cast(type(_functionCall.expression())); solAssert( - !funType.bound() && + !funType.boundToType() && !funType.takesArbitraryParameters() && _arguments.size() == 1 && funType.parameterTypes().size() == 1, "" diff --git a/libsolidity/formal/SMTEncoder.cpp b/libsolidity/formal/SMTEncoder.cpp index e779fbeb8..bf5e69ec7 100644 --- a/libsolidity/formal/SMTEncoder.cpp +++ b/libsolidity/formal/SMTEncoder.cpp @@ -3118,7 +3118,7 @@ vector SMTEncoder::symbolicArguments(FunctionCall const& _f vector> arguments = _funCall.sortedArguments(); auto functionParams = funDef->parameters(); unsigned firstParam = 0; - if (funType->bound()) + if (funType->boundToType()) { calledExpr = innermostTuple(*calledExpr); auto const& boundFunction = dynamic_cast(calledExpr);