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