From 2b6b257f4e5503a7a2675bdb8735693db769f75c Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 23 Jul 2016 20:44:14 +0000 Subject: Vendor import of clang release_39 branch r276489: https://llvm.org/svn/llvm-project/cfe/branches/release_39@276489 --- lib/FrontendTool/ExecuteCompilerInvocation.cpp | 105 +++++++++++++++---------- 1 file changed, 62 insertions(+), 43 deletions(-) (limited to 'lib/FrontendTool/ExecuteCompilerInvocation.cpp') diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 79cf0049a7b20..509c326d1597a 100644 --- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -31,33 +31,34 @@ using namespace clang; using namespace llvm::opt; -static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { +static std::unique_ptr +CreateFrontendBaseAction(CompilerInstance &CI) { using namespace clang::frontend; StringRef Action("unknown"); (void)Action; switch (CI.getFrontendOpts().ProgramAction) { - case ASTDeclList: return new ASTDeclListAction(); - case ASTDump: return new ASTDumpAction(); - case ASTPrint: return new ASTPrintAction(); - case ASTView: return new ASTViewAction(); - case DumpRawTokens: return new DumpRawTokensAction(); - case DumpTokens: return new DumpTokensAction(); - case EmitAssembly: return new EmitAssemblyAction(); - case EmitBC: return new EmitBCAction(); - case EmitHTML: return new HTMLPrintAction(); - case EmitLLVM: return new EmitLLVMAction(); - case EmitLLVMOnly: return new EmitLLVMOnlyAction(); - case EmitCodeGenOnly: return new EmitCodeGenOnlyAction(); - case EmitObj: return new EmitObjAction(); - case FixIt: return new FixItAction(); - case GenerateModule: return new GenerateModuleAction; - case GeneratePCH: return new GeneratePCHAction; - case GeneratePTH: return new GeneratePTHAction(); - case InitOnly: return new InitOnlyAction(); - case ParseSyntaxOnly: return new SyntaxOnlyAction(); - case ModuleFileInfo: return new DumpModuleInfoAction(); - case VerifyPCH: return new VerifyPCHAction(); + case ASTDeclList: return llvm::make_unique(); + case ASTDump: return llvm::make_unique(); + case ASTPrint: return llvm::make_unique(); + case ASTView: return llvm::make_unique(); + case DumpRawTokens: return llvm::make_unique(); + case DumpTokens: return llvm::make_unique(); + case EmitAssembly: return llvm::make_unique(); + case EmitBC: return llvm::make_unique(); + case EmitHTML: return llvm::make_unique(); + case EmitLLVM: return llvm::make_unique(); + case EmitLLVMOnly: return llvm::make_unique(); + case EmitCodeGenOnly: return llvm::make_unique(); + case EmitObj: return llvm::make_unique(); + case FixIt: return llvm::make_unique(); + case GenerateModule: return llvm::make_unique(); + case GeneratePCH: return llvm::make_unique(); + case GeneratePTH: return llvm::make_unique(); + case InitOnly: return llvm::make_unique(); + case ParseSyntaxOnly: return llvm::make_unique(); + case ModuleFileInfo: return llvm::make_unique(); + case VerifyPCH: return llvm::make_unique(); case PluginAction: { for (FrontendPluginRegistry::iterator it = @@ -65,9 +66,11 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { it != ie; ++it) { if (it->getName() == CI.getFrontendOpts().ActionName) { std::unique_ptr P(it->instantiate()); - if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs)) + if ((P->getActionType() != PluginASTAction::ReplaceAction && + P->getActionType() != PluginASTAction::Cmdline) || + !P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs[it->getName()])) return nullptr; - return P.release(); + return std::move(P); } } @@ -76,32 +79,33 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { return nullptr; } - case PrintDeclContext: return new DeclContextPrintAction(); - case PrintPreamble: return new PrintPreambleAction(); + case PrintDeclContext: return llvm::make_unique(); + case PrintPreamble: return llvm::make_unique(); case PrintPreprocessedInput: { if (CI.getPreprocessorOutputOpts().RewriteIncludes) - return new RewriteIncludesAction(); - return new PrintPreprocessedAction(); + return llvm::make_unique(); + return llvm::make_unique(); } - case RewriteMacros: return new RewriteMacrosAction(); - case RewriteTest: return new RewriteTestAction(); + case RewriteMacros: return llvm::make_unique(); + case RewriteTest: return llvm::make_unique(); #ifdef CLANG_ENABLE_OBJC_REWRITER - case RewriteObjC: return new RewriteObjCAction(); + case RewriteObjC: return llvm::make_unique(); #else case RewriteObjC: Action = "RewriteObjC"; break; #endif #ifdef CLANG_ENABLE_ARCMT - case MigrateSource: return new arcmt::MigrateSourceAction(); + case MigrateSource: + return llvm::make_unique(); #else case MigrateSource: Action = "MigrateSource"; break; #endif #ifdef CLANG_ENABLE_STATIC_ANALYZER - case RunAnalysis: return new ento::AnalysisAction(); + case RunAnalysis: return llvm::make_unique(); #else case RunAnalysis: Action = "RunAnalysis"; break; #endif - case RunPreprocessorOnly: return new PreprocessOnlyAction(); + case RunPreprocessorOnly: return llvm::make_unique(); } #if !defined(CLANG_ENABLE_ARCMT) || !defined(CLANG_ENABLE_STATIC_ANALYZER) \ @@ -113,16 +117,17 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { #endif } -static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { +static std::unique_ptr +CreateFrontendAction(CompilerInstance &CI) { // Create the underlying action. - FrontendAction *Act = CreateFrontendBaseAction(CI); + std::unique_ptr Act = CreateFrontendBaseAction(CI); if (!Act) return nullptr; const FrontendOptions &FEOpts = CI.getFrontendOpts(); if (FEOpts.FixAndRecompile) { - Act = new FixItRecompile(Act); + Act = llvm::make_unique(std::move(Act)); } #ifdef CLANG_ENABLE_ARCMT @@ -133,13 +138,13 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { case FrontendOptions::ARCMT_None: break; case FrontendOptions::ARCMT_Check: - Act = new arcmt::CheckAction(Act); + Act = llvm::make_unique(std::move(Act)); break; case FrontendOptions::ARCMT_Modify: - Act = new arcmt::ModifyAction(Act); + Act = llvm::make_unique(std::move(Act)); break; case FrontendOptions::ARCMT_Migrate: - Act = new arcmt::MigrateAction(Act, + Act = llvm::make_unique(std::move(Act), FEOpts.MTMigrateDir, FEOpts.ARCMTMigrateReportOut, FEOpts.ARCMTMigrateEmitARCErrors); @@ -147,8 +152,9 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { } if (FEOpts.ObjCMTAction != FrontendOptions::ObjCMT_None) { - Act = new arcmt::ObjCMigrateAction(Act, FEOpts.MTMigrateDir, - FEOpts.ObjCMTAction); + Act = llvm::make_unique(std::move(Act), + FEOpts.MTMigrateDir, + FEOpts.ObjCMTAction); } } #endif @@ -156,7 +162,8 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { // If there are any AST files to merge, create a frontend action // adaptor to perform the merge. if (!FEOpts.ASTMergeFiles.empty()) - Act = new ASTMergeAction(Act, FEOpts.ASTMergeFiles); + Act = llvm::make_unique(std::move(Act), + FEOpts.ASTMergeFiles); return Act; } @@ -189,6 +196,18 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) { << Path << Error; } + // Check if any of the loaded plugins replaces the main AST action + for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), + ie = FrontendPluginRegistry::end(); + it != ie; ++it) { + std::unique_ptr P(it->instantiate()); + if (P->getActionType() == PluginASTAction::ReplaceAction) { + Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction; + Clang->getFrontendOpts().ActionName = it->getName(); + break; + } + } + // Honor -mllvm. // // FIXME: Remove this, one day. -- cgit v1.2.3