From: Richard Smith Date: Wed, 12 Nov 2014 01:24:00 +0000 (+0000) Subject: Fix this code to follow the coding style regarding anonymous namespaces and X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=affaed529a7098a02845b9373b4fba58619957b1;p=clang Fix this code to follow the coding style regarding anonymous namespaces and static functions. Make a bunch of file-local functions static. Remove one unused static function revealed by this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221745 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h index b04b996b7f..dd5f7677ba 100644 --- a/include/clang/Sema/Overload.h +++ b/include/clang/Sema/Overload.h @@ -86,21 +86,6 @@ namespace clang { ICK_Num_Conversion_Kinds ///< The number of conversion kinds }; - /// ImplicitConversionCategory - The category of an implicit - /// conversion kind. The enumerator values match with Table 9 of - /// (C++ 13.3.3.1.1) and are listed such that better conversion - /// categories have smaller values. - enum ImplicitConversionCategory { - ICC_Identity = 0, ///< Identity - ICC_Lvalue_Transformation, ///< Lvalue transformation - ICC_Qualification_Adjustment, ///< Qualification adjustment - ICC_Promotion, ///< Promotion - ICC_Conversion ///< Conversion - }; - - ImplicitConversionCategory - GetConversionCategory(ImplicitConversionKind Kind); - /// ImplicitConversionRank - The rank of an implicit conversion /// kind. The enumerator values match with Table 9 of (C++ /// 13.3.3.1.1) and are listed such that better conversion ranks diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 40f446bb7b..e3355e7ccc 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -35,7 +35,7 @@ #include #include -namespace clang { +using namespace clang; using namespace sema; /// A convenience routine for creating a decayed reference to a function. @@ -102,43 +102,9 @@ CompareDerivedToBaseConversions(Sema &S, const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2); - - -/// GetConversionCategory - Retrieve the implicit conversion -/// category corresponding to the given implicit conversion kind. -ImplicitConversionCategory -GetConversionCategory(ImplicitConversionKind Kind) { - static const ImplicitConversionCategory - Category[(int)ICK_Num_Conversion_Kinds] = { - ICC_Identity, - ICC_Lvalue_Transformation, - ICC_Lvalue_Transformation, - ICC_Lvalue_Transformation, - ICC_Identity, - ICC_Qualification_Adjustment, - ICC_Promotion, - ICC_Promotion, - ICC_Promotion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion, - ICC_Conversion - }; - return Category[(int)Kind]; -} - /// GetConversionRank - Retrieve the implicit conversion rank /// corresponding to the given implicit conversion kind. -ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind) { +ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) { static const ImplicitConversionRank Rank[(int)ICK_Num_Conversion_Kinds] = { ICR_Exact_Match, @@ -171,7 +137,7 @@ ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind) { /// GetImplicitConversionName - Return the name of this kind of /// implicit conversion. -const char* GetImplicitConversionName(ImplicitConversionKind Kind) { +static const char* GetImplicitConversionName(ImplicitConversionKind Kind) { static const char* const Name[(int)ICK_Num_Conversion_Kinds] = { "No conversion", "Lvalue-to-rvalue", @@ -568,9 +534,10 @@ namespace { /// \brief Convert from Sema's representation of template deduction information /// to the form used in overload-candidate information. -DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, - Sema::TemplateDeductionResult TDK, - TemplateDeductionInfo &Info) { +DeductionFailureInfo +clang::MakeDeductionFailureInfo(ASTContext &Context, + Sema::TemplateDeductionResult TDK, + TemplateDeductionInfo &Info) { DeductionFailureInfo Result; Result.Result = static_cast(TDK); Result.HasDiagnostic = false; @@ -1268,11 +1235,11 @@ Sema::TryImplicitConversion(Expr *From, QualType ToType, bool InOverloadResolution, bool CStyle, bool AllowObjCWritebackConversion) { - return clang::TryImplicitConversion(*this, From, ToType, - SuppressUserConversions, AllowExplicit, - InOverloadResolution, CStyle, - AllowObjCWritebackConversion, - /*AllowObjCConversionOnExplicit=*/false); + return ::TryImplicitConversion(*this, From, ToType, + SuppressUserConversions, AllowExplicit, + InOverloadResolution, CStyle, + AllowObjCWritebackConversion, + /*AllowObjCConversionOnExplicit=*/false); } /// PerformImplicitConversion - Perform an implicit conversion of the @@ -1301,13 +1268,13 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, if (getLangOpts().ObjC1) CheckObjCBridgeRelatedConversions(From->getLocStart(), ToType, From->getType(), From); - ICS = clang::TryImplicitConversion(*this, From, ToType, - /*SuppressUserConversions=*/false, - AllowExplicit, - /*InOverloadResolution=*/false, - /*CStyle=*/false, - AllowObjCWritebackConversion, - /*AllowObjCConversionOnExplicit=*/false); + ICS = ::TryImplicitConversion(*this, From, ToType, + /*SuppressUserConversions=*/false, + AllowExplicit, + /*InOverloadResolution=*/false, + /*CStyle=*/false, + AllowObjCWritebackConversion, + /*AllowObjCConversionOnExplicit=*/false); return PerformImplicitConversion(From, ToType, ICS, Action); } @@ -3657,7 +3624,7 @@ CompareStandardConversionSequences(Sema &S, /// CompareQualificationConversions - Compares two standard conversion /// sequences to determine whether they can be ranked based on their /// qualification conversions (C++ 13.3.3.2p3 bullet 3). -ImplicitConversionSequence::CompareKind +static ImplicitConversionSequence::CompareKind CompareQualificationConversions(Sema &S, const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2) { @@ -3770,7 +3737,7 @@ CompareQualificationConversions(Sema &S, /// various kinds of derived-to-base conversions (C++ /// [over.ics.rank]p4b3). As part of these checks, we also look at /// conversions between Objective-C interface types. -ImplicitConversionSequence::CompareKind +static ImplicitConversionSequence::CompareKind CompareDerivedToBaseConversions(Sema &S, const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2) { @@ -8283,12 +8250,10 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, /// isBetterOverloadCandidate - Determines whether the first overload /// candidate is a better candidate than the second (C++ 13.3.3p1). -bool -isBetterOverloadCandidate(Sema &S, - const OverloadCandidate &Cand1, - const OverloadCandidate &Cand2, - SourceLocation Loc, - bool UserDefinedConversion) { +bool clang::isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, + const OverloadCandidate &Cand2, + SourceLocation Loc, + bool UserDefinedConversion) { // Define viable functions to be better candidates than non-viable // functions. if (!Cand2.Viable) @@ -8620,9 +8585,8 @@ void ImplicitConversionSequence::DiagnoseAmbiguousConversion( S.Diag(SourceLocation(), diag::note_ovl_too_many_candidates) << int(E - I); } -namespace { - -void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, unsigned I) { +static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, + unsigned I) { const ImplicitConversionSequence &Conv = Cand->Conversions[I]; assert(Conv.isBad()); assert(Cand->Function && "for now, candidate must be a function"); @@ -8840,8 +8804,8 @@ void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, unsigned I) { /// Additional arity mismatch diagnosis specific to a function overload /// candidates. This is not covered by the more general DiagnoseArityMismatch() /// over a candidate in any candidate set. -bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand, - unsigned NumArgs) { +static bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand, + unsigned NumArgs) { FunctionDecl *Fn = Cand->Function; unsigned MinParams = Fn->getMinRequiredArguments(); @@ -8868,7 +8832,7 @@ bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand, } /// General arity mismatch diagnosis over a candidate in a candidate set. -void DiagnoseArityMismatch(Sema &S, Decl *D, unsigned NumFormalArgs) { +static void DiagnoseArityMismatch(Sema &S, Decl *D, unsigned NumFormalArgs) { assert(isa(D) && "The templated declaration should at least be a function" " when diagnosing bad template argument deduction due to too many" @@ -8912,13 +8876,13 @@ void DiagnoseArityMismatch(Sema &S, Decl *D, unsigned NumFormalArgs) { } /// Arity mismatch diagnosis specific to a function overload candidate. -void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand, - unsigned NumFormalArgs) { +static void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand, + unsigned NumFormalArgs) { if (!CheckArityMismatch(S, Cand, NumFormalArgs)) DiagnoseArityMismatch(S, Cand->Function, NumFormalArgs); } -TemplateDecl *getDescribedTemplate(Decl *Templated) { +static TemplateDecl *getDescribedTemplate(Decl *Templated) { if (FunctionDecl *FD = dyn_cast(Templated)) return FD->getDescribedFunctionTemplate(); else if (CXXRecordDecl *RD = dyn_cast(Templated)) @@ -8929,9 +8893,9 @@ TemplateDecl *getDescribedTemplate(Decl *Templated) { } /// Diagnose a failed template-argument deduction. -void DiagnoseBadDeduction(Sema &S, Decl *Templated, - DeductionFailureInfo &DeductionFailure, - unsigned NumArgs) { +static void DiagnoseBadDeduction(Sema &S, Decl *Templated, + DeductionFailureInfo &DeductionFailure, + unsigned NumArgs) { TemplateParameter Param = DeductionFailure.getTemplateParameter(); NamedDecl *ParamD; (ParamD = Param.dyn_cast()) || @@ -9118,7 +9082,8 @@ void DiagnoseBadDeduction(Sema &S, Decl *Templated, } /// Diagnose a failed template-argument deduction, for function calls. -void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand, unsigned NumArgs) { +static void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand, + unsigned NumArgs) { unsigned TDK = Cand->DeductionFailure.Result; if (TDK == Sema::TDK_TooFewArguments || TDK == Sema::TDK_TooManyArguments) { if (CheckArityMismatch(S, Cand, NumArgs)) @@ -9129,7 +9094,7 @@ void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand, unsigned NumArgs) { } /// CUDA: diagnose an invalid call across targets. -void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) { +static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) { FunctionDecl *Caller = cast(S.CurContext); FunctionDecl *Callee = Cand->Function; @@ -9183,7 +9148,7 @@ void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) { } } -void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) { +static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) { FunctionDecl *Callee = Cand->Function; EnableIfAttr *Attr = static_cast(Cand->DeductionFailure.Data); @@ -9205,8 +9170,8 @@ void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) { /// It would be great to be able to express per-candidate problems /// more richly for those diagnostic clients that cared, but we'd /// still have to be just as careful with the default diagnostics. -void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, - unsigned NumArgs) { +static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, + unsigned NumArgs) { FunctionDecl *Fn = Cand->Function; // Note deleted candidates, but only if they're viable. @@ -9261,7 +9226,7 @@ void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, } } -void NoteSurrogateCandidate(Sema &S, OverloadCandidate *Cand) { +static void NoteSurrogateCandidate(Sema &S, OverloadCandidate *Cand) { // Desugar the type of the surrogate down to a function type, // retaining as many typedefs as possible while still showing // the function type (and, therefore, its parameter types). @@ -9294,10 +9259,9 @@ void NoteSurrogateCandidate(Sema &S, OverloadCandidate *Cand) { MaybeEmitInheritedConstructorNote(S, Cand->Surrogate); } -void NoteBuiltinOperatorCandidate(Sema &S, - StringRef Opc, - SourceLocation OpLoc, - OverloadCandidate *Cand) { +static void NoteBuiltinOperatorCandidate(Sema &S, StringRef Opc, + SourceLocation OpLoc, + OverloadCandidate *Cand) { assert(Cand->NumConversions <= 2 && "builtin operator is not binary"); std::string TypeStr("operator"); TypeStr += Opc; @@ -9314,8 +9278,8 @@ void NoteBuiltinOperatorCandidate(Sema &S, } } -void NoteAmbiguousUserConversions(Sema &S, SourceLocation OpLoc, - OverloadCandidate *Cand) { +static void NoteAmbiguousUserConversions(Sema &S, SourceLocation OpLoc, + OverloadCandidate *Cand) { unsigned NoOperands = Cand->NumConversions; for (unsigned ArgIdx = 0; ArgIdx < NoOperands; ++ArgIdx) { const ImplicitConversionSequence &ICS = Cand->Conversions[ArgIdx]; @@ -9367,6 +9331,7 @@ static unsigned RankDeductionFailure(const DeductionFailureInfo &DFI) { llvm_unreachable("Unhandled deduction result"); } +namespace { struct CompareOverloadCandidatesForDisplay { Sema &S; size_t NumArgs; @@ -9490,11 +9455,12 @@ struct CompareOverloadCandidatesForDisplay { return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc); } }; +} /// CompleteNonViableCandidate - Normally, overload resolution only /// computes up to the first. Produces the FixIt set if possible. -void CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand, - ArrayRef Args) { +static void CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand, + ArrayRef Args) { assert(!Cand->Viable); // Don't do anything on failures other than bad conversion. @@ -9574,8 +9540,6 @@ void CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand, } } -} // end anonymous namespace - /// PrintOverloadCandidates - When overload resolution fails, prints /// diagnostic messages containing the candidates in the candidate /// set. @@ -9652,6 +9616,7 @@ GetLocationForCandidate(const TemplateSpecCandidate *Cand) { : SourceLocation(); } +namespace { struct CompareTemplateSpecCandidatesForDisplay { Sema &S; CompareTemplateSpecCandidatesForDisplay(Sema &S) : S(S) {} @@ -9682,6 +9647,7 @@ struct CompareTemplateSpecCandidatesForDisplay { return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc); } }; +} /// Diagnose a template argument deduction failure. /// We are treating these failures as overload failures due to bad @@ -9770,10 +9736,10 @@ QualType Sema::ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType) { return Ret; } +namespace { // A helper class to help with address of function resolution // - allows us to avoid passing around all those ugly parameters -class AddressOfFunctionResolver -{ +class AddressOfFunctionResolver { Sema& S; Expr* SourceExpr; const QualType& TargetType; @@ -10099,7 +10065,8 @@ public: return &Matches[0].first; } }; - +} + /// ResolveAddressOfOverloadedFunction - Try to resolve the address of /// an overloaded function (C++ [over.over]), where @p From is an /// expression with overloaded function type and @p ToType is the type @@ -12435,5 +12402,3 @@ ExprResult Sema::FixOverloadedFunctionReference(ExprResult E, FunctionDecl *Fn) { return FixOverloadedFunctionReference(E.get(), Found, Fn); } - -} // end namespace clang