clang  3.9.0
FrontendAction.cpp
Go to the documentation of this file.
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 
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/DeclGroup.h"
14 #include "clang/Frontend/ASTUnit.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"
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 {
41  bool DeletePrevious;
42 
43 public:
44  explicit DelegatingDeserializationListener(
45  ASTDeserializationListener *Previous, bool DeletePrevious)
46  : Previous(Previous), DeletePrevious(DeletePrevious) {}
47  ~DelegatingDeserializationListener() override {
48  if (DeletePrevious)
49  delete Previous;
50  }
51 
52  void ReaderInitialized(ASTReader *Reader) override {
53  if (Previous)
54  Previous->ReaderInitialized(Reader);
55  }
56  void IdentifierRead(serialization::IdentID ID,
57  IdentifierInfo *II) override {
58  if (Previous)
59  Previous->IdentifierRead(ID, II);
60  }
61  void TypeRead(serialization::TypeIdx Idx, QualType T) override {
62  if (Previous)
63  Previous->TypeRead(Idx, T);
64  }
65  void DeclRead(serialization::DeclID ID, const Decl *D) override {
66  if (Previous)
67  Previous->DeclRead(ID, D);
68  }
69  void SelectorRead(serialization::SelectorID ID, Selector Sel) override {
70  if (Previous)
71  Previous->SelectorRead(ID, Sel);
72  }
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:
83  explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous,
84  bool DeletePrevious)
85  : DelegatingDeserializationListener(Previous, DeletePrevious) {}
86 
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:
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 
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
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 
127 FrontendAction::FrontendAction() : Instance(nullptr) {}
128 
130 
132  std::unique_ptr<ASTUnit> AST) {
133  this->CurrentInput = CurrentInput;
134  CurrentASTUnit = std::move(AST);
135 }
136 
137 std::unique_ptr<ASTConsumer>
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
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;
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]) {
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 
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 
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()) {
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())
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();
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.
294  Dir->path(), FileMgr, CI.getPCHContainerReader(),
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())
314 
315  // Inform the diagnostic client we are processing a source file.
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;
360  DeserialListener = new DeserializedDeclsDumper(DeserialListener,
361  DeleteDeserialListener);
362  DeleteDeserialListener = true;
363  }
365  DeserialListener = new DeserializedDeclsChecker(
366  CI.getASTContext(),
368  DeserialListener, DeleteDeserialListener);
369  DeleteDeserialListener = true;
370  }
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 
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))
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() &&
425  Override(new LayoutOverrideSource(
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)
444  CI.clearOutputFiles(/*EraseFiles=*/true);
446  setCompilerInstance(nullptr);
447  return false;
448 }
449 
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 =
465  if (!Cache.empty())
468  }
469 
470  return true;
471 }
472 
475 
476  // Inform the diagnostic client we are done with this source file.
478 
479  // Inform the preprocessor we are done.
480  if (CI.hasPreprocessor())
482 
483  // Finalize the action.
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();
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";
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) {
518  } else {
519  CI.setPreprocessor(nullptr);
520  CI.setSourceManager(nullptr);
521  CI.setFileManager(nullptr);
522  }
523  }
524 
525  setCompilerInstance(nullptr);
527 }
528 
531 }
532 
533 //===----------------------------------------------------------------------===//
534 // Utility Actions
535 //===----------------------------------------------------------------------===//
536 
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() &&
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 
558 }
559 
560 void PluginASTAction::anchor() { }
561 
562 std::unique_ptr<ASTConsumer>
564  StringRef InFile) {
565  llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
566 }
567 
568 std::unique_ptr<ASTConsumer>
570  StringRef InFile) {
571  return WrappedAction->CreateASTConsumer(CI, InFile);
572 }
574  return WrappedAction->BeginInvocation(CI);
575 }
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 }
586  WrappedAction->ExecuteAction();
587 }
589  WrappedAction->EndSourceFileAction();
590 }
591 
593  return WrappedAction->usesPreprocessorOnly();
594 }
596  return WrappedAction->getTranslationUnitKind();
597 }
599  return WrappedAction->hasPCHSupport();
600 }
602  return WrappedAction->hasASTFileSupport();
603 }
605  return WrappedAction->hasIRSupport();
606 }
608  return WrappedAction->hasCodeCompletionSupport();
609 }
610 
612  std::unique_ptr<FrontendAction> WrappedAction)
613  : WrappedAction(std::move(WrappedAction)) {}
614 
void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)
Attach an external AST source to the AST context.
Definition: ASTContext.cpp:817
Defines the clang::ASTContext interface.
virtual bool isModelParsingAction() const
Is this action invoked on a model file?
LangOptions & getLangOpts()
ASTContext & getASTContext() const
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:598
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:117
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
The ChainedIncludesSource class converts headers to chained PCHs in memory, mainly for testing...
void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:123
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
CompilerInstance & getCompilerInstance() const
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
bool hasCodeCompletionConsumer() const
StringRef P
virtual bool usesPreprocessorOnly() const =0
Does this action only use the preprocessor?
bool hasErrorOccurred() const
Definition: Diagnostic.h:580
TypePropertyCache< Private > Cache
Definition: Type.cpp:3282
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Provide a default implementation which returns aborts; this method should never be called by Frontend...
FullSourceLoc getFullLoc(SourceLocation Loc) const
Definition: ASTContext.h:612
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:63
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1124
bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override
Callback at the start of processing a single input.
bool InitializeSourceManager(const FrontendInputFile &Input)
InitializeSourceManager - Initialize the source manager to set InputFile as the main file...
virtual void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II)
An identifier was deserialized from the AST file.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
void setModuleManager(IntrusiveRefCntPtr< ASTReader > Reader)
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1347
SourceManager & getSourceManager() const
Return the current source manager.
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:700
iterator begin() const
Definition: Type.h:4235
One of these records is kept for each identifier that is lexed.
const FrontendInputFile & getCurrentInput() const
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:322
virtual void ReaderInitialized(ASTReader *Reader)
The ASTReader was initialized.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
Record the location of a macro definition.
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
void createFileManager()
Create the file manager and replace any existing one with it.
void createSourceManager(FileManager &FileMgr)
Create the source manager and replace any existing one with it.
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:690
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
CodeGenOptions & getCodeGenOpts()
Execute the action before the main action.
bool hasPCHSupport() const override
Does this action support use with PCH?
Action is determined by the cc1 command-line.
unsigned ShowStats
Show frontend performance metrics and statistics.
FrontendOptions & getFrontendOpts()
DiagnosticConsumer & getDiagnosticClient() const
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:695
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value...
unsigned SkipFunctionBodies
Emit ARC errors even if the migrator can fix them.
IntrusiveRefCntPtr< ASTReader > getModuleManager() const
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
iterator end() const
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename)
Callback at the start of processing a single input.
bool DisablePCHValidation
When true, disables most of the normal validation performed on precompiled headers.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
DiagnosticsEngine & getDiagnostics() const
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel)
A selector was read from the AST file.
void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
Create an external AST source to read a PCH file and attach it to the AST context.
bool hasVirtualFileSystem() const
static ErrorCode writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, StringRef Path)
Write a global index into the given.
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
virtual void DeclRead(serialization::DeclID ID, const Decl *D)
A decl was deserialized from the AST file.
void setPreprocessor(Preprocessor *Value)
Replace the current preprocessor.
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
const DirectoryEntry * getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
void setVirtualFileSystem(IntrusiveRefCntPtr< vfs::FileSystem > FS)
Replace the current virtual file system.
StringRef Filename
Definition: Format.cpp:1194
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
void setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, std::string ExistingModuleCachePath)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
Definition: ASTReader.cpp:4402
bool hasIRSupport() const override
Does this action support use with IR files?
std::string getSpecificModuleCachePath()
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
StateNode * Previous
std::set< std::string > DeserializedPCHDeclsToErrorOn
This is a set of names for decls that we do not want to be deserialized, and we emit an error if they...
bool loadModuleMapFile(const FileEntry *File, bool IsSystem)
Read the contents of the given module map file.
Defines the clang::Preprocessor interface.
IntrusiveRefCntPtr< vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
void createASTContext()
Create the AST context.
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
void setSema(Sema *S)
Replace the current Sema; the compiler instance takes ownership of S.
virtual bool hasIRSupport() const
Does this action support use with IR files?
An input file for the front end.
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile)=0
Create the AST consumer object for this action, if supported.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
virtual void ExecuteAction()=0
Callback to run the program action, using the initialized compiler instance.
void EndSourceFileAction() override
Callback at the end of processing a single input.
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
bool hasSourceManager() const
FileSystemOptions & getFileSystemOpts()
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:943
bool Execute()
Set the source manager's main input file, and run the action.
const TemplateArgument * iterator
Definition: Type.h:4233
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input. ...
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
virtual void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinitionRecord *MD)
A macro definition was read from the AST file.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
const std::string ID
const StringRef getCurrentFile() const
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:697
void ParseAST(Preprocessor &pp, ASTConsumer *C, ASTContext &Ctx, bool PrintStats=false, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr, bool SkipFunctionBodies=false)
Parse the entire file specified, notifying the ASTConsumer as the file is parsed. ...
Definition: ParseAST.cpp:98
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Definition: Builtins.cpp:81
InputKind getKind() const
std::unordered_map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
Execute the action after the main action.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:609
void createPreprocessor(TranslationUnitKind TUKind)
Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...
virtual void TypeRead(serialization::TypeIdx Idx, QualType T)
A type was deserialized from the AST file.
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
Abstract interface for a consumer of code-completion information.
bool hasFrontendTimer() const
StringRef getFile() const
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:312
FileManager & getFileManager() const
Return the current file manager to the caller.
bool loadModuleFile(StringRef FileName)
void setASTMutationListener(ASTMutationListener *Listener)
Attach an AST mutation listener to the AST context.
Definition: ASTContext.h:952
bool isCurrentFileAST() const
virtual bool hasPCHSupport() const
Does this action support use with PCH?
void clearOutputFiles(bool EraseFiles)
clearOutputFiles - Clear the output file list.
void BuryPointer(const void *Ptr)
bool hasASTFileSupport() const override
Does this action support use with AST files?
void setCompilerInstance(CompilerInstance *Value)
void PrintStats() const
Print some statistics to stderr that indicate how well the hashing is doing.
CodeCompleteConsumer & getCodeCompletionConsumer() const
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:40
unsigned DisableFree
Disable memory freeing on exit.
The type-property cache.
Definition: Type.cpp:3242
An external AST source that overrides the layout of a specified set of record types.
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:157
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:142
llvm::Timer & getFrontendTimer() const
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:172
const StringRef Input
void PrintStats() const
Print statistics to stderr.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1339
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, bool CaptureDiagnostics=false, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:652
TargetOptions & getTargetOpts()
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:83
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:97
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.