[cfe-commits] r124698 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Sema/CodeCompleteConsumer.h include/clang/Sema/Sema.h lib/Frontend/ASTUnit.cpp lib/Sema/CodeCompleteConsumer.cpp lib/Sema/SemaCodeComplete.cpp tools/libclang/CIndexCodeCompletion.cpp

Douglas Gregor dgregor at apple.com
Tue Feb 1 14:57:45 PST 2011


Author: dgregor
Date: Tue Feb  1 16:57:45 2011
New Revision: 124698

URL: http://llvm.org/viewvc/llvm-project?rev=124698&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Feb  1 16:57:45 2011
@@ -288,11 +288,8 @@
   }
   
 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<CachedCodeCompletionResult> CachedCompletionResults;

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Tue Feb  1 16:57:45 2011
@@ -421,13 +421,20 @@
   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 @@
   llvm::SmallVector<Chunk, 4> 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 @@
   /// \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 @@
     /// 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 @@
   
   /// \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 @@
   /// \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 @@
                                          OverloadCandidate *Candidates,
                                          unsigned NumCandidates);  
   
-  virtual llvm::BumpPtrAllocator &getAllocator() { return Allocator; }
+  virtual CodeCompletionAllocator &getAllocator() { return Allocator; }
 };
   
 } // end namespace clang

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Feb  1 16:57:45 2011
@@ -63,6 +63,7 @@
   class ClassTemplatePartialSpecializationDecl;
   class ClassTemplateSpecializationDecl;
   class CodeCompleteConsumer;
+  class CodeCompletionAllocator;
   class CodeCompletionResult;
   class Decl;
   class DeclAccessPair;
@@ -4909,7 +4910,7 @@
                                              MacroInfo *MacroInfo,
                                              unsigned Argument);
   void CodeCompleteNaturalLanguage();
-  void GatherGlobalCodeCompletions(llvm::BumpPtrAllocator &Allocator,
+  void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
                   llvm::SmallVectorImpl<CodeCompletionResult> &Results);
   //@}
 

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Feb  1 16:57:45 2011
@@ -1661,7 +1661,7 @@
       Next.ProcessOverloadCandidates(S, CurrentArg, Candidates, NumCandidates);
     }
     
-    virtual llvm::BumpPtrAllocator &getAllocator() {
+    virtual CodeCompletionAllocator &getAllocator() {
       return Next.getAllocator();
     }
   };

Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Tue Feb  1 16:57:45 2011
@@ -220,6 +220,13 @@
   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(), 

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Feb  1 16:57:45 2011
@@ -119,7 +119,7 @@
     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 @@
     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 @@
     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 @@
     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 @@
 /// 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 @@
   // 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 @@
       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 @@
       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 @@
     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 @@
     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 @@
   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 @@
                                         = Ty->getAs<InjectedClassNameType>())
       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 @@
 /// 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 @@
     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 @@
       
       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 @@
       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 @@
   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 @@
   if (TemplateDecl *Template = dyn_cast<TemplateDecl>(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 @@
   if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(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 @@
     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 @@
           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 @@
         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 @@
     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 @@
 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 @@
   }
   
   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 @@
     
     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 @@
         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 @@
       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 @@
     }
     
     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 @@
     }
     
     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 @@
     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 @@
   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 @@
       
       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 @@
 
     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 @@
     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 @@
       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 @@
     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 @@
       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 @@
       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 @@
           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 @@
     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 @@
                             0, 0);
 }
 
-void Sema::GatherGlobalCodeCompletions(llvm::BumpPtrAllocator &Allocator,
+void Sema::GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
                  llvm::SmallVectorImpl<CodeCompletionResult> &Results) {
   ResultBuilder Builder(*this, Allocator, CodeCompletionContext::CCC_Recovery);
   if (!CodeCompleter || CodeCompleter->includeGlobals()) {

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=124698&r1=124697&r2=124698&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Tue Feb  1 16:57:45 2011
@@ -230,7 +230,7 @@
   llvm::SmallVector<const llvm::MemoryBuffer *, 1> 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 @@
       }
     }
     
-    virtual llvm::BumpPtrAllocator &getAllocator() { 
+    virtual CodeCompletionAllocator &getAllocator() { 
       return AllocatedResults.CodeCompletionAllocator;
     }
     





More information about the cfe-commits mailing list