From 1169e2fa84939325bdf1d0f558c63e87404a6b57 Mon Sep 17 00:00:00 2001 From: Robert Wilhelm Date: Sun, 21 Jul 2013 15:20:44 +0000 Subject: [PATCH] Convert Sema::MatchTemplateParametersToScopeSpecifier to ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186794 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 13 +++------ lib/Sema/SemaDecl.cpp | 41 +++++++++----------------- lib/Sema/SemaDeclCXX.cpp | 11 +++---- lib/Sema/SemaTemplate.cpp | 61 ++++++++++++++++----------------------- 4 files changed, 47 insertions(+), 79 deletions(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 9543dc549b..8fa240b24c 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4972,15 +4972,10 @@ public: bool CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, TemplateParamListContext TPC); - TemplateParameterList * - MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, - SourceLocation DeclLoc, - const CXXScopeSpec &SS, - TemplateParameterList **ParamLists, - unsigned NumParamLists, - bool IsFriend, - bool &IsExplicitSpecialization, - bool &Invalid); + TemplateParameterList *MatchTemplateParametersToScopeSpecifier( + SourceLocation DeclStartLoc, SourceLocation DeclLoc, + const CXXScopeSpec &SS, ArrayRef ParamLists, + bool IsFriend, bool &IsExplicitSpecialization, bool &Invalid); DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 53303e75d3..aeae35aba9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4926,16 +4926,11 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, // determine whether we have a template or a template specialization. isExplicitSpecialization = false; bool Invalid = false; - if (TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier( - D.getDeclSpec().getLocStart(), - D.getIdentifierLoc(), - D.getCXXScopeSpec(), - TemplateParamLists.data(), - TemplateParamLists.size(), - /*never a friend*/ false, - isExplicitSpecialization, - Invalid)) { + if (TemplateParameterList *TemplateParams = + MatchTemplateParametersToScopeSpecifier( + D.getDeclSpec().getLocStart(), D.getIdentifierLoc(), + D.getCXXScopeSpec(), TemplateParamLists, + /*never a friend*/ false, isExplicitSpecialization, Invalid)) { if (TemplateParams->size() > 0) { // There is no such thing as a variable template. Diag(D.getIdentifierLoc(), diag::err_template_variable) @@ -6147,16 +6142,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Match up the template parameter lists with the scope specifier, then // determine whether we have a template or a template specialization. bool Invalid = false; - if (TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier( - D.getDeclSpec().getLocStart(), - D.getIdentifierLoc(), - D.getCXXScopeSpec(), - TemplateParamLists.data(), - TemplateParamLists.size(), - isFriend, - isExplicitSpecialization, - Invalid)) { + if (TemplateParameterList *TemplateParams = + MatchTemplateParametersToScopeSpecifier( + D.getDeclSpec().getLocStart(), D.getIdentifierLoc(), + D.getCXXScopeSpec(), TemplateParamLists, isFriend, + isExplicitSpecialization, Invalid)) { if (TemplateParams->size() > 0) { // This is a function template @@ -9718,13 +9708,10 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // for non-C++ cases. if (TemplateParameterLists.size() > 0 || (SS.isNotEmpty() && TUK != TUK_Reference)) { - if (TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier(KWLoc, NameLoc, SS, - TemplateParameterLists.data(), - TemplateParameterLists.size(), - TUK == TUK_Friend, - isExplicitSpecialization, - Invalid)) { + if (TemplateParameterList *TemplateParams = + MatchTemplateParametersToScopeSpecifier( + KWLoc, NameLoc, SS, TemplateParameterLists, TUK == TUK_Friend, + isExplicitSpecialization, Invalid)) { if (Kind == TTK_Enum) { Diag(KWLoc, diag::err_enum_template); return 0; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index e331afd4d0..25dbd07b41 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -10996,13 +10996,10 @@ Decl *Sema::ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, bool isExplicitSpecialization = false; bool Invalid = false; - if (TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier(TagLoc, NameLoc, SS, - TempParamLists.data(), - TempParamLists.size(), - /*friend*/ true, - isExplicitSpecialization, - Invalid)) { + if (TemplateParameterList *TemplateParams = + MatchTemplateParametersToScopeSpecifier( + TagLoc, NameLoc, SS, TempParamLists, /*friend*/ true, + isExplicitSpecialization, Invalid)) { if (TemplateParams->size() > 0) { // This is a declaration of a class template. if (Invalid) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 7939c48c64..c0ebc8e058 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1601,15 +1601,10 @@ static SourceRange getRangeOfTypeInNestedNameSpecifier(ASTContext &Context, /// template) or may have no template parameters (if we're declaring a /// template specialization), or may be NULL (if what we're declaring isn't /// itself a template). -TemplateParameterList * -Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, - SourceLocation DeclLoc, - const CXXScopeSpec &SS, - TemplateParameterList **ParamLists, - unsigned NumParamLists, - bool IsFriend, - bool &IsExplicitSpecialization, - bool &Invalid) { +TemplateParameterList *Sema::MatchTemplateParametersToScopeSpecifier( + SourceLocation DeclStartLoc, SourceLocation DeclLoc, const CXXScopeSpec &SS, + ArrayRef ParamLists, bool IsFriend, + bool &IsExplicitSpecialization, bool &Invalid) { IsExplicitSpecialization = false; Invalid = false; @@ -1782,7 +1777,7 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // unspecialized, except that the declaration shall not explicitly // specialize a class member template if its en- closing class templates // are not explicitly specialized as well. - if (ParamIdx < NumParamLists) { + if (ParamIdx < ParamLists.size()) { if (ParamLists[ParamIdx]->size() == 0) { if (SawNonEmptyTemplateParameterList) { Diag(DeclLoc, diag::err_specialize_member_of_template) @@ -1800,8 +1795,8 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // here, then it's an explicit specialization. if (TypeIdx == NumTypes - 1) IsExplicitSpecialization = true; - - if (ParamIdx < NumParamLists) { + + if (ParamIdx < ParamLists.size()) { if (ParamLists[ParamIdx]->size() > 0) { // The header has template parameters when it shouldn't. Complain. Diag(ParamLists[ParamIdx]->getTemplateLoc(), @@ -1822,7 +1817,7 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, if (!IsFriend) { // We don't have a template header, but we should. SourceLocation ExpectedTemplateLoc; - if (NumParamLists > 0) + if (!ParamLists.empty()) ExpectedTemplateLoc = ParamLists[0]->getTemplateLoc(); else ExpectedTemplateLoc = DeclStartLoc; @@ -1841,15 +1836,15 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // assume that empty parameter lists are supposed to match this // template-id. if (IsFriend && T->isDependentType()) { - if (ParamIdx < NumParamLists && + if (ParamIdx < ParamLists.size() && DependsOnTemplateParameters(T, ParamLists[ParamIdx])) ExpectedTemplateParams = 0; else continue; } - if (ParamIdx < NumParamLists) { - // Check the template parameter list, if we can. + if (ParamIdx < ParamLists.size()) { + // Check the template parameter list, if we can. if (ExpectedTemplateParams && !TemplateParameterListsAreEqual(ParamLists[ParamIdx], ExpectedTemplateParams, @@ -1876,25 +1871,25 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // If there were at least as many template-ids as there were template // parameter lists, then there are no template parameter lists remaining for // the declaration itself. - if (ParamIdx >= NumParamLists) + if (ParamIdx >= ParamLists.size()) return 0; // If there were too many template parameter lists, complain about that now. - if (ParamIdx < NumParamLists - 1) { + if (ParamIdx < ParamLists.size() - 1) { bool HasAnyExplicitSpecHeader = false; bool AllExplicitSpecHeaders = true; - for (unsigned I = ParamIdx; I != NumParamLists - 1; ++I) { + for (unsigned I = ParamIdx, E = ParamLists.size() - 1; I != E; ++I) { if (ParamLists[I]->size() == 0) HasAnyExplicitSpecHeader = true; else AllExplicitSpecHeaders = false; } - + Diag(ParamLists[ParamIdx]->getTemplateLoc(), - AllExplicitSpecHeaders? diag::warn_template_spec_extra_headers - : diag::err_template_spec_extra_headers) - << SourceRange(ParamLists[ParamIdx]->getTemplateLoc(), - ParamLists[NumParamLists - 2]->getRAngleLoc()); + AllExplicitSpecHeaders ? diag::warn_template_spec_extra_headers + : diag::err_template_spec_extra_headers) + << SourceRange(ParamLists[ParamIdx]->getTemplateLoc(), + ParamLists[ParamLists.size() - 2]->getRAngleLoc()); // If there was a specialization somewhere, such that 'template<>' is // not required, and there were any 'template<>' headers, note where the @@ -1918,8 +1913,7 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // unspecialized, except that the declaration shall not explicitly // specialize a class member template if its en- closing class templates // are not explicitly specialized as well. - if (ParamLists[NumParamLists - 1]->size() == 0 && - SawNonEmptyTemplateParameterList) { + if (ParamLists.back()->size() == 0 && SawNonEmptyTemplateParameterList) { Diag(DeclLoc, diag::err_specialize_member_of_template) << ParamLists[ParamIdx]->getSourceRange(); Invalid = true; @@ -1929,7 +1923,7 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, // Return the last template parameter list, which corresponds to the // entity being declared. - return ParamLists[NumParamLists - 1]; + return ParamLists.back(); } void Sema::NoteAllFoundTemplates(TemplateName Name) { @@ -5246,15 +5240,10 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // FIXME: We probably shouldn't complain about these headers for // friend declarations. bool Invalid = false; - TemplateParameterList *TemplateParams - = MatchTemplateParametersToScopeSpecifier(TemplateNameLoc, - TemplateNameLoc, - SS, - TemplateParameterLists.data(), - TemplateParameterLists.size(), - TUK == TUK_Friend, - isExplicitSpecialization, - Invalid); + TemplateParameterList *TemplateParams = + MatchTemplateParametersToScopeSpecifier( + TemplateNameLoc, TemplateNameLoc, SS, TemplateParameterLists, + TUK == TUK_Friend, isExplicitSpecialization, Invalid); if (Invalid) return true; -- 2.40.0