]> granicus.if.org Git - clang/commitdiff
Tweak libclang's heuristics for building precompiled preambles and
authorDouglas Gregor <dgregor@apple.com>
Mon, 15 Nov 2010 23:00:34 +0000 (23:00 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 15 Nov 2010 23:00:34 +0000 (23:00 +0000)
caching global code-completion results. In particular, don't perform
either operation the first time we parse, but do both after the first
reparse.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119285 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp
tools/c-index-test/c-index-test.c

index ff05f45b14d6ffc7ba9c8e30ffc9aff99be6b5b0..5c7b770a355cee30f2493da29a1a7b749b8a2f6f 100644 (file)
@@ -326,7 +326,6 @@ void ASTUnit::CacheCodeCompletionResults() {
 
   // Make a note of the state when we performed this caching.
   NumTopLevelDeclsAtLastCompletionCache = top_level_size();
-  CacheCodeCompletionCoolDown = 15;
 }
 
 void ASTUnit::ClearCachedCompletionResults() {
@@ -824,12 +823,6 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
   }
 
   Invocation.reset(Clang.takeInvocation());
-  
-  // If we were asked to cache code-completion results and don't have any
-  // results yet, do so now.
-  if (ShouldCacheCodeCompletionResults && CachedCompletionResults.empty())
-    CacheCodeCompletionResults();
-
   return false;
   
 error:
@@ -1350,7 +1343,7 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {
 
   llvm::MemoryBuffer *OverrideMainBuffer = 0;
   if (PrecompilePreamble) {
-    PreambleRebuildCounter = 1;
+    PreambleRebuildCounter = 2;
     OverrideMainBuffer
       = getMainBufferWithPrecompiledPreamble(*Invocation);
   }
@@ -1377,6 +1370,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->CompleteTranslationUnit = CompleteTranslationUnit;
   AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
+  AST->CacheCodeCompletionCoolDown = 1;
   AST->Invocation.reset(CI);
   
   return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take();
@@ -1481,6 +1475,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->CompleteTranslationUnit = CompleteTranslationUnit;
   AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
+  AST->CacheCodeCompletionCoolDown = 1;
   AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
   AST->NumStoredDiagnosticsInPreamble = StoredDiagnostics.size();
   AST->StoredDiagnostics.swap(StoredDiagnostics);
index ae36a8e99696cb048e9eff51e32335dfc06db98a..edaf116d9ad62d2bf8e123258066e3f0b3caf48c 100644 (file)
@@ -1040,6 +1040,11 @@ int perform_code_completion(int argc, const char **argv, int timing_only) {
     fprintf(stderr, "Unable to load translation unit!\n");
     return 1;
   }
+
+  if (clang_reparseTranslationUnit(TU, 0, 0, clang_defaultReparseOptions(TU))) {
+    fprintf(stderr, "Unable to reparse translation init!\n");
+    return 1;
+  }
   
   for (I = 0; I != Repeats; ++I) {
     results = clang_codeCompleteAt(TU, filename, line, column,