diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp b/contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp index 7910179..c81c81a 100644 --- a/contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp +++ b/contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp @@ -129,14 +129,15 @@ FrontendAction::FrontendAction() : Instance(nullptr) {} FrontendAction::~FrontendAction() {} void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, - ASTUnit *AST) { + std::unique_ptr<ASTUnit> AST) { this->CurrentInput = CurrentInput; - CurrentASTUnit.reset(AST); + CurrentASTUnit = std::move(AST); } -ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, - StringRef InFile) { - ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); +std::unique_ptr<ASTConsumer> +FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, + StringRef InFile) { + std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile); if (!Consumer) return nullptr; @@ -145,7 +146,8 @@ ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, // Make sure the non-plugin consumer is first, so that plugins can't // modifiy the AST. - std::vector<ASTConsumer*> Consumers(1, Consumer); + std::vector<std::unique_ptr<ASTConsumer>> Consumers; + Consumers.push_back(std::move(Consumer)); for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); i != e; ++i) { @@ -155,16 +157,15 @@ ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, it = FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); it != ie; ++it) { - if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { - std::unique_ptr<PluginASTAction> P(it->instantiate()); - FrontendAction* c = P.get(); - if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) - Consumers.push_back(c->CreateASTConsumer(CI, InFile)); - } + if (it->getName() != CI.getFrontendOpts().AddPluginActions[i]) + continue; + std::unique_ptr<PluginASTAction> P = it->instantiate(); + if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) + Consumers.push_back(P->CreateASTConsumer(CI, InFile)); } } - return new MultiplexConsumer(Consumers); + return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } bool FrontendAction::BeginSourceFile(CompilerInstance &CI, @@ -189,13 +190,12 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); - ASTUnit *AST = ASTUnit::LoadFromASTFile(InputFile, Diags, - CI.getFileSystemOpts()); + std::unique_ptr<ASTUnit> AST = + ASTUnit::LoadFromASTFile(InputFile, Diags, CI.getFileSystemOpts()); + if (!AST) goto failure; - setCurrentInput(Input, AST); - // Inform the diagnostic client we are processing a source file. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); HasBegunSourceFile = true; @@ -207,6 +207,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, CI.setPreprocessor(&AST->getPreprocessor()); CI.setASTContext(&AST->getASTContext()); + setCurrentInput(Input, std::move(AST)); + // Initialize the action. if (!BeginSourceFileAction(CI, InputFile)) goto failure; @@ -285,8 +287,10 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, } } - // Set up the preprocessor. - CI.createPreprocessor(getTranslationUnitKind()); + // Set up the preprocessor if needed. When parsing model files the + // preprocessor of the original source is reused. + if (!isModelParsingAction()) + CI.createPreprocessor(getTranslationUnitKind()); // Inform the diagnostic client we are processing a source file. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), @@ -305,15 +309,19 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, // Create the AST context and consumer unless this is a preprocessor only // action. if (!usesPreprocessorOnly()) { - CI.createASTContext(); + // Parsing a model file should reuse the existing ASTContext. + if (!isModelParsingAction()) + CI.createASTContext(); - std::unique_ptr<ASTConsumer> Consumer( - CreateWrappedASTConsumer(CI, InputFile)); + std::unique_ptr<ASTConsumer> Consumer = + CreateWrappedASTConsumer(CI, InputFile); if (!Consumer) goto failure; - CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); - + // FIXME: should not overwrite ASTMutationListener when parsing model files? + if (!isModelParsingAction()) + CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); + if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) { // Convert headers to PCH and chain them. IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader; @@ -349,7 +357,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, goto failure; } - CI.setASTConsumer(Consumer.release()); + CI.setASTConsumer(std::move(Consumer)); if (!CI.hasASTConsumer()) goto failure; } @@ -375,6 +383,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, "doesn't support modules"); } + // If we were asked to load any module files, do so now. + for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles) + if (!CI.loadModuleFile(ModuleFile)) + goto failure; + // If there is a layout overrides file, attach an external AST source that // provides the layouts from that file. if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() && @@ -432,6 +445,10 @@ void FrontendAction::EndSourceFile() { // Inform the diagnostic client we are done with this source file. CI.getDiagnosticClient().EndSourceFile(); + // Inform the preprocessor we are done. + if (CI.hasPreprocessor()) + CI.getPreprocessor().EndSourceFile(); + // Finalize the action. EndSourceFileAction(); @@ -444,7 +461,7 @@ void FrontendAction::EndSourceFile() { CI.resetAndLeakSema(); CI.resetAndLeakASTContext(); } - BuryPointer(CI.takeASTConsumer()); + BuryPointer(CI.takeASTConsumer().get()); } else { if (!isCurrentFileAST()) { CI.setSema(nullptr); @@ -453,10 +470,6 @@ void FrontendAction::EndSourceFile() { CI.setASTConsumer(nullptr); } - // Inform the preprocessor we are done. - if (CI.hasPreprocessor()) - CI.getPreprocessor().EndSourceFile(); - if (CI.getFrontendOpts().ShowStats) { llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; CI.getPreprocessor().PrintStats(); @@ -516,14 +529,15 @@ void ASTFrontendAction::ExecuteAction() { void PluginASTAction::anchor() { } -ASTConsumer * +std::unique_ptr<ASTConsumer> PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); } -ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr<ASTConsumer> +WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { return WrappedAction->CreateASTConsumer(CI, InFile); } bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { |