diff --git a/liblangutil/Token.h b/liblangutil/Token.h index abcdf6d5d..741413a0b 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -307,8 +307,8 @@ namespace TokenTraits constexpr bool isElementaryTypeName(Token tok) { return (Token::Int <= tok && tok < Token::TypesEnd) || - tok == Token::Word || tok == Token::Void || tok == Token::Integer || - tok == Token::Pair || tok == Token::Unit || tok == Token::Fun; + tok == Token::Word || tok == Token::Void || tok == Token::Integer || + tok == Token::Pair || tok == Token::Unit || tok == Token::Fun; } constexpr bool isAssignmentOp(Token tok) { return Token::Assign <= tok && tok <= Token::AssignMod; } constexpr bool isBinaryOp(Token op) { return Token::Comma <= op && op <= Token::Exp; } @@ -344,7 +344,7 @@ namespace TokenTraits constexpr bool isBuiltinTypeClassName(Token tok) { return tok == Token::Integer || (isBinaryOp(tok) && tok != Token::Comma) || - isCompareOp(tok) || isUnaryOp(tok) || (isAssignmentOp(tok) && tok != Token::Assign); + isCompareOp(tok) || isUnaryOp(tok) || (isAssignmentOp(tok) && tok != Token::Assign); } constexpr bool isExperimentalSolidityKeyword(Token tok) { diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 3db08ed14..da2206f45 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -304,7 +304,7 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier) } std::string name = splitName.front(); auto declarations = m_resolver.nameFromCurrentScope(name); - switch(declarations.size()) + switch (declarations.size()) { case 0: if (splitName.size() > 1) diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index faaae7c87..031068a76 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -2511,11 +2511,11 @@ public: ASTPointer _class, std::vector> _subNodes ): - ASTNode(_id, _location), - m_typeConstructor(std::move(_typeConstructor)), - m_argumentSorts(std::move(_argumentSorts)), - m_class(std::move(_class)), - m_subNodes(std::move(_subNodes)) + ASTNode(_id, _location), + m_typeConstructor(std::move(_typeConstructor)), + m_argumentSorts(std::move(_argumentSorts)), + m_class(std::move(_class)), + m_subNodes(std::move(_subNodes)) {} void accept(ASTVisitor& _visitor) override; diff --git a/libsolidity/ast/AST_accept.h b/libsolidity/ast/AST_accept.h index eaf179e73..d0b5ad281 100644 --- a/libsolidity/ast/AST_accept.h +++ b/libsolidity/ast/AST_accept.h @@ -1063,7 +1063,7 @@ void TypeClassInstantiation::accept(ASTVisitor& _visitor) if (_visitor.visit(*this)) { m_typeConstructor->accept(_visitor); - if(m_argumentSorts) + if (m_argumentSorts) m_argumentSorts->accept(_visitor); m_class->accept(_visitor); listAccept(m_subNodes, _visitor); @@ -1076,7 +1076,7 @@ void TypeClassInstantiation::accept(ASTConstVisitor& _visitor) const if (_visitor.visit(*this)) { m_typeConstructor->accept(_visitor); - if(m_argumentSorts) + if (m_argumentSorts) m_argumentSorts->accept(_visitor); m_class->accept(_visitor); listAccept(m_subNodes, _visitor); diff --git a/libsolidity/experimental/analysis/Analysis.cpp b/libsolidity/experimental/analysis/Analysis.cpp index 7e1cf94b6..56d4d36f9 100644 --- a/libsolidity/experimental/analysis/Analysis.cpp +++ b/libsolidity/experimental/analysis/Analysis.cpp @@ -127,20 +127,20 @@ bool Analysis::check(std::vector> const& _sour return ([&](auto&& _step) { for (auto source: _sourceUnits) if (!_step.analyze(*source)) - return false; + return false; return true; }(std::tuple_element_t{*this}) && ...); }, makeIndexTuple(std::make_index_sequence>{})); /* - { + { SyntaxRestrictor syntaxRestrictor{*this}; for (auto source: _sourceUnits) if (!syntaxRestrictor.analyze(*source)) return false; } - { + { TypeRegistration typeRegistration{*this}; for (auto source: _sourceUnits) if (!typeRegistration.analyze(*source)) diff --git a/libsolidity/experimental/analysis/TypeInference.cpp b/libsolidity/experimental/analysis/TypeInference.cpp index 56dec5dc6..36d105157 100644 --- a/libsolidity/experimental/analysis/TypeInference.cpp +++ b/libsolidity/experimental/analysis/TypeInference.cpp @@ -216,7 +216,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition) if (!functionTypes.emplace(functionDefinition->name(), functionType).second) m_errorReporter.fatalTypeError(0000_error, functionDefinition->location(), "Function in type class declared multiple times."); auto typeVars = TypeEnvironmentHelpers{*m_env}.typeVars(functionType); - if(typeVars.size() != 1) + if (typeVars.size() != 1) m_errorReporter.fatalTypeError(0000_error, functionDefinition->location(), "Function in type class may only depend on the type class variable."); unify(typeVars.front(), typeVar, functionDefinition->location()); typeMembers[functionDefinition->name()] = TypeMember{functionType}; @@ -499,7 +499,7 @@ void TypeInference::endVisit(Assignment const& _assignment) experimental::Type TypeInference::handleIdentifierByReferencedDeclaration(langutil::SourceLocation _location, Declaration const& _declaration) { - switch(m_expressionContext) + switch (m_expressionContext) { case ExpressionContext::Term: { @@ -601,7 +601,7 @@ bool TypeInference::visit(Identifier const& _identifier) return false; } - switch(m_expressionContext) + switch (m_expressionContext) { case ExpressionContext::Term: // TODO: error handling @@ -791,9 +791,7 @@ experimental::Type TypeInference::memberType(Type _type, std::string _memberName { auto constructor = std::get<0>(helper.destTypeConstant(type)); if (auto* typeMember = util::valueOrNullptr(annotation().members.at(constructor), _memberName)) - { return polymorphicInstance(typeMember->type); - } else { m_errorReporter.typeError(0000_error, _location, fmt::format("Member {} not found in type {}.", _memberName, TypeEnvironmentHelpers{*m_env}.typeToString(_type))); @@ -809,7 +807,7 @@ experimental::Type TypeInference::memberType(Type _type, std::string _memberName void TypeInference::endVisit(MemberAccess const& _memberAccess) { - auto &memberAccessAnnotation = annotation(_memberAccess); + auto& memberAccessAnnotation = annotation(_memberAccess); solAssert(!memberAccessAnnotation.type); Type expressionType = getType(_memberAccess.expression()); memberAccessAnnotation.type = memberType(expressionType, _memberAccess.memberName(), _memberAccess.location()); @@ -820,22 +818,22 @@ bool TypeInference::visit(TypeDefinition const& _typeDefinition) TypeSystemHelpers helper{m_typeSystem}; auto& typeDefinitionAnnotation = annotation(_typeDefinition); if (typeDefinitionAnnotation.type) - return false; + return false; if (_typeDefinition.arguments()) - _typeDefinition.arguments()->accept(*this); + _typeDefinition.arguments()->accept(*this); std::optional underlyingType; if (_typeDefinition.typeExpression()) { - ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type}; - _typeDefinition.typeExpression()->accept(*this); - underlyingType = annotation(*_typeDefinition.typeExpression()).type; + ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type}; + _typeDefinition.typeExpression()->accept(*this); + underlyingType = annotation(*_typeDefinition.typeExpression()).type; } std::vector arguments; if (_typeDefinition.arguments()) - for (size_t i = 0; i < _typeDefinition.arguments()->parameters().size(); ++i) + for (size_t i = 0; i < _typeDefinition.arguments()->parameters().size(); ++i) arguments.emplace_back(m_typeSystem.freshTypeVariable({})); Type definedType = type(&_typeDefinition, arguments); @@ -865,43 +863,43 @@ void TypeInference::endVisit(FunctionCall const& _functionCall) TypeSystemHelpers helper{m_typeSystem}; std::vector argTypes; - for(auto arg: _functionCall.arguments()) + for (auto arg: _functionCall.arguments()) { - switch(m_expressionContext) - { - case ExpressionContext::Term: - case ExpressionContext::Type: + switch (m_expressionContext) + { + case ExpressionContext::Term: + case ExpressionContext::Type: argTypes.emplace_back(getType(*arg)); break; - case ExpressionContext::Sort: + case ExpressionContext::Sort: m_errorReporter.typeError(0000_error, _functionCall.location(), "Function call in sort context."); functionCallAnnotation.type = m_typeSystem.freshTypeVariable({}); break; - } + } } - switch(m_expressionContext) + switch (m_expressionContext) { case ExpressionContext::Term: { - Type argTuple = helper.tupleType(argTypes); - Type resultType = m_typeSystem.freshTypeVariable({}); - Type genericFunctionType = helper.functionType(argTuple, resultType); - unify(functionType, genericFunctionType, _functionCall.location()); - functionCallAnnotation.type = resultType; - break; + Type argTuple = helper.tupleType(argTypes); + Type resultType = m_typeSystem.freshTypeVariable({}); + Type genericFunctionType = helper.functionType(argTuple, resultType); + unify(functionType, genericFunctionType, _functionCall.location()); + functionCallAnnotation.type = resultType; + break; } case ExpressionContext::Type: { - Type argTuple = helper.tupleType(argTypes); - Type resultType = m_typeSystem.freshTypeVariable({}); - Type genericFunctionType = helper.typeFunctionType(argTuple, resultType); - unify(functionType, genericFunctionType, _functionCall.location()); - functionCallAnnotation.type = resultType; - break; + Type argTuple = helper.tupleType(argTypes); + Type resultType = m_typeSystem.freshTypeVariable({}); + Type genericFunctionType = helper.typeFunctionType(argTuple, resultType); + unify(functionType, genericFunctionType, _functionCall.location()); + functionCallAnnotation.type = resultType; + break; } case ExpressionContext::Sort: - solAssert(false); + solAssert(false); } } @@ -914,10 +912,10 @@ std::optional parseRational(std::string const& _value) rational value; try { - auto radixPoint = find(_value.begin(), _value.end(), '.'); + auto radixPoint = find(_value.begin(), _value.end(), '.'); - if (radixPoint != _value.end()) - { + if (radixPoint != _value.end()) + { if ( !all_of(radixPoint + 1, _value.end(), util::isDigit) || !all_of(_value.begin(), radixPoint, util::isDigit) @@ -941,14 +939,14 @@ std::optional parseRational(std::string const& _value) ); numerator = bigint(std::string(_value.begin(), radixPoint)); value = numerator + denominator; - } - else + } + else value = bigint(_value); - return value; + return value; } catch (...) { - return std::nullopt; + return std::nullopt; } } @@ -964,19 +962,19 @@ std::optional rationalValue(Literal const& _literal) rational value; try { - ASTString valueString = _literal.valueWithoutUnderscores(); + ASTString valueString = _literal.valueWithoutUnderscores(); - auto expPoint = find(valueString.begin(), valueString.end(), 'e'); - if (expPoint == valueString.end()) + auto expPoint = find(valueString.begin(), valueString.end(), 'e'); + if (expPoint == valueString.end()) expPoint = find(valueString.begin(), valueString.end(), 'E'); - if (boost::starts_with(valueString, "0x")) - { + if (boost::starts_with(valueString, "0x")) + { // process as hex value = bigint(valueString); - } - else if (expPoint != valueString.end()) - { + } + else if (expPoint != valueString.end()) + { // Parse mantissa and exponent. Checks numeric limit. std::optional mantissa = parseRational(std::string(valueString.begin(), expPoint)); @@ -1013,47 +1011,47 @@ std::optional rationalValue(Literal const& _literal) expAbs ); } - } - else - { + } + else + { // parse as rational number std::optional tmp = parseRational(valueString); if (!tmp) return std::nullopt; value = *tmp; - } + } } catch (...) { - return std::nullopt; + return std::nullopt; } switch (_literal.subDenomination()) { case Literal::SubDenomination::None: case Literal::SubDenomination::Wei: case Literal::SubDenomination::Second: - break; + break; case Literal::SubDenomination::Gwei: - value *= bigint("1000000000"); - break; + value *= bigint("1000000000"); + break; case Literal::SubDenomination::Ether: - value *= bigint("1000000000000000000"); - break; + value *= bigint("1000000000000000000"); + break; case Literal::SubDenomination::Minute: - value *= bigint("60"); - break; + value *= bigint("60"); + break; case Literal::SubDenomination::Hour: - value *= bigint("3600"); - break; + value *= bigint("3600"); + break; case Literal::SubDenomination::Day: - value *= bigint("86400"); - break; + value *= bigint("86400"); + break; case Literal::SubDenomination::Week: - value *= bigint("604800"); - break; + value *= bigint("604800"); + break; case Literal::SubDenomination::Year: - value *= bigint("31536000"); - break; + value *= bigint("31536000"); + break; } return value; @@ -1065,19 +1063,19 @@ bool TypeInference::visit(Literal const& _literal) auto& literalAnnotation = annotation(_literal); if (_literal.token() != Token::Number) { - m_errorReporter.typeError(0000_error, _literal.location(), "Only number literals are supported."); - return false; + m_errorReporter.typeError(0000_error, _literal.location(), "Only number literals are supported."); + return false; } std::optional value = rationalValue(_literal); if (!value) { - m_errorReporter.typeError(0000_error, _literal.location(), "Invalid number literals."); - return false; + m_errorReporter.typeError(0000_error, _literal.location(), "Invalid number literals."); + return false; } if (value->denominator() != 1) { - m_errorReporter.typeError(0000_error, _literal.location(), "Only integers are supported."); - return false; + m_errorReporter.typeError(0000_error, _literal.location(), "Only integers are supported."); + return false; } literalAnnotation.type = m_typeSystem.freshTypeVariable(Sort{{annotation().builtinClasses.at(BuiltinClass::Integer)}}); return false; @@ -1091,7 +1089,7 @@ TypeRegistration::TypeClassInstantiations const& typeClassInstantiations(Analysi { auto const* typeClassDeclaration = _analysis.typeSystem().typeClassDeclaration(_class); if (typeClassDeclaration) - return _analysis.annotation(*typeClassDeclaration).instantiations; + return _analysis.annotation(*typeClassDeclaration).instantiations; // TODO: better mechanism than fetching by name. auto& annotation = _analysis.annotation(); auto& inferenceAnnotation = _analysis.annotation(); diff --git a/libsolidity/experimental/analysis/TypeRegistration.cpp b/libsolidity/experimental/analysis/TypeRegistration.cpp index 424dc78ff..577df25a5 100644 --- a/libsolidity/experimental/analysis/TypeRegistration.cpp +++ b/libsolidity/experimental/analysis/TypeRegistration.cpp @@ -61,7 +61,7 @@ bool TypeRegistration::visit(ElementaryTypeName const& _typeName) if (annotation(_typeName).typeConstructor) return false; annotation(_typeName).typeConstructor = [&]() -> std::optional { - switch(_typeName.typeName().token()) + switch (_typeName.typeName().token()) { case Token::Void: return m_typeSystem.constructor(PrimitiveType::Void); diff --git a/libsolidity/experimental/ast/TypeSystem.cpp b/libsolidity/experimental/ast/TypeSystem.cpp index 3ed04fd1f..e6e65a110 100644 --- a/libsolidity/experimental/ast/TypeSystem.cpp +++ b/libsolidity/experimental/ast/TypeSystem.cpp @@ -72,12 +72,12 @@ std::vector TypeEnvironment::unify(Type _a, failures += instantiate(_var, _a); }, [&](TypeConstant _left, TypeConstant _right) { - if(_left.constructor != _right.constructor) - return unificationFailure(); - if (_left.arguments.size() != _right.arguments.size()) - return unificationFailure(); - for (auto&& [left, right]: ranges::zip_view(_left.arguments, _right.arguments)) - failures += unify(left, right); + if (_left.constructor != _right.constructor) + return unificationFailure(); + if (_left.arguments.size() != _right.arguments.size()) + return unificationFailure(); + for (auto&& [left, right]: ranges::zip_view(_left.arguments, _right.arguments)) + failures += unify(left, right); }, [&](auto, auto) { unificationFailure(); @@ -98,14 +98,14 @@ bool TypeEnvironment::typeEquals(Type _lhs, Type _rhs) const return false; }, [&](TypeConstant _left, TypeConstant _right) { - if(_left.constructor != _right.constructor) - return false; - if (_left.arguments.size() != _right.arguments.size()) - return false; - for (auto&& [left, right]: ranges::zip_view(_left.arguments, _right.arguments)) - if (!typeEquals(left, right)) - return false; - return true; + if (_left.constructor != _right.constructor) + return false; + if (_left.arguments.size() != _right.arguments.size()) + return false; + for (auto&& [left, right]: ranges::zip_view(_left.arguments, _right.arguments)) + if (!typeEquals(left, right)) + return false; + return true; }, [&](auto, auto) { return false; @@ -133,7 +133,7 @@ TypeSystem::TypeSystem() m_primitiveTypeClasses.emplace(PrimitiveClass::Type, declarePrimitiveClass("type")); - for (auto [type, name, arity]: std::initializer_list> { + for (auto [type, name, arity]: std::initializer_list>{ {PrimitiveType::TypeFunction, "tfun", 2}, {PrimitiveType::Function, "fun", 2}, {PrimitiveType::Function, "itself", 1}, @@ -184,7 +184,7 @@ std::vector TypeEnvironment::instantiate(Ty experimental::Type TypeEnvironment::resolve(Type _type) const { Type result = _type; - while(auto const* var = std::get_if(&result)) + while (auto const* var = std::get_if(&result)) if (Type const* resolvedType = util::valueOrNullptr(m_typeVariables, var->index())) result = *resolvedType; else diff --git a/libsolidity/experimental/ast/TypeSystemHelper.cpp b/libsolidity/experimental/ast/TypeSystemHelper.cpp index 2d86ea4b5..e819b84ba 100644 --- a/libsolidity/experimental/ast/TypeSystemHelper.cpp +++ b/libsolidity/experimental/ast/TypeSystemHelper.cpp @@ -54,7 +54,7 @@ using namespace solidity::frontend::experimental; std::optional experimental::typeConstructorFromToken(Analysis const& _analysis, langutil::Token _token) { TypeSystem const& typeSystem = _analysis.typeSystem(); - switch(_token) + switch (_token) { case Token::Void: return typeSystem.builtinConstructor(BuiltinType::Void); @@ -142,7 +142,7 @@ std::vector TypeSystemHelpers::destTupleType(Type _tupleType std::vector result; result.emplace_back(arguments.front()); Type tail = arguments.back(); - while(true) + while (true) { if (!isTypeConstant(tail)) break; @@ -184,7 +184,7 @@ std::vector TypeSystemHelpers::destSumType(Type _tupleType) std::vector result; result.emplace_back(arguments.front()); Type tail = arguments.back(); - while(true) + while (true) { if (!isTypeConstant(tail)) break; @@ -338,22 +338,22 @@ std::string TypeEnvironmentHelpers::typeToString(Type const& _type) const { std::map)>> formatters{ {env.typeSystem().constructor(PrimitiveType::Function), [&](auto const& _args) { - solAssert(_args.size() == 2); - return fmt::format("{} -> {}", typeToString(_args.front()), typeToString(_args.back())); - }}, + solAssert(_args.size() == 2); + return fmt::format("{} -> {}", typeToString(_args.front()), typeToString(_args.back())); + }}, {env.typeSystem().constructor(PrimitiveType::Unit), [&](auto const& _args) { - solAssert(_args.size() == 0); - return "()"; - }}, + solAssert(_args.size() == 0); + return "()"; + }}, {env.typeSystem().constructor(PrimitiveType::Pair), [&](auto const& _arguments) { - auto tupleTypes = TypeSystemHelpers{env.typeSystem()}.destTupleType(_arguments.back()); - std::string result = "("; - result += typeToString(_arguments.front()); - for (auto type: tupleTypes) - result += ", " + typeToString(type); - result += ")"; - return result; - }}, + auto tupleTypes = TypeSystemHelpers{env.typeSystem()}.destTupleType(_arguments.back()); + std::string result = "("; + result += typeToString(_arguments.front()); + for (auto type: tupleTypes) + result += ", " + typeToString(type); + result += ")"; + return result; + }}, }; return std::visit(util::GenericVisitor{ [&](TypeConstant const& _type) { diff --git a/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp b/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp index 6add66c42..1da96f147 100644 --- a/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp +++ b/libsolidity/experimental/codegen/IRGeneratorForStatements.cpp @@ -46,7 +46,8 @@ std::string IRGeneratorForStatements::generate(ASTNode const& _node) } -namespace { +namespace +{ struct CopyTranslate: public yul::ASTCopier { @@ -300,7 +301,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) auto declaration = m_expressionDeclaration.at(&_functionCall.expression()); if (auto builtin = std::get_if(&declaration)) { - switch(*builtin) + switch (*builtin) { case Builtins::FromBool: case Builtins::Identity: diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 2d080a8ba..36a26ba40 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -486,7 +486,7 @@ bool CompilerStack::analyze() for (Source const* source: m_sourceOrder) if (source->ast && !docStringTagParser.parseDocStrings(*source->ast)) noErrors = false; - } + } // Requires DocStringTagParser for (Source const* source: m_sourceOrder) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 947329aff..700141508 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -2076,7 +2076,7 @@ int Parser::tokenPrecedence(Token _token) const { if (m_experimentalSolidityEnabledInCurrentSourceUnit) { - switch(_token) + switch (_token) { case Token::Colon: return 1000;