]> granicus.if.org Git - clang/commitdiff
Introduce libclang-level options for C++ precompiled preambles,
authorDouglas Gregor <dgregor@apple.com>
Wed, 27 Oct 2010 17:24:53 +0000 (17:24 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 27 Oct 2010 17:24:53 +0000 (17:24 +0000)
separating out chaining precompiled preambles from non-chaining ones.

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

include/clang-c/Index.h
include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
tools/libclang/CIndex.cpp

index 7f569d288344fa37ab07c2459f65fdcdb4bddb5c..bb76c564cc948c79c182833a2b5495fab2c3599d 100644 (file)
@@ -713,7 +713,22 @@ enum CXTranslationUnit_Flags {
    * introduces some overhead to reparsing but improves the performance of
    * code-completion operations.
    */
-  CXTranslationUnit_CacheCompletionResults = 0x08
+  CXTranslationUnit_CacheCompletionResults = 0x08,
+  /**
+   * \brief Enable precompiled preambles in C++.
+   *
+   * Note: this is a *temporary* option that is available only while
+   * we are testing C++ precompiled preamble support.
+   */
+  CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
+
+  /**
+   * \brief Enabled chained precompiled preambles in C++.
+   *
+   * Note: this is a *temporary* option that is available only while
+   * we are testing C++ precompiled preamble support.
+   */
+  CXTranslationUnit_CXXChainedPCH = 0x20
 };
 
 /**
index 1e08c3a92d8e14d76386efd01b9d62481bfa2b48..d8bc35a76a80268cc8e8c951c4cd273a64bcfa74 100644 (file)
@@ -546,7 +546,9 @@ public:
                                       bool CaptureDiagnostics = false,
                                       bool PrecompilePreamble = false,
                                       bool CompleteTranslationUnit = true,
-                                      bool CacheCodeCompletionResults = false);
+                                      bool CacheCodeCompletionResults = false,
+                                      bool CXXPrecompilePreamble = false,
+                                      bool CXXChainedPCH = false);
   
   /// \brief Reparse the source files using the same command-line options that
   /// were originally used to produce this translation unit.
index e8e80647b4080eb25dcda08745914a909100caca..33abb0733167bbf2afaa8028ca7b1b5aeac22856 100644 (file)
@@ -1328,8 +1328,7 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {
   
   
   llvm::MemoryBuffer *OverrideMainBuffer = 0;
-  // FIXME: When C++ PCH is ready, allow use of it for a precompiled preamble.
-  if (PrecompilePreamble && !Invocation->getLangOpts().CPlusPlus) {
+  if (PrecompilePreamble) {
     PreambleRebuildCounter = 1;
     OverrideMainBuffer
       = getMainBufferWithPrecompiledPreamble(*Invocation);
@@ -1386,7 +1385,9 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
                                       bool CaptureDiagnostics,
                                       bool PrecompilePreamble,
                                       bool CompleteTranslationUnit,
-                                      bool CacheCodeCompletionResults) {
+                                      bool CacheCodeCompletionResults,
+                                      bool CXXPrecompilePreamble,
+                                      bool CXXChainedPCH) {
   bool CreatedDiagnosticsObject = false;
   
   if (!Diags.getPtr()) {
@@ -1457,6 +1458,16 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
   // Override the resources path.
   CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
 
+  // Check whether we should precompile the preamble and/or use chained PCH.
+  // FIXME: This is a temporary hack while we debug C++ chained PCH.
+  if (CI->getLangOpts().CPlusPlus) {
+    PrecompilePreamble = PrecompilePreamble && CXXPrecompilePreamble;
+    
+    if (PrecompilePreamble && !CXXChainedPCH &&
+        !CI->getPreprocessorOpts().ImplicitPCHInclude.empty())
+      PrecompilePreamble = false;
+  }
+  
   // Create the AST unit.
   llvm::OwningPtr<ASTUnit> AST;
   AST.reset(new ASTUnit(false));
index c1e40de7142bf6e5a529854682d65d048c4fea71..3262016c2b1214a0a7b1350a46e361a1b70478c5 100644 (file)
@@ -1972,7 +1972,8 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
 
 unsigned clang_defaultEditingTranslationUnitOptions() {
   return CXTranslationUnit_PrecompiledPreamble | 
-         CXTranslationUnit_CacheCompletionResults;
+         CXTranslationUnit_CacheCompletionResults |
+         CXTranslationUnit_CXXPrecompiledPreamble;
 }
   
 CXTranslationUnit
@@ -2020,6 +2021,10 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
     = ((options & CXTranslationUnit_Incomplete) == 0);
   bool CacheCodeCompetionResults
     = options & CXTranslationUnit_CacheCompletionResults;
+  bool CXXPrecompilePreamble
+    = options & CXTranslationUnit_CXXPrecompiledPreamble;
+  bool CXXChainedPCH
+    = options & CXTranslationUnit_CXXChainedPCH;
   
   // Configure the diagnostics.
   DiagnosticOptions DiagOpts;
@@ -2084,7 +2089,9 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
                                  /*CaptureDiagnostics=*/true,
                                  PrecompilePreamble,
                                  CompleteTranslationUnit,
-                                 CacheCodeCompetionResults));
+                                 CacheCodeCompetionResults,
+                                 CXXPrecompilePreamble,
+                                 CXXChainedPCH));
 
   if (NumErrors != Diags->getNumErrors()) {
     // Make sure to check that 'Unit' is non-NULL.