FrontendAction.cpp 21 KB

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