1 //===--- FrontendAction.cpp -----------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "clang/Frontend/FrontendAction.h" 11 #include "clang/AST/ASTConsumer.h" 12 #include "clang/AST/ASTContext.h" 13 #include "clang/AST/DeclGroup.h" 14 #include "clang/Frontend/ASTUnit.h" 15 #include "clang/Frontend/CompilerInstance.h" 16 #include "clang/Frontend/FrontendDiagnostic.h" 17 #include "clang/Frontend/FrontendPluginRegistry.h" 18 #include "clang/Frontend/LayoutOverrideSource.h" 19 #include "clang/Frontend/MultiplexConsumer.h" 20 #include "clang/Frontend/Utils.h" 21 #include "clang/Lex/HeaderSearch.h" 22 #include "clang/Lex/Preprocessor.h" 23 #include "clang/Lex/PreprocessorOptions.h" 24 #include "clang/Parse/ParseAST.h" 25 #include "clang/Serialization/ASTDeserializationListener.h" 26 #include "clang/Serialization/ASTReader.h" 27 #include "clang/Serialization/GlobalModuleIndex.h" 28 #include "llvm/Support/ErrorHandling.h" 29 #include "llvm/Support/FileSystem.h" 30 #include "llvm/Support/Path.h" 31 #include "llvm/Support/Timer.h" 32 #include "llvm/Support/raw_ostream.h" 33 #include <system_error> 34 using namespace clang; 35 36 LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry) 37 38 namespace { 39 40 class DelegatingDeserializationListener : public ASTDeserializationListener { 41 ASTDeserializationListener *Previous; 42 bool DeletePrevious; 43 44 public: 45 explicit DelegatingDeserializationListener( 46 ASTDeserializationListener *Previous, bool DeletePrevious) 47 : Previous(Previous), DeletePrevious(DeletePrevious) {} 48 ~DelegatingDeserializationListener() override { 49 if (DeletePrevious) 50 delete Previous; 51 } 52 53 void ReaderInitialized(ASTReader *Reader) override { 54 if (Previous) 55 Previous->ReaderInitialized(Reader); 56 } 57 void IdentifierRead(serialization::IdentID ID, 58 IdentifierInfo *II) override { 59 if (Previous) 60 Previous->IdentifierRead(ID, II); 61 } 62 void TypeRead(serialization::TypeIdx Idx, QualType T) override { 63 if (Previous) 64 Previous->TypeRead(Idx, T); 65 } 66 void DeclRead(serialization::DeclID ID, const Decl *D) override { 67 if (Previous) 68 Previous->DeclRead(ID, D); 69 } 70 void SelectorRead(serialization::SelectorID ID, Selector Sel) override { 71 if (Previous) 72 Previous->SelectorRead(ID, Sel); 73 } 74 void MacroDefinitionRead(serialization::PreprocessedEntityID PPID, 75 MacroDefinitionRecord *MD) override { 76 if (Previous) 77 Previous->MacroDefinitionRead(PPID, MD); 78 } 79 }; 80 81 /// \brief Dumps deserialized declarations. 82 class DeserializedDeclsDumper : public DelegatingDeserializationListener { 83 public: 84 explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous, 85 bool DeletePrevious) 86 : DelegatingDeserializationListener(Previous, DeletePrevious) {} 87 88 void DeclRead(serialization::DeclID ID, const Decl *D) override { 89 llvm::outs() << "PCH DECL: " << D->getDeclKindName(); 90 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 91 llvm::outs() << " - " << *ND; 92 llvm::outs() << "\n"; 93 94 DelegatingDeserializationListener::DeclRead(ID, D); 95 } 96 }; 97 98 /// \brief Checks deserialized declarations and emits error if a name 99 /// matches one given in command-line using -error-on-deserialized-decl. 100 class DeserializedDeclsChecker : public DelegatingDeserializationListener { 101 ASTContext &Ctx; 102 std::set<std::string> NamesToCheck; 103 104 public: 105 DeserializedDeclsChecker(ASTContext &Ctx, 106 const std::set<std::string> &NamesToCheck, 107 ASTDeserializationListener *Previous, 108 bool DeletePrevious) 109 : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx), 110 NamesToCheck(NamesToCheck) {} 111 112 void DeclRead(serialization::DeclID ID, const Decl *D) override { 113 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 114 if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) { 115 unsigned DiagID 116 = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, 117 "%0 was deserialized"); 118 Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID) 119 << ND->getNameAsString(); 120 } 121 122 DelegatingDeserializationListener::DeclRead(ID, D); 123 } 124 }; 125 126 } // end anonymous namespace 127 128 FrontendAction::FrontendAction() : Instance(nullptr) {} 129 130 FrontendAction::~FrontendAction() {} 131 132 void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, 133 std::unique_ptr<ASTUnit> AST) { 134 this->CurrentInput = CurrentInput; 135 CurrentASTUnit = std::move(AST); 136 } 137 138 std::unique_ptr<ASTConsumer> 139 FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, 140 StringRef InFile) { 141 std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile); 142 if (!Consumer) 143 return nullptr; 144 145 // If there are no registered plugins we don't need to wrap the consumer 146 if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) 147 return Consumer; 148 149 // Collect the list of plugins that go before the main action (in Consumers) 150 // or after it (in AfterConsumers) 151 std::vector<std::unique_ptr<ASTConsumer>> Consumers; 152 std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers; 153 for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), 154 ie = FrontendPluginRegistry::end(); 155 it != ie; ++it) { 156 std::unique_ptr<PluginASTAction> P = it->instantiate(); 157 PluginASTAction::ActionType ActionType = P->getActionType(); 158 if (ActionType == PluginASTAction::Cmdline) { 159 // This is O(|plugins| * |add_plugins|), but since both numbers are 160 // way below 50 in practice, that's ok. 161 for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); 162 i != e; ++i) { 163 if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { 164 ActionType = PluginASTAction::AddAfterMainAction; 165 break; 166 } 167 } 168 } 169 if ((ActionType == PluginASTAction::AddBeforeMainAction || 170 ActionType == PluginASTAction::AddAfterMainAction) && 171 P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs[it->getName()])) { 172 std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile); 173 if (ActionType == PluginASTAction::AddBeforeMainAction) { 174 Consumers.push_back(std::move(PluginConsumer)); 175 } else { 176 AfterConsumers.push_back(std::move(PluginConsumer)); 177 } 178 } 179 } 180 181 // Add to Consumers the main consumer, then all the plugins that go after it 182 Consumers.push_back(std::move(Consumer)); 183 for (auto &C : AfterConsumers) { 184 Consumers.push_back(std::move(C)); 185 } 186 187 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); 188 } 189 190 bool FrontendAction::BeginSourceFile(CompilerInstance &CI, 191 const FrontendInputFile &Input) { 192 assert(!Instance && "Already processing a source file!"); 193 assert(!Input.isEmpty() && "Unexpected empty filename!"); 194 setCurrentInput(Input); 195 setCompilerInstance(&CI); 196 197 StringRef InputFile = Input.getFile(); 198 bool HasBegunSourceFile = false; 199 if (!BeginInvocation(CI)) 200 goto failure; 201 202 // AST files follow a very different path, since they share objects via the 203 // AST unit. 204 if (Input.getKind() == IK_AST) { 205 assert(!usesPreprocessorOnly() && 206 "Attempt to pass AST file to preprocessor only action!"); 207 assert(hasASTFileSupport() && 208 "This action does not have AST file support!"); 209 210 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); 211 212 std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( 213 InputFile, CI.getPCHContainerReader(), Diags, CI.getFileSystemOpts(), 214 CI.getCodeGenOpts().DebugTypeExtRefs); 215 216 if (!AST) 217 goto failure; 218 219 // Inform the diagnostic client we are processing a source file. 220 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); 221 HasBegunSourceFile = true; 222 223 // Set the shared objects, these are reset when we finish processing the 224 // file, otherwise the CompilerInstance will happily destroy them. 225 CI.setFileManager(&AST->getFileManager()); 226 CI.setSourceManager(&AST->getSourceManager()); 227 CI.setPreprocessor(AST->getPreprocessorPtr()); 228 Preprocessor &PP = CI.getPreprocessor(); 229 PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(), 230 PP.getLangOpts()); 231 CI.setASTContext(&AST->getASTContext()); 232 233 setCurrentInput(Input, std::move(AST)); 234 235 // Initialize the action. 236 if (!BeginSourceFileAction(CI, InputFile)) 237 goto failure; 238 239 // Create the AST consumer. 240 CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile)); 241 if (!CI.hasASTConsumer()) 242 goto failure; 243 244 return true; 245 } 246 247 if (!CI.hasVirtualFileSystem()) { 248 if (IntrusiveRefCntPtr<vfs::FileSystem> VFS = 249 createVFSFromCompilerInvocation(CI.getInvocation(), 250 CI.getDiagnostics())) 251 CI.setVirtualFileSystem(VFS); 252 else 253 goto failure; 254 } 255 256 // Set up the file and source managers, if needed. 257 if (!CI.hasFileManager()) 258 CI.createFileManager(); 259 if (!CI.hasSourceManager()) 260 CI.createSourceManager(CI.getFileManager()); 261 262 // IR files bypass the rest of initialization. 263 if (Input.getKind() == IK_LLVM_IR) { 264 assert(hasIRSupport() && 265 "This action does not have IR file support!"); 266 267 // Inform the diagnostic client we are processing a source file. 268 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); 269 HasBegunSourceFile = true; 270 271 // Initialize the action. 272 if (!BeginSourceFileAction(CI, InputFile)) 273 goto failure; 274 275 // Initialize the main file entry. 276 if (!CI.InitializeSourceManager(CurrentInput)) 277 goto failure; 278 279 return true; 280 } 281 282 // If the implicit PCH include is actually a directory, rather than 283 // a single file, search for a suitable PCH file in that directory. 284 if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { 285 FileManager &FileMgr = CI.getFileManager(); 286 PreprocessorOptions &PPOpts = CI.getPreprocessorOpts(); 287 StringRef PCHInclude = PPOpts.ImplicitPCHInclude; 288 std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath(); 289 if (const DirectoryEntry *PCHDir = FileMgr.getDirectory(PCHInclude)) { 290 std::error_code EC; 291 SmallString<128> DirNative; 292 llvm::sys::path::native(PCHDir->getName(), DirNative); 293 bool Found = false; 294 vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); 295 for (vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; 296 Dir != DirEnd && !EC; Dir.increment(EC)) { 297 // Check whether this is an acceptable AST file. 298 if (ASTReader::isAcceptableASTFile( 299 Dir->getName(), FileMgr, CI.getPCHContainerReader(), 300 CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(), 301 SpecificModuleCachePath)) { 302 PPOpts.ImplicitPCHInclude = Dir->getName(); 303 Found = true; 304 break; 305 } 306 } 307 308 if (!Found) { 309 CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude; 310 goto failure; 311 } 312 } 313 } 314 315 // Set up the preprocessor if needed. When parsing model files the 316 // preprocessor of the original source is reused. 317 if (!isModelParsingAction()) 318 CI.createPreprocessor(getTranslationUnitKind()); 319 320 // Inform the diagnostic client we are processing a source file. 321 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 322 &CI.getPreprocessor()); 323 HasBegunSourceFile = true; 324 325 // Initialize the action. 326 if (!BeginSourceFileAction(CI, InputFile)) 327 goto failure; 328 329 // Initialize the main file entry. It is important that this occurs after 330 // BeginSourceFileAction, which may change CurrentInput during module builds. 331 if (!CI.InitializeSourceManager(CurrentInput)) 332 goto failure; 333 334 // Create the AST context and consumer unless this is a preprocessor only 335 // action. 336 if (!usesPreprocessorOnly()) { 337 // Parsing a model file should reuse the existing ASTContext. 338 if (!isModelParsingAction()) 339 CI.createASTContext(); 340 341 std::unique_ptr<ASTConsumer> Consumer = 342 CreateWrappedASTConsumer(CI, InputFile); 343 if (!Consumer) 344 goto failure; 345 346 // FIXME: should not overwrite ASTMutationListener when parsing model files? 347 if (!isModelParsingAction()) 348 CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); 349 350 if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) { 351 // Convert headers to PCH and chain them. 352 IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader; 353 source = createChainedIncludesSource(CI, FinalReader); 354 if (!source) 355 goto failure; 356 CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get())); 357 CI.getASTContext().setExternalSource(source); 358 } else if (CI.getLangOpts().Modules || 359 !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { 360 // Use PCM or PCH. 361 assert(hasPCHSupport() && "This action does not have PCH support!"); 362 ASTDeserializationListener *DeserialListener = 363 Consumer->GetASTDeserializationListener(); 364 bool DeleteDeserialListener = false; 365 if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) { 366 DeserialListener = new DeserializedDeclsDumper(DeserialListener, 367 DeleteDeserialListener); 368 DeleteDeserialListener = true; 369 } 370 if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) { 371 DeserialListener = new DeserializedDeclsChecker( 372 CI.getASTContext(), 373 CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn, 374 DeserialListener, DeleteDeserialListener); 375 DeleteDeserialListener = true; 376 } 377 if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { 378 CI.createPCHExternalASTSource( 379 CI.getPreprocessorOpts().ImplicitPCHInclude, 380 CI.getPreprocessorOpts().DisablePCHValidation, 381 CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener, 382 DeleteDeserialListener); 383 if (!CI.getASTContext().getExternalSource()) 384 goto failure; 385 } 386 // If modules are enabled, create the module manager before creating 387 // any builtins, so that all declarations know that they might be 388 // extended by an external source. 389 if (CI.getLangOpts().Modules || !CI.hasASTContext() || 390 !CI.getASTContext().getExternalSource()) { 391 CI.createModuleManager(); 392 CI.getModuleManager()->setDeserializationListener(DeserialListener, 393 DeleteDeserialListener); 394 } 395 } 396 397 CI.setASTConsumer(std::move(Consumer)); 398 if (!CI.hasASTConsumer()) 399 goto failure; 400 } 401 402 // Initialize built-in info as long as we aren't using an external AST 403 // source. 404 if (CI.getLangOpts().Modules || !CI.hasASTContext() || 405 !CI.getASTContext().getExternalSource()) { 406 Preprocessor &PP = CI.getPreprocessor(); 407 PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(), 408 PP.getLangOpts()); 409 } else { 410 // FIXME: If this is a problem, recover from it by creating a multiplex 411 // source. 412 assert((!CI.getLangOpts().Modules || CI.getModuleManager()) && 413 "modules enabled but created an external source that " 414 "doesn't support modules"); 415 } 416 417 // If we were asked to load any module map files, do so now. 418 for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) { 419 if (auto *File = CI.getFileManager().getFile(Filename)) 420 CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile( 421 File, /*IsSystem*/false); 422 else 423 CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename; 424 } 425 426 // If we were asked to load any module files, do so now. 427 for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles) 428 if (!CI.loadModuleFile(ModuleFile)) 429 goto failure; 430 431 // If there is a layout overrides file, attach an external AST source that 432 // provides the layouts from that file. 433 if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() && 434 CI.hasASTContext() && !CI.getASTContext().getExternalSource()) { 435 IntrusiveRefCntPtr<ExternalASTSource> 436 Override(new LayoutOverrideSource( 437 CI.getFrontendOpts().OverrideRecordLayoutsFile)); 438 CI.getASTContext().setExternalSource(Override); 439 } 440 441 return true; 442 443 // If we failed, reset state since the client will not end up calling the 444 // matching EndSourceFile(). 445 failure: 446 if (isCurrentFileAST()) { 447 CI.setASTContext(nullptr); 448 CI.setPreprocessor(nullptr); 449 CI.setSourceManager(nullptr); 450 CI.setFileManager(nullptr); 451 } 452 453 if (HasBegunSourceFile) 454 CI.getDiagnosticClient().EndSourceFile(); 455 CI.clearOutputFiles(/*EraseFiles=*/true); 456 setCurrentInput(FrontendInputFile()); 457 setCompilerInstance(nullptr); 458 return false; 459 } 460 461 bool FrontendAction::Execute() { 462 CompilerInstance &CI = getCompilerInstance(); 463 464 if (CI.hasFrontendTimer()) { 465 llvm::TimeRegion Timer(CI.getFrontendTimer()); 466 ExecuteAction(); 467 } 468 else ExecuteAction(); 469 470 // If we are supposed to rebuild the global module index, do so now unless 471 // there were any module-build failures. 472 if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() && 473 CI.hasPreprocessor()) { 474 StringRef Cache = 475 CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); 476 if (!Cache.empty()) 477 GlobalModuleIndex::writeIndex(CI.getFileManager(), 478 CI.getPCHContainerReader(), Cache); 479 } 480 481 return true; 482 } 483 484 void FrontendAction::EndSourceFile() { 485 CompilerInstance &CI = getCompilerInstance(); 486 487 // Inform the diagnostic client we are done with this source file. 488 CI.getDiagnosticClient().EndSourceFile(); 489 490 // Inform the preprocessor we are done. 491 if (CI.hasPreprocessor()) 492 CI.getPreprocessor().EndSourceFile(); 493 494 // Finalize the action. 495 EndSourceFileAction(); 496 497 // Sema references the ast consumer, so reset sema first. 498 // 499 // FIXME: There is more per-file stuff we could just drop here? 500 bool DisableFree = CI.getFrontendOpts().DisableFree; 501 if (DisableFree) { 502 CI.resetAndLeakSema(); 503 CI.resetAndLeakASTContext(); 504 BuryPointer(CI.takeASTConsumer().get()); 505 } else { 506 CI.setSema(nullptr); 507 CI.setASTContext(nullptr); 508 CI.setASTConsumer(nullptr); 509 } 510 511 if (CI.getFrontendOpts().ShowStats) { 512 llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; 513 CI.getPreprocessor().PrintStats(); 514 CI.getPreprocessor().getIdentifierTable().PrintStats(); 515 CI.getPreprocessor().getHeaderSearchInfo().PrintStats(); 516 CI.getSourceManager().PrintStats(); 517 llvm::errs() << "\n"; 518 } 519 520 // Cleanup the output streams, and erase the output files if instructed by the 521 // FrontendAction. 522 CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles()); 523 524 if (isCurrentFileAST()) { 525 if (DisableFree) { 526 CI.resetAndLeakPreprocessor(); 527 CI.resetAndLeakSourceManager(); 528 CI.resetAndLeakFileManager(); 529 } else { 530 CI.setPreprocessor(nullptr); 531 CI.setSourceManager(nullptr); 532 CI.setFileManager(nullptr); 533 } 534 } 535 536 setCompilerInstance(nullptr); 537 setCurrentInput(FrontendInputFile()); 538 } 539 540 bool FrontendAction::shouldEraseOutputFiles() { 541 return getCompilerInstance().getDiagnostics().hasErrorOccurred(); 542 } 543 544 //===----------------------------------------------------------------------===// 545 // Utility Actions 546 //===----------------------------------------------------------------------===// 547 548 void ASTFrontendAction::ExecuteAction() { 549 CompilerInstance &CI = getCompilerInstance(); 550 if (!CI.hasPreprocessor()) 551 return; 552 553 // FIXME: Move the truncation aspect of this into Sema, we delayed this till 554 // here so the source manager would be initialized. 555 if (hasCodeCompletionSupport() && 556 !CI.getFrontendOpts().CodeCompletionAt.FileName.empty()) 557 CI.createCodeCompletionConsumer(); 558 559 // Use a code completion consumer? 560 CodeCompleteConsumer *CompletionConsumer = nullptr; 561 if (CI.hasCodeCompletionConsumer()) 562 CompletionConsumer = &CI.getCodeCompletionConsumer(); 563 564 if (!CI.hasSema()) 565 CI.createSema(getTranslationUnitKind(), CompletionConsumer); 566 567 ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats, 568 CI.getFrontendOpts().SkipFunctionBodies); 569 } 570 571 void PluginASTAction::anchor() { } 572 573 std::unique_ptr<ASTConsumer> 574 PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, 575 StringRef InFile) { 576 llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); 577 } 578 579 std::unique_ptr<ASTConsumer> 580 WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, 581 StringRef InFile) { 582 return WrappedAction->CreateASTConsumer(CI, InFile); 583 } 584 bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { 585 return WrappedAction->BeginInvocation(CI); 586 } 587 bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI, 588 StringRef Filename) { 589 WrappedAction->setCurrentInput(getCurrentInput()); 590 WrappedAction->setCompilerInstance(&CI); 591 auto Ret = WrappedAction->BeginSourceFileAction(CI, Filename); 592 // BeginSourceFileAction may change CurrentInput, e.g. during module builds. 593 setCurrentInput(WrappedAction->getCurrentInput()); 594 return Ret; 595 } 596 void WrapperFrontendAction::ExecuteAction() { 597 WrappedAction->ExecuteAction(); 598 } 599 void WrapperFrontendAction::EndSourceFileAction() { 600 WrappedAction->EndSourceFileAction(); 601 } 602 603 bool WrapperFrontendAction::usesPreprocessorOnly() const { 604 return WrappedAction->usesPreprocessorOnly(); 605 } 606 TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() { 607 return WrappedAction->getTranslationUnitKind(); 608 } 609 bool WrapperFrontendAction::hasPCHSupport() const { 610 return WrappedAction->hasPCHSupport(); 611 } 612 bool WrapperFrontendAction::hasASTFileSupport() const { 613 return WrappedAction->hasASTFileSupport(); 614 } 615 bool WrapperFrontendAction::hasIRSupport() const { 616 return WrappedAction->hasIRSupport(); 617 } 618 bool WrapperFrontendAction::hasCodeCompletionSupport() const { 619 return WrappedAction->hasCodeCompletionSupport(); 620 } 621 622 WrapperFrontendAction::WrapperFrontendAction( 623 std::unique_ptr<FrontendAction> WrappedAction) 624 : WrappedAction(std::move(WrappedAction)) {} 625 626