diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-28 04:56:00 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-28 04:56:00 +0000 |
commit | 6f3ce979a7748fd117e6473d6272b16d643b6262 (patch) | |
tree | de0942a2ca83386321511f21b544289d0862330f /lib/Frontend/ASTUnit.cpp | |
parent | 991bf49f68e8caeb900dd9738712b861073363d9 (diff) |
[libclang] Indexing API: If the client requested to get a CXTranslationUnit after
indexing, honor all the TU options.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145229 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | lib/Frontend/ASTUnit.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 2419d27941..8606f68655 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -27,6 +27,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" +#include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/Utils.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/ASTWriter.h" @@ -1649,21 +1650,33 @@ ASTUnit *ASTUnit::create(CompilerInvocation *CI, ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI, llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags, ASTFrontendAction *Action, - ASTUnit *Unit) { + ASTUnit *Unit, + bool Persistent, + StringRef ResourceFilesPath, + bool OnlyLocalDecls, + bool CaptureDiagnostics, + bool PrecompilePreamble, + bool CacheCodeCompletionResults) { assert(CI && "A CompilerInvocation is required"); llvm::OwningPtr<ASTUnit> OwnAST; ASTUnit *AST = Unit; if (!AST) { // Create the AST unit. - OwnAST.reset(create(CI, Diags)); + OwnAST.reset(create(CI, Diags, CaptureDiagnostics)); AST = OwnAST.get(); } - AST->OnlyLocalDecls = false; - AST->CaptureDiagnostics = false; + if (!ResourceFilesPath.empty()) { + // Override the resources path. + CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath; + } + AST->OnlyLocalDecls = OnlyLocalDecls; + AST->CaptureDiagnostics = CaptureDiagnostics; + if (PrecompilePreamble) + AST->PreambleRebuildCounter = 2; AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete; - AST->ShouldCacheCodeCompletionResults = false; + AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit> @@ -1742,7 +1755,17 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI, Clang->getFrontendOpts().Inputs[0].second, Clang->getFrontendOpts().Inputs[0].first)) return 0; - + + if (Persistent && !TrackerAct) { + Clang->getPreprocessor().addPPCallbacks( + new MacroDefinitionTrackerPPCallbacks(AST->getCurrentTopLevelHashValue())); + std::vector<ASTConsumer*> Consumers; + if (Clang->hasASTConsumer()) + Consumers.push_back(Clang->takeASTConsumer()); + Consumers.push_back(new TopLevelDeclTrackerConsumer(*AST, + AST->getCurrentTopLevelHashValue())); + Clang->setASTConsumer(new MultiplexConsumer(Consumers)); + } Act->Execute(); // Steal the created target, context, and preprocessor. |