From 69e5c4b55bd01f4962bd2af3587bb23c62675a7e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 1 Feb 2011 22:57:45 +0000 Subject: [PATCH] Create a special allocator class for code completion, so that all of the string copying goes through a single place that can have associated state. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124698 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 5 +- include/clang/Sema/CodeCompleteConsumer.h | 25 ++++-- include/clang/Sema/Sema.h | 3 +- lib/Frontend/ASTUnit.cpp | 2 +- lib/Sema/CodeCompleteConsumer.cpp | 7 ++ lib/Sema/SemaCodeComplete.cpp | 142 ++++++++++++++---------------- tools/libclang/CIndexCodeCompletion.cpp | 4 +- 7 files changed, 95 insertions(+), 93 deletions(-) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 6ee3e85fe..b1eb0da24 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -288,11 +288,8 @@ public: } private: - /// \brief Allocator used to store temporary code completion results. - llvm::BumpPtrAllocator CompletionAllocator; - /// \brief Allocator used to store cached code completions. - llvm::BumpPtrAllocator CachedCompletionAllocator; + CodeCompletionAllocator CachedCompletionAllocator; /// \brief The set of cached code-completion results. std::vector CachedCompletionResults; diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 9daefd72a..8cb8e7539 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -421,13 +421,20 @@ public: std::string getAsString() const; }; +/// \brief An allocator used specifically for the purpose of code completion. +class CodeCompletionAllocator : public llvm::BumpPtrAllocator { +public: + /// \brief Copy the given string into this allocator. + const char *CopyString(llvm::StringRef String); +}; + /// \brief A builder class used to construct new code-completion strings. class CodeCompletionBuilder { public: typedef CodeCompletionString::Chunk Chunk; private: - llvm::BumpPtrAllocator &Allocator; + CodeCompletionAllocator &Allocator; unsigned Priority; CXAvailabilityKind Availability; @@ -435,17 +442,17 @@ private: llvm::SmallVector Chunks; public: - CodeCompletionBuilder(llvm::BumpPtrAllocator &Allocator) + CodeCompletionBuilder(CodeCompletionAllocator &Allocator) : Allocator(Allocator), Priority(0), Availability(CXAvailability_Available){ } - CodeCompletionBuilder(llvm::BumpPtrAllocator &Allocator, + CodeCompletionBuilder(CodeCompletionAllocator &Allocator, unsigned Priority, CXAvailabilityKind Availability) : Allocator(Allocator), Priority(Priority), Availability(Availability) { } /// \brief Retrieve the allocator into which the code completion /// strings will be - llvm::BumpPtrAllocator &getAllocator() const { return Allocator; } + CodeCompletionAllocator &getAllocator() const { return Allocator; } /// \brief Take the resulting completion string. /// @@ -630,7 +637,7 @@ public: /// \param Allocator The allocator that will be used to allocate the /// string itself. CodeCompletionString *CreateCodeCompletionString(Sema &S, - llvm::BumpPtrAllocator &Allocator); + CodeCompletionAllocator &Allocator); /// \brief Determine a base priority for the given declaration. static unsigned getPriorityFromDecl(NamedDecl *ND); @@ -742,7 +749,7 @@ public: /// signature of this overload candidate. CodeCompletionString *CreateSignatureString(unsigned CurrentArg, Sema &S, - llvm::BumpPtrAllocator &Allocator) const; + CodeCompletionAllocator &Allocator) const; }; CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false), @@ -791,7 +798,7 @@ public: /// \brief Retrieve the allocator that will be used to allocate /// code completion strings. - virtual llvm::BumpPtrAllocator &getAllocator() = 0; + virtual CodeCompletionAllocator &getAllocator() = 0; }; /// \brief A simple code-completion consumer that prints the results it @@ -800,7 +807,7 @@ class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { /// \brief The raw output stream. llvm::raw_ostream &OS; - llvm::BumpPtrAllocator Allocator; + CodeCompletionAllocator Allocator; public: /// \brief Create a new printing code-completion consumer that prints its @@ -821,7 +828,7 @@ public: OverloadCandidate *Candidates, unsigned NumCandidates); - virtual llvm::BumpPtrAllocator &getAllocator() { return Allocator; } + virtual CodeCompletionAllocator &getAllocator() { return Allocator; } }; } // end namespace clang diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 9d0442171..bb22113ed 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -63,6 +63,7 @@ namespace clang { class ClassTemplatePartialSpecializationDecl; class ClassTemplateSpecializationDecl; class CodeCompleteConsumer; + class CodeCompletionAllocator; class CodeCompletionResult; class Decl; class DeclAccessPair; @@ -4909,7 +4910,7 @@ public: MacroInfo *MacroInfo, unsigned Argument); void CodeCompleteNaturalLanguage(); - void GatherGlobalCodeCompletions(llvm::BumpPtrAllocator &Allocator, + void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, llvm::SmallVectorImpl &Results); //@} diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 5617df688..1db81cb13 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1661,7 +1661,7 @@ namespace { Next.ProcessOverloadCandidates(S, CurrentArg, Candidates, NumCandidates); } - virtual llvm::BumpPtrAllocator &getAllocator() { + virtual CodeCompletionAllocator &getAllocator() { return Next.getAllocator(); } }; diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index ddfe8b0b1..cb2dd234b 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -220,6 +220,13 @@ const char *CodeCompletionString::getTypedText() const { return 0; } +const char *CodeCompletionAllocator::CopyString(llvm::StringRef String) { + char *Mem = (char *)Allocate(String.size() + 1, 1); + std::copy(String.begin(), String.end(), Mem); + Mem[String.size()] = 0; + return Mem; +} + CodeCompletionString *CodeCompletionBuilder::TakeString() { void *Mem = Allocator.Allocate( sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size(), diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 90f55a293..cf088007c 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -119,7 +119,7 @@ namespace { Sema &SemaRef; /// \brief The allocator used to allocate new code-completion strings. - llvm::BumpPtrAllocator &Allocator; + CodeCompletionAllocator &Allocator; /// \brief If non-NULL, a filter function used to remove any code-completion /// results that are not desirable. @@ -162,7 +162,7 @@ namespace { void MaybeAddConstructorResults(Result R); public: - explicit ResultBuilder(Sema &SemaRef, llvm::BumpPtrAllocator &Allocator, + explicit ResultBuilder(Sema &SemaRef, CodeCompletionAllocator &Allocator, const CodeCompletionContext &CompletionContext, LookupFilter Filter = 0) : SemaRef(SemaRef), Allocator(Allocator), Filter(Filter), @@ -247,7 +247,7 @@ namespace { Sema &getSema() const { return SemaRef; } /// \brief Retrieve the allocator used to allocate code completion strings. - llvm::BumpPtrAllocator &getAllocator() const { return Allocator; } + CodeCompletionAllocator &getAllocator() const { return Allocator; } /// \brief Determine whether the given declaration is at all interesting /// as a code-completion result. @@ -1778,15 +1778,6 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Results.AddResult(Result("operator")); } -/// \brief Copy the given string into the allocator. -static const char* -CopyString(llvm::BumpPtrAllocator &Allocator, llvm::StringRef Text) { - char *Mem = (char *)Allocator.Allocate(Text.size() + 1, 1); - std::copy(Text.begin(), Text.end(), Mem); - Mem[Text.size()] = 0; - return Mem; -} - /// \brief Retrieve the string representation of the given type as a string /// that has the appropriate lifetime for code completion. /// @@ -1794,7 +1785,7 @@ CopyString(llvm::BumpPtrAllocator &Allocator, llvm::StringRef Text) { /// common type names. const char *GetCompletionTypeString(QualType T, ASTContext &Context, - llvm::BumpPtrAllocator &Allocator) { + CodeCompletionAllocator &Allocator) { PrintingPolicy Policy(Context.PrintingPolicy); Policy.AnonymousTagLocations = false; @@ -1819,7 +1810,7 @@ const char *GetCompletionTypeString(QualType T, // Slow path: format the type as a string. std::string Result; T.getAsStringInternal(Result, Policy); - return CopyString(Allocator, Result); + return Allocator.CopyString(Result); } /// \brief If the given declaration has an associated type, add it as a result @@ -2017,8 +2008,8 @@ static void AddFunctionParameterChunks(ASTContext &Context, PlaceholderStr += ", ..."; // Add the placeholder string. - Result.AddPlaceholderChunk(CopyString(Result.getAllocator(), - PlaceholderStr)); + Result.AddPlaceholderChunk( + Result.getAllocator().CopyString(PlaceholderStr)); } if (const FunctionProtoType *Proto @@ -2103,8 +2094,8 @@ static void AddTemplateParameterChunks(ASTContext &Context, Result.AddChunk(Chunk(CodeCompletionString::CK_Comma)); // Add the placeholder string. - Result.AddPlaceholderChunk(CopyString(Result.getAllocator(), - PlaceholderStr)); + Result.AddPlaceholderChunk( + Result.getAllocator().CopyString(PlaceholderStr)); } } @@ -2124,9 +2115,9 @@ AddQualifierToCompletionString(CodeCompletionBuilder &Result, Qualifier->print(OS, Context.PrintingPolicy); } if (QualifierIsInformative) - Result.AddInformativeChunk(CopyString(Result.getAllocator(), PrintedNNS)); + Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS)); else - Result.AddTextChunk(CopyString(Result.getAllocator(), PrintedNNS)); + Result.AddTextChunk(Result.getAllocator().CopyString(PrintedNNS)); } static void @@ -2163,7 +2154,7 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, QualsStr += " volatile"; if (Proto->getTypeQuals() & Qualifiers::Restrict) QualsStr += " restrict"; - Result.AddInformativeChunk(CopyString(Result.getAllocator(), QualsStr)); + Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr)); } /// \brief Add the name of the given declaration @@ -2205,8 +2196,8 @@ static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND, case DeclarationName::CXXConversionFunctionName: case DeclarationName::CXXDestructorName: case DeclarationName::CXXLiteralOperatorName: - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - ND->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(ND->getNameAsString())); break; case DeclarationName::CXXUsingDirective: @@ -2224,13 +2215,13 @@ static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND, = Ty->getAs()) Record = InjectedTy->getDecl(); else { - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - ND->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(ND->getNameAsString())); break; } - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - Record->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(Record->getNameAsString())); if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) { Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle)); AddTemplateParameterChunks(Context, Template, Result); @@ -2249,7 +2240,7 @@ static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND, /// result is all that is needed. CodeCompletionString * CodeCompletionResult::CreateCodeCompletionString(Sema &S, - llvm::BumpPtrAllocator &Allocator) { + CodeCompletionAllocator &Allocator) { typedef CodeCompletionString::Chunk Chunk; CodeCompletionBuilder Result(Allocator, Priority, Availability); @@ -2268,8 +2259,8 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, MacroInfo *MI = S.PP.getMacroInfo(Macro); assert(MI && "Not a macro?"); - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - Macro->getName())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(Macro->getName())); if (!MI->isFunctionLike()) return Result.TakeString(); @@ -2283,8 +2274,8 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, if (!MI->isVariadic() || A != AEnd - 1) { // Non-variadic argument. - Result.AddPlaceholderChunk(CopyString(Result.getAllocator(), - (*A)->getName())); + Result.AddPlaceholderChunk( + Result.getAllocator().CopyString((*A)->getName())); continue; } @@ -2296,7 +2287,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, else { std::string Arg = (*A)->getName(); Arg += "..."; - Result.AddPlaceholderChunk(CopyString(Result.getAllocator(), Arg)); + Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Arg)); } } Result.AddChunk(Chunk(CodeCompletionString::CK_RightParen)); @@ -2307,8 +2298,8 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, NamedDecl *ND = Declaration; if (StartsNestedNameSpecifier) { - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - ND->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(ND->getNameAsString())); Result.AddTextChunk("::"); return Result.TakeString(); } @@ -2383,8 +2374,8 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, if (TemplateDecl *Template = dyn_cast(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, S.Context); - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - Template->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(Template->getNameAsString())); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftAngle)); AddTemplateParameterChunks(S.Context, Template, Result); Result.AddChunk(Chunk(CodeCompletionString::CK_RightAngle)); @@ -2394,7 +2385,7 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, if (ObjCMethodDecl *Method = dyn_cast(ND)) { Selector Sel = Method->getSelector(); if (Sel.isUnarySelector()) { - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), + Result.AddTypedTextChunk(Result.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(0)->getName())); return Result.TakeString(); } @@ -2402,9 +2393,9 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, std::string SelName = Sel.getIdentifierInfoForSlot(0)->getName().str(); SelName += ':'; if (StartParameter == 0) - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), SelName)); + Result.AddTypedTextChunk(Result.getAllocator().CopyString(SelName)); else { - Result.AddInformativeChunk(CopyString(Result.getAllocator(), SelName)); + Result.AddInformativeChunk(Result.getAllocator().CopyString(SelName)); // If there is only one parameter, and we're past it, add an empty // typed-text chunk since there is nothing to type. @@ -2423,10 +2414,9 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, Keyword += II->getName().str(); Keyword += ":"; if (Idx < StartParameter || AllParametersAreInformative) - Result.AddInformativeChunk(CopyString(Result.getAllocator(), - Keyword)); + Result.AddInformativeChunk(Result.getAllocator().CopyString(Keyword)); else - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), Keyword)); + Result.AddTypedTextChunk(Result.getAllocator().CopyString(Keyword)); } // If we're before the starting parameter, skip the placeholder. @@ -2449,11 +2439,11 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, Arg += ", ..."; if (DeclaringEntity) - Result.AddTextChunk(CopyString(Result.getAllocator(), Arg)); + Result.AddTextChunk(Result.getAllocator().CopyString(Arg)); else if (AllParametersAreInformative) - Result.AddInformativeChunk(CopyString(Result.getAllocator(), Arg)); + Result.AddInformativeChunk(Result.getAllocator().CopyString(Arg)); else - Result.AddPlaceholderChunk(CopyString(Result.getAllocator(), Arg)); + Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Arg)); } if (Method->isVariadic()) { @@ -2476,8 +2466,8 @@ CodeCompletionResult::CreateCodeCompletionString(Sema &S, AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, S.Context); - Result.AddTypedTextChunk(CopyString(Result.getAllocator(), - ND->getNameAsString())); + Result.AddTypedTextChunk( + Result.getAllocator().CopyString(ND->getNameAsString())); return Result.TakeString(); } @@ -2485,7 +2475,7 @@ CodeCompletionString * CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( unsigned CurrentArg, Sema &S, - llvm::BumpPtrAllocator &Allocator) const { + CodeCompletionAllocator &Allocator) const { typedef CodeCompletionString::Chunk Chunk; // FIXME: Set priority, availability appropriately. @@ -2508,11 +2498,11 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( } if (FDecl) - Result.AddTextChunk(CopyString(Result.getAllocator(), - FDecl->getNameAsString())); + Result.AddTextChunk( + Result.getAllocator().CopyString(FDecl->getNameAsString())); else Result.AddTextChunk( - CopyString(Result.getAllocator(), + Result.getAllocator().CopyString( Proto->getResultType().getAsString(S.Context.PrintingPolicy))); Result.AddChunk(Chunk(CodeCompletionString::CK_LeftParen)); @@ -2535,9 +2525,9 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( if (I == CurrentArg) Result.AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, - CopyString(Result.getAllocator(), ArgString))); + Result.getAllocator().CopyString(ArgString))); else - Result.AddTextChunk(CopyString(Result.getAllocator(), ArgString)); + Result.AddTextChunk(Result.getAllocator().CopyString(ArgString)); } if (Proto && Proto->isVariadic()) { @@ -2781,12 +2771,12 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, std::string Str; llvm::raw_string_ostream OS(Str); NNS->print(OS, S.Context.PrintingPolicy); - Builder.AddTextChunk(CopyString(Results.getAllocator(), OS.str())); + Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str())); } } else if (!InContext->Equals(Overridden->getDeclContext())) continue; - Builder.AddTypedTextChunk(CopyString(Results.getAllocator(), + Builder.AddTypedTextChunk(Results.getAllocator().CopyString( Overridden->getNameAsString())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); bool FirstParam = true; @@ -2798,7 +2788,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, else Builder.AddChunk(CodeCompletionString::CK_Comma); - Builder.AddPlaceholderChunk(CopyString(Results.getAllocator(), + Builder.AddPlaceholderChunk(Results.getAllocator().CopyString( (*P)->getIdentifier()->getName())); } Builder.AddChunk(CodeCompletionString::CK_RightParen); @@ -3729,7 +3719,7 @@ void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, } Builder.AddTypedTextChunk( - CopyString(Results.getAllocator(), + Results.getAllocator().CopyString( Base->getType().getAsString(Context.PrintingPolicy))); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); @@ -3754,7 +3744,7 @@ void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, } Builder.AddTypedTextChunk( - CopyString(Builder.getAllocator(), + Builder.getAllocator().CopyString( Base->getType().getAsString(Context.PrintingPolicy))); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); @@ -3780,7 +3770,7 @@ void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD, if (!Field->getDeclName()) continue; - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Field->getIdentifier()->getName())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); @@ -4498,10 +4488,10 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, Selector Sel = CurMethod->getSelector(); if (Sel.isUnarySelector()) { if (NeedSuperKeyword) - Builder.AddTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTextChunk(Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(0)->getName())); else - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(0)->getName())); } else { ObjCMethodDecl::param_iterator CurP = CurMethod->param_begin(); @@ -4511,19 +4501,19 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, if (I < NumSelIdents) Builder.AddInformativeChunk( - CopyString(Builder.getAllocator(), + Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(I)->getName().str() + ":")); else if (NeedSuperKeyword || I > NumSelIdents) { Builder.AddTextChunk( - CopyString(Builder.getAllocator(), + Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(I)->getName().str() + ":")); - Builder.AddPlaceholderChunk(CopyString(Builder.getAllocator(), + Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString( (*CurP)->getIdentifier()->getName())); } else { Builder.AddTypedTextChunk( - CopyString(Builder.getAllocator(), + Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(I)->getName().str() + ":")); - Builder.AddPlaceholderChunk(CopyString(Builder.getAllocator(), + Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString( (*CurP)->getIdentifier()->getName())); } } @@ -4969,7 +4959,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents, CodeCompletionBuilder Builder(Results.getAllocator()); if (Sel.isUnarySelector()) { - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(0)->getName())); Results.AddResult(Builder.TakeString()); continue; @@ -4979,7 +4969,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents, for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I) { if (I == NumSelIdents) { if (!Accumulator.empty()) { - Builder.AddInformativeChunk(CopyString(Builder.getAllocator(), + Builder.AddInformativeChunk(Builder.getAllocator().CopyString( Accumulator)); Accumulator.clear(); } @@ -4988,7 +4978,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents, Accumulator += Sel.getIdentifierInfoForSlot(I)->getName().str(); Accumulator += ':'; } - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), Accumulator)); + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Accumulator)); Results.AddResult(Builder.TakeString()); } Results.ExitScope(); @@ -5461,7 +5451,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Selector Sel = Method->getSelector(); // Add the first part of the selector to the pattern. - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Sel.getIdentifierInfoForSlot(0)->getName())); // Add parameters to the pattern. @@ -5475,7 +5465,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, else if (I < Sel.getNumArgs()) { Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddTypedTextChunk( - CopyString(Builder.getAllocator(), + Builder.getAllocator().CopyString( (Sel.getIdentifierInfoForSlot(I)->getName() + ":").str())); } else @@ -5489,7 +5479,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Builder.AddChunk(CodeCompletionString::CK_RightParen); if (IdentifierInfo *Id = (*P)->getIdentifier()) - Builder.AddTextChunk(CopyString(Builder.getAllocator(), Id->getName())); + Builder.AddTextChunk(Builder.getAllocator().CopyString( Id->getName())); } if (Method->isVariadic()) { @@ -5578,7 +5568,7 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, ParmVarDecl *Param = MethList->Method->param_begin()[NumSelIdents-1]; if (Param->getIdentifier()) { CodeCompletionBuilder Builder(Results.getAllocator()); - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Param->getIdentifier()->getName())); Results.AddResult(Builder.TakeString()); } @@ -5775,7 +5765,7 @@ void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) { for (Preprocessor::macro_iterator M = PP.macro_begin(), MEnd = PP.macro_end(); M != MEnd; ++M) { - Builder.AddTypedTextChunk(CopyString(Builder.getAllocator(), + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( M->first->getName())); Results.AddResult(Builder.TakeString()); } @@ -5829,7 +5819,7 @@ void Sema::CodeCompleteNaturalLanguage() { 0, 0); } -void Sema::GatherGlobalCodeCompletions(llvm::BumpPtrAllocator &Allocator, +void Sema::GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, llvm::SmallVectorImpl &Results) { ResultBuilder Builder(*this, Allocator, CodeCompletionContext::CCC_Recovery); if (!CodeCompleter || CodeCompleter->includeGlobals()) { diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 97f2066e1..2bd572ccf 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -230,7 +230,7 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { llvm::SmallVector TemporaryBuffers; /// \brief Allocator used to store code completion results. - llvm::BumpPtrAllocator CodeCompletionAllocator; + CodeCompletionAllocator CodeCompletionAllocator; }; /// \brief Tracks the number of code-completion result objects that are @@ -310,7 +310,7 @@ namespace { } } - virtual llvm::BumpPtrAllocator &getAllocator() { + virtual CodeCompletionAllocator &getAllocator() { return AllocatedResults.CodeCompletionAllocator; } -- 2.11.4.GIT