diff options
Diffstat (limited to 'include/clang/Sema/CodeCompleteConsumer.h')
-rw-r--r-- | include/clang/Sema/CodeCompleteConsumer.h | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index ff2ca871f2..fe9bed5c86 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -501,8 +501,6 @@ public: /// \brief An allocator used specifically for the purpose of code completion. class CodeCompletionAllocator : public llvm::BumpPtrAllocator { - llvm::DenseMap<DeclContext *, StringRef> ParentNames; - public: /// \brief Copy the given string into this allocator. const char *CopyString(StringRef String); @@ -519,12 +517,34 @@ public: const char *CopyString(const std::string &String) { return CopyString(StringRef(String)); } - - /// \brief Retrieve the mapping from known parent declaration contexts to - /// the (already copied) strings associated with each context. - llvm::DenseMap<DeclContext *, StringRef> &getParentNames() { - return ParentNames; +}; + +/// \brief Allocator for a cached set of global code completions. +class GlobalCodeCompletionAllocator + : public CodeCompletionAllocator, + public RefCountedBase<GlobalCodeCompletionAllocator> +{ + +}; + +class CodeCompletionTUInfo { + llvm::DenseMap<DeclContext *, StringRef> ParentNames; + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> AllocatorRef; + +public: + explicit CodeCompletionTUInfo( + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> Allocator) + : AllocatorRef(Allocator) { } + + IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> getAllocatorRef() const { + return AllocatorRef; + } + CodeCompletionAllocator &getAllocator() const { + assert(AllocatorRef); + return *AllocatorRef; } + + StringRef getParentName(DeclContext *DC); }; } // end namespace clang @@ -544,6 +564,7 @@ public: private: CodeCompletionAllocator &Allocator; + CodeCompletionTUInfo &CCTUInfo; unsigned Priority; CXAvailabilityKind Availability; CXCursorKind ParentKind; @@ -555,19 +576,25 @@ private: SmallVector<const char *, 2> Annotations; public: - CodeCompletionBuilder(CodeCompletionAllocator &Allocator) - : Allocator(Allocator), Priority(0), Availability(CXAvailability_Available), + CodeCompletionBuilder(CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo) + : Allocator(Allocator), CCTUInfo(CCTUInfo), + Priority(0), Availability(CXAvailability_Available), ParentKind(CXCursor_NotImplemented) { } CodeCompletionBuilder(CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability) - : Allocator(Allocator), Priority(Priority), Availability(Availability), + : Allocator(Allocator), CCTUInfo(CCTUInfo), + Priority(Priority), Availability(Availability), ParentKind(CXCursor_NotImplemented) { } /// \brief Retrieve the allocator into which the code completion /// strings should be allocated. CodeCompletionAllocator &getAllocator() const { return Allocator; } + CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; } + /// \brief Take the resulting completion string. /// /// This operation can only be performed once. @@ -753,10 +780,12 @@ public: /// \param Allocator The allocator that will be used to allocate the /// string itself. CodeCompletionString *CreateCodeCompletionString(Sema &S, - CodeCompletionAllocator &Allocator); + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo); CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, Preprocessor &PP, - CodeCompletionAllocator &Allocator); + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo); /// \brief Determine a base priority for the given declaration. static unsigned getPriorityFromDecl(NamedDecl *ND); @@ -868,7 +897,8 @@ public: /// signature of this overload candidate. CodeCompletionString *CreateSignatureString(unsigned CurrentArg, Sema &S, - CodeCompletionAllocator &Allocator) const; + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo) const; }; CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false), @@ -918,6 +948,8 @@ public: /// \brief Retrieve the allocator that will be used to allocate /// code completion strings. virtual CodeCompletionAllocator &getAllocator() = 0; + + virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0; }; /// \brief A simple code-completion consumer that prints the results it @@ -926,7 +958,7 @@ class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { /// \brief The raw output stream. raw_ostream &OS; - CodeCompletionAllocator Allocator; + CodeCompletionTUInfo CCTUInfo; public: /// \brief Create a new printing code-completion consumer that prints its @@ -935,7 +967,8 @@ public: bool IncludeGlobals, raw_ostream &OS) : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals, - false), OS(OS) {} + false), OS(OS), + CCTUInfo(new GlobalCodeCompletionAllocator) {} /// \brief Prints the finalized code-completion results. virtual void ProcessCodeCompleteResults(Sema &S, @@ -947,7 +980,11 @@ public: OverloadCandidate *Candidates, unsigned NumCandidates); - virtual CodeCompletionAllocator &getAllocator() { return Allocator; } + virtual CodeCompletionAllocator &getAllocator() { + return CCTUInfo.getAllocator(); + } + + virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() { return CCTUInfo; } }; } // end namespace clang |