From bbd68e1f187894ba4562dcf4aaf9acd65f3cf5d0 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 26 Jun 2014 04:58:53 +0000 Subject: Convert some function arguments to use ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211764 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclTemplate.h | 62 +++++++++++++++----------------- lib/AST/ASTImporter.cpp | 5 ++- lib/AST/DeclTemplate.cpp | 35 +++++++++--------- lib/CodeGen/CGClass.cpp | 2 +- lib/Sema/SemaDeclCXX.cpp | 6 ++-- lib/Sema/SemaTemplate.cpp | 23 ++++-------- lib/Sema/SemaTemplateInstantiateDecl.cpp | 18 ++++------ lib/Serialization/ASTReaderDecl.cpp | 3 +- 8 files changed, 63 insertions(+), 91 deletions(-) diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 483ea7941f..980a06e35b 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -86,11 +86,11 @@ public: unsigned size() const { return NumParams; } - llvm::ArrayRef asArray() { - return llvm::ArrayRef(begin(), size()); + ArrayRef asArray() { + return ArrayRef(begin(), size()); } - llvm::ArrayRef asArray() const { - return llvm::ArrayRef(begin(), size()); + ArrayRef asArray() const { + return ArrayRef(begin(), size()); } NamedDecl* getParam(unsigned Idx) { @@ -203,8 +203,8 @@ public: const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } /// \brief Produce this as an array ref. - llvm::ArrayRef asArray() const { - return llvm::ArrayRef(data(), size()); + ArrayRef asArray() const { + return ArrayRef(data(), size()); } /// \brief Retrieve the number of template arguments in this @@ -380,16 +380,15 @@ public: } void Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, TemplateArguments->data(), - TemplateArguments->size(), + Profile(ID, TemplateArguments->asArray(), Function->getASTContext()); } static void - Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs, ASTContext &Context) { - ID.AddInteger(NumTemplateArgs); - for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) + Profile(llvm::FoldingSetNodeID &ID, ArrayRef TemplateArgs, + ASTContext &Context) { + ID.AddInteger(TemplateArgs.size()); + for (unsigned Arg = 0; Arg != TemplateArgs.size(); ++Arg) TemplateArgs[Arg].Profile(ID, Context); } }; @@ -597,8 +596,7 @@ protected: template typename SpecEntryTraits::DeclType* findSpecializationImpl(llvm::FoldingSetVector &Specs, - const TemplateArgument *Args, unsigned NumArgs, - void *&InsertPos); + ArrayRef Args, void *&InsertPos); struct CommonBase { CommonBase() : InstantiatedFromMember(nullptr, false) { } @@ -819,8 +817,8 @@ public: /// \brief Return the specialization with the provided arguments if it exists, /// otherwise return the insertion point. - FunctionDecl *findSpecialization(const TemplateArgument *Args, - unsigned NumArgs, void *&InsertPos); + FunctionDecl *findSpecialization(ArrayRef Args, + void *&InsertPos); FunctionTemplateDecl *getCanonicalDecl() override { return cast( @@ -1628,14 +1626,14 @@ public: SourceRange getSourceRange() const override LLVM_READONLY; void Profile(llvm::FoldingSetNodeID &ID) const { - Profile(ID, TemplateArgs->data(), TemplateArgs->size(), getASTContext()); + Profile(ID, TemplateArgs->asArray(), getASTContext()); } static void - Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs, ASTContext &Context) { - ID.AddInteger(NumTemplateArgs); - for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) + Profile(llvm::FoldingSetNodeID &ID, ArrayRef TemplateArgs, + ASTContext &Context) { + ID.AddInteger(TemplateArgs.size()); + for (unsigned Arg = 0; Arg != TemplateArgs.size(); ++Arg) TemplateArgs[Arg].Profile(ID, Context); } @@ -1878,8 +1876,7 @@ public: /// \brief Return the specialization with the provided arguments if it exists, /// otherwise return the insertion point. ClassTemplateSpecializationDecl * - findSpecialization(const TemplateArgument *Args, unsigned NumArgs, - void *&InsertPos); + findSpecialization(ArrayRef Args, void *&InsertPos); /// \brief Insert the specified specialization knowing that it is not already /// in. InsertPos must be obtained from findSpecialization. @@ -1925,8 +1922,7 @@ public: /// \brief Return the partial specialization with the provided arguments if it /// exists, otherwise return the insertion point. ClassTemplatePartialSpecializationDecl * - findPartialSpecialization(const TemplateArgument *Args, unsigned NumArgs, - void *&InsertPos); + findPartialSpecialization(ArrayRef Args, void *&InsertPos); /// \brief Insert the specified partial specialization knowing that it is not /// already in. InsertPos must be obtained from findPartialSpecialization. @@ -2487,14 +2483,14 @@ public: } void Profile(llvm::FoldingSetNodeID &ID) const { - Profile(ID, TemplateArgs->data(), TemplateArgs->size(), getASTContext()); + Profile(ID, TemplateArgs->asArray(), getASTContext()); } static void Profile(llvm::FoldingSetNodeID &ID, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs, ASTContext &Context) { - ID.AddInteger(NumTemplateArgs); - for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg) + ArrayRef TemplateArgs, + ASTContext &Context) { + ID.AddInteger(TemplateArgs.size()); + for (unsigned Arg = 0; Arg != TemplateArgs.size(); ++Arg) TemplateArgs[Arg].Profile(ID, Context); } @@ -2715,8 +2711,7 @@ public: /// \brief Return the specialization with the provided arguments if it exists, /// otherwise return the insertion point. VarTemplateSpecializationDecl * - findSpecialization(const TemplateArgument *Args, unsigned NumArgs, - void *&InsertPos); + findSpecialization(ArrayRef Args, void *&InsertPos); /// \brief Insert the specified specialization knowing that it is not already /// in. InsertPos must be obtained from findSpecialization. @@ -2752,8 +2747,7 @@ public: /// \brief Return the partial specialization with the provided arguments if it /// exists, otherwise return the insertion point. VarTemplatePartialSpecializationDecl * - findPartialSpecialization(const TemplateArgument *Args, unsigned NumArgs, - void *&InsertPos); + findPartialSpecialization(ArrayRef Args, void *&InsertPos); /// \brief Insert the specified partial specialization knowing that it is not /// already in. InsertPos must be obtained from findPartialSpecialization. diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index b180326508..b0e0b1dc9e 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -4090,8 +4090,7 @@ Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( // Try to find an existing specialization with these template arguments. void *InsertPos = nullptr; ClassTemplateSpecializationDecl *D2 - = ClassTemplate->findSpecialization(TemplateArgs.data(), - TemplateArgs.size(), InsertPos); + = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); if (D2) { // We already have a class template specialization with these template // arguments. @@ -4284,7 +4283,7 @@ Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( // Try to find an existing specialization with these template arguments. void *InsertPos = nullptr; VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( - TemplateArgs.data(), TemplateArgs.size(), InsertPos); + TemplateArgs, InsertPos); if (D2) { // We already have a variable template specialization with these template // arguments. diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index a69146b5b8..0d1d2a4613 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -164,11 +164,11 @@ template typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType* RedeclarableTemplateDecl::findSpecializationImpl( llvm::FoldingSetVector &Specs, - const TemplateArgument *Args, unsigned NumArgs, + ArrayRef Args, void *&InsertPos) { typedef SpecEntryTraits SETraits; llvm::FoldingSetNodeID ID; - EntryType::Profile(ID,Args,NumArgs, getASTContext()); + EntryType::Profile(ID,Args, getASTContext()); EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); return Entry ? SETraits::getMostRecentDecl(Entry) : nullptr; } @@ -263,9 +263,9 @@ FunctionTemplateDecl::getSpecializations() const { } FunctionDecl * -FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, - unsigned NumArgs, void *&InsertPos) { - return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); +FunctionTemplateDecl::findSpecialization(ArrayRef Args, + void *&InsertPos) { + return findSpecializationImpl(getSpecializations(), Args, InsertPos); } void FunctionTemplateDecl::addSpecialization( @@ -350,9 +350,9 @@ ClassTemplateDecl::newCommon(ASTContext &C) const { } ClassTemplateSpecializationDecl * -ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, - unsigned NumArgs, void *&InsertPos) { - return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); +ClassTemplateDecl::findSpecialization(ArrayRef Args, + void *&InsertPos) { + return findSpecializationImpl(getSpecializations(), Args, InsertPos); } void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, @@ -370,11 +370,9 @@ void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, } ClassTemplatePartialSpecializationDecl * -ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, - unsigned NumArgs, +ClassTemplateDecl::findPartialSpecialization(ArrayRef Args, void *&InsertPos) { - return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, - InsertPos); + return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); } void ClassTemplateDecl::AddPartialSpecialization( @@ -985,9 +983,9 @@ VarTemplateDecl::newCommon(ASTContext &C) const { } VarTemplateSpecializationDecl * -VarTemplateDecl::findSpecialization(const TemplateArgument *Args, - unsigned NumArgs, void *&InsertPos) { - return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); +VarTemplateDecl::findSpecialization(ArrayRef Args, + void *&InsertPos) { + return findSpecializationImpl(getSpecializations(), Args, InsertPos); } void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D, @@ -1005,10 +1003,9 @@ void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D, } VarTemplatePartialSpecializationDecl * -VarTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, - unsigned NumArgs, void *&InsertPos) { - return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, - InsertPos); +VarTemplateDecl::findPartialSpecialization(ArrayRef Args, + void *&InsertPos) { + return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); } void VarTemplateDecl::AddPartialSpecialization( diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index e82ac1df53..9427de14d7 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -2179,7 +2179,7 @@ void CodeGenFunction::EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD) { FunctionTemplateDecl *CallOpTemplate = CallOp->getDescribedFunctionTemplate(); void *InsertPos = nullptr; FunctionDecl *CorrespondingCallOpSpecialization = - CallOpTemplate->findSpecialization(TAL->data(), TAL->size(), InsertPos); + CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos); assert(CorrespondingCallOpSpecialization); CallOp = cast(CorrespondingCallOpSpecialization); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 35fd22c060..03600d02f8 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -10552,8 +10552,7 @@ void Sema::DefineImplicitLambdaToFunctionPointerConversion( DeducedTemplateArgs = Conv->getTemplateSpecializationArgs(); void *InsertPos = nullptr; FunctionDecl *CallOpSpec = CallOpTemplate->findSpecialization( - DeducedTemplateArgs->data(), - DeducedTemplateArgs->size(), + DeducedTemplateArgs->asArray(), InsertPos); assert(CallOpSpec && "Conversion operator must have a corresponding call operator"); @@ -10579,8 +10578,7 @@ void Sema::DefineImplicitLambdaToFunctionPointerConversion( Invoker->getDescribedFunctionTemplate(); void *InsertPos = nullptr; FunctionDecl *InvokeSpec = InvokeTemplate->findSpecialization( - DeducedTemplateArgs->data(), - DeducedTemplateArgs->size(), + DeducedTemplateArgs->asArray(), InsertPos); assert(InvokeSpec && "Must have a corresponding static invoker specialization"); diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 00d93f8528..32d51d5d41 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2119,8 +2119,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // corresponds to these arguments. void *InsertPos = nullptr; ClassTemplateSpecializationDecl *Decl - = ClassTemplate->findSpecialization(Converted.data(), Converted.size(), - InsertPos); + = ClassTemplate->findSpecialization(Converted, InsertPos); if (!Decl) { // This is the first time we have referenced this class template // specialization. Create the canonical declaration and add it to @@ -2500,11 +2499,9 @@ DeclResult Sema::ActOnVarTemplateSpecialization( if (IsPartialSpecialization) // FIXME: Template parameter list matters too - PrevDecl = VarTemplate->findPartialSpecialization( - Converted.data(), Converted.size(), InsertPos); + PrevDecl = VarTemplate->findPartialSpecialization(Converted, InsertPos); else - PrevDecl = VarTemplate->findSpecialization(Converted.data(), - Converted.size(), InsertPos); + PrevDecl = VarTemplate->findSpecialization(Converted, InsertPos); VarTemplateSpecializationDecl *Specialization = nullptr; @@ -2669,7 +2666,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, // corresponds to these arguments. void *InsertPos = nullptr; if (VarTemplateSpecializationDecl *Spec = Template->findSpecialization( - Converted.data(), Converted.size(), InsertPos)) + Converted, InsertPos)) // If we already have a variable template specialization, return it. return Spec; @@ -6080,14 +6077,9 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (isPartialSpecialization) // FIXME: Template parameter list matters, too - PrevDecl - = ClassTemplate->findPartialSpecialization(Converted.data(), - Converted.size(), - InsertPos); + PrevDecl = ClassTemplate->findPartialSpecialization(Converted, InsertPos); else - PrevDecl - = ClassTemplate->findSpecialization(Converted.data(), - Converted.size(), InsertPos); + PrevDecl = ClassTemplate->findSpecialization(Converted, InsertPos); ClassTemplateSpecializationDecl *Specialization = nullptr; @@ -7097,8 +7089,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, // corresponds to these arguments. void *InsertPos = nullptr; ClassTemplateSpecializationDecl *PrevDecl - = ClassTemplate->findSpecialization(Converted.data(), - Converted.size(), InsertPos); + = ClassTemplate->findSpecialization(Converted, InsertPos); TemplateSpecializationKind PrevDecl_TSK = PrevDecl ? PrevDecl->getTemplateSpecializationKind() : TSK_Undeclared; diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 29a10d0daa..0790daf16d 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1230,8 +1230,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, void *InsertPos = nullptr; FunctionDecl *SpecFunc - = FunctionTemplate->findSpecialization(Innermost.begin(), Innermost.size(), - InsertPos); + = FunctionTemplate->findSpecialization(Innermost, InsertPos); // If we already have a function template specialization, return it. if (SpecFunc) @@ -1508,9 +1507,7 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, void *InsertPos = nullptr; FunctionDecl *SpecFunc - = FunctionTemplate->findSpecialization(Innermost.begin(), - Innermost.size(), - InsertPos); + = FunctionTemplate->findSpecialization(Innermost, InsertPos); // If we already have a function template specialization, return it. if (SpecFunc) @@ -2386,8 +2383,7 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl( // in the member template's set of class template explicit specializations. void *InsertPos = nullptr; ClassTemplateSpecializationDecl *PrevDecl = - InstClassTemplate->findSpecialization(Converted.data(), Converted.size(), - InsertPos); + InstClassTemplate->findSpecialization(Converted, InsertPos); // Check whether we've already seen a conflicting instantiation of this // declaration (for instance, if there was a prior implicit instantiation). @@ -2509,7 +2505,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( // corresponds to these arguments. void *InsertPos = nullptr; if (VarTemplateSpecializationDecl *VarSpec = VarTemplate->findSpecialization( - Converted.data(), Converted.size(), InsertPos)) + Converted, InsertPos)) // If we already have a variable template specialization, return it. return VarSpec; @@ -2674,8 +2670,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( // in the member template's set of class template partial specializations. void *InsertPos = nullptr; ClassTemplateSpecializationDecl *PrevDecl - = ClassTemplate->findPartialSpecialization(Converted.data(), - Converted.size(), InsertPos); + = ClassTemplate->findPartialSpecialization(Converted, InsertPos); // Build the canonical type that describes the converted template // arguments of the class template partial specialization. @@ -2799,8 +2794,7 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( // in the member template's set of variable template partial specializations. void *InsertPos = nullptr; VarTemplateSpecializationDecl *PrevDecl = - VarTemplate->findPartialSpecialization(Converted.data(), Converted.size(), - InsertPos); + VarTemplate->findPartialSpecialization(Converted, InsertPos); // Build the canonical type that describes the converted template // arguments of the variable template partial specialization. diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 47748a33f7..beffe06590 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -664,8 +664,7 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { // We avoid getASTContext because a decl in the parent hierarchy may // be initializing. llvm::FoldingSetNodeID ID; - FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(), - TemplArgs.size(), C); + FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); void *InsertPos = nullptr; FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); -- cgit v1.2.3