using namespace idx;
+/// \brief Allocator for a cached set of global code completions.
+class GlobalCodeCompletionAllocator
+ : public CodeCompletionAllocator,
+ public llvm::RefCountedBase<GlobalCodeCompletionAllocator>
+{
+
+};
+
/// \brief Utility class for loading a ASTContext from an AST file.
///
class ASTUnit {
return CachedCompletionTypes;
}
+ /// \brief Retrieve the allocator used to cache global code completions.
+ llvm::IntrusiveRefCntPtr<GlobalCodeCompletionAllocator>
+ getCachedCompletionAllocator() {
+ return CachedCompletionAllocator;
+ }
+
private:
/// \brief Allocator used to store cached code completions.
- CodeCompletionAllocator CachedCompletionAllocator;
+ llvm::IntrusiveRefCntPtr<GlobalCodeCompletionAllocator>
+ CachedCompletionAllocator;
/// \brief The set of cached code-completion results.
std::vector<CachedCodeCompletionResult> CachedCompletionResults;
// Gather the set of global code completions.
typedef CodeCompletionResult Result;
llvm::SmallVector<Result, 8> Results;
- TheSema->GatherGlobalCodeCompletions(CachedCompletionAllocator, Results);
+ CachedCompletionAllocator = new GlobalCodeCompletionAllocator;
+ TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator, Results);
// Translate global code completions into cached completions.
llvm::DenseMap<CanQualType, unsigned> CompletionTypes;
bool IsNestedNameSpecifier = false;
CachedCodeCompletionResult CachedResult;
CachedResult.Completion = Results[I].CreateCodeCompletionString(*TheSema,
- CachedCompletionAllocator);
+ *CachedCompletionAllocator);
CachedResult.ShowInContexts = getDeclShowContexts(Results[I].Declaration,
Ctx->getLangOptions(),
IsNestedNameSpecifier);
Results[I].StartsNestedNameSpecifier = true;
CachedResult.Completion
= Results[I].CreateCodeCompletionString(*TheSema,
- CachedCompletionAllocator);
+ *CachedCompletionAllocator);
CachedResult.ShowInContexts = RemainingContexts;
CachedResult.Priority = CCP_NestedNameSpecifier;
CachedResult.TypeClass = STC_Void;
CachedCodeCompletionResult CachedResult;
CachedResult.Completion
= Results[I].CreateCodeCompletionString(*TheSema,
- CachedCompletionAllocator);
+ *CachedCompletionAllocator);
CachedResult.ShowInContexts
= (1 << (CodeCompletionContext::CCC_TopLevel - 1))
| (1 << (CodeCompletionContext::CCC_ObjCInterface - 1))
void ASTUnit::ClearCachedCompletionResults() {
CachedCompletionResults.clear();
CachedCompletionTypes.clear();
- CachedCompletionAllocator.Reset();
+ CachedCompletionAllocator = 0;
}
namespace {
/// the code-completion results.
llvm::SmallVector<const llvm::MemoryBuffer *, 1> TemporaryBuffers;
+ /// \brief Allocator used to store globally cached code-completion results.
+ llvm::IntrusiveRefCntPtr<clang::GlobalCodeCompletionAllocator>
+ CachedCompletionAllocator;
+
/// \brief Allocator used to store code completion results.
clang::CodeCompletionAllocator CodeCompletionAllocator;
};
AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults;
Results->Results = 0;
Results->NumResults = 0;
-
+
// Create a code-completion consumer to capture the results.
CaptureCompletionResults Capture(*Results);
*Results->Diag, Results->LangOpts, Results->SourceMgr,
Results->FileMgr, Results->Diagnostics,
Results->TemporaryBuffers);
+
+ // Keep a reference to the allocator used for cached global completions, so
+ // that we can be sure that the memory used by our code completion strings
+ // doesn't get freed due to subsequent reparses (while the code completion
+ // results are still active).
+ Results->CachedCompletionAllocator = AST->getCachedCompletionAllocator();