diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-18 20:39:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-18 20:39:29 +0000 |
commit | 293534b1a50f7489f6d6e2c24aeccc8e7db88c05 (patch) | |
tree | dc32e59f7a8de096b84d1202bbc73093e1747083 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 35b0eaf23d5fe90ad9a04f76488c212cb6f31210 (diff) | |
download | llvm-293534b1a50f7489f6d6e2c24aeccc8e7db88c05.zip llvm-293534b1a50f7489f6d6e2c24aeccc8e7db88c05.tar.gz llvm-293534b1a50f7489f6d6e2c24aeccc8e7db88c05.tar.bz2 |
Initialize the AST consumer as soon as we have both an ASTConsumer and an
ASTContext. Fixes some cases where we could previously initialize the AST
consumer more than once.
llvm-svn: 245346
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5079353..dfd71af 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -96,7 +96,12 @@ void CompilerInstance::setSourceManager(SourceManager *Value) { void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; } -void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; } +void CompilerInstance::setASTContext(ASTContext *Value) { + Context = Value; + + if (Context && Consumer) + getASTConsumer().Initialize(getASTContext()); +} void CompilerInstance::setSema(Sema *S) { TheSema.reset(S); @@ -104,6 +109,9 @@ void CompilerInstance::setSema(Sema *S) { void CompilerInstance::setASTConsumer(std::unique_ptr<ASTConsumer> Value) { Consumer = std::move(Value); + + if (Context && Consumer) + getASTConsumer().Initialize(getASTContext()); } void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { @@ -385,10 +393,11 @@ std::string CompilerInstance::getSpecificModuleCachePath() { void CompilerInstance::createASTContext() { Preprocessor &PP = getPreprocessor(); - Context = new ASTContext(getLangOpts(), PP.getSourceManager(), - PP.getIdentifierTable(), PP.getSelectorTable(), - PP.getBuiltinInfo()); + auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(), + PP.getIdentifierTable(), PP.getSelectorTable(), + PP.getBuiltinInfo()); Context->InitBuiltinTypes(getTarget()); + setASTContext(Context); } // ExternalASTSource @@ -1249,7 +1258,7 @@ void CompilerInstance::createModuleManager() { ReadTimer = llvm::make_unique<llvm::Timer>("Reading modules", *FrontendTimerGroup); ModuleManager = new ASTReader( - getPreprocessor(), *Context, getPCHContainerReader(), + getPreprocessor(), getASTContext(), getPCHContainerReader(), Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, /*AllowASTWithCompilerErrors=*/false, /*AllowConfigurationMismatch=*/false, @@ -1265,10 +1274,8 @@ void CompilerInstance::createModuleManager() { getASTContext().setExternalSource(ModuleManager); if (hasSema()) ModuleManager->InitializeSema(getSema()); - if (hasASTConsumer()) { - getASTConsumer().Initialize(getASTContext()); + if (hasASTConsumer()) ModuleManager->StartTranslationUnit(&getASTConsumer()); - } if (TheDependencyFileGenerator) TheDependencyFileGenerator->AttachToASTReader(*ModuleManager); |