clang  3.7.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 (CI.getFrontendOpts().AddPluginActions.size() == 0)
145  return Consumer;
146 
147  // Make sure the non-plugin consumer is first, so that plugins can't
148  // modifiy the AST.
149  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
150  Consumers.push_back(std::move(Consumer));
151 
152  for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
153  i != e; ++i) {
154  // This is O(|plugins| * |add_plugins|), but since both numbers are
155  // way below 50 in practice, that's ok.
156  for (FrontendPluginRegistry::iterator
157  it = FrontendPluginRegistry::begin(),
158  ie = FrontendPluginRegistry::end();
159  it != ie; ++it) {
160  if (it->getName() != CI.getFrontendOpts().AddPluginActions[i])
161  continue;
162  std::unique_ptr<PluginASTAction> P = it->instantiate();
163  if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i]))
164  Consumers.push_back(P->CreateASTConsumer(CI, InFile));
165  }
166  }
167 
168  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
169 }
170 
172  const FrontendInputFile &Input) {
173  assert(!Instance && "Already processing a source file!");
174  assert(!Input.isEmpty() && "Unexpected empty filename!");
175  setCurrentInput(Input);
176  setCompilerInstance(&CI);
177 
178  StringRef InputFile = Input.getFile();
179  bool HasBegunSourceFile = false;
180  if (!BeginInvocation(CI))
181  goto failure;
182 
183  // AST files follow a very different path, since they share objects via the
184  // AST unit.
185  if (Input.getKind() == IK_AST) {
186  assert(!usesPreprocessorOnly() &&
187  "Attempt to pass AST file to preprocessor only action!");
188  assert(hasASTFileSupport() &&
189  "This action does not have AST file support!");
190 
192 
193  std::unique_ptr<ASTUnit> AST =
195  Diags, CI.getFileSystemOpts());
196 
197  if (!AST)
198  goto failure;
199 
200  // Inform the diagnostic client we are processing a source file.
201  CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
202  HasBegunSourceFile = true;
203 
204  // Set the shared objects, these are reset when we finish processing the
205  // file, otherwise the CompilerInstance will happily destroy them.
206  CI.setFileManager(&AST->getFileManager());
207  CI.setSourceManager(&AST->getSourceManager());
208  CI.setPreprocessor(&AST->getPreprocessor());
209  CI.setASTContext(&AST->getASTContext());
210 
211  setCurrentInput(Input, std::move(AST));
212 
213  // Initialize the action.
214  if (!BeginSourceFileAction(CI, InputFile))
215  goto failure;
216 
217  // Create the AST consumer.
218  CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
219  if (!CI.hasASTConsumer())
220  goto failure;
221 
222  return true;
223  }
224 
225  if (!CI.hasVirtualFileSystem()) {
228  CI.getDiagnostics()))
229  CI.setVirtualFileSystem(VFS);
230  else
231  goto failure;
232  }
233 
234  // Set up the file and source managers, if needed.
235  if (!CI.hasFileManager())
236  CI.createFileManager();
237  if (!CI.hasSourceManager())
239 
240  // IR files bypass the rest of initialization.
241  if (Input.getKind() == IK_LLVM_IR) {
242  assert(hasIRSupport() &&
243  "This action does not have IR file support!");
244 
245  // Inform the diagnostic client we are processing a source file.
246  CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
247  HasBegunSourceFile = true;
248 
249  // Initialize the action.
250  if (!BeginSourceFileAction(CI, InputFile))
251  goto failure;
252 
253  // Initialize the main file entry.
254  if (!CI.InitializeSourceManager(CurrentInput))
255  goto failure;
256 
257  return true;
258  }
259 
260  // If the implicit PCH include is actually a directory, rather than
261  // a single file, search for a suitable PCH file in that directory.
262  if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
263  FileManager &FileMgr = CI.getFileManager();
265  StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
266  std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath();
267  if (const DirectoryEntry *PCHDir = FileMgr.getDirectory(PCHInclude)) {
268  std::error_code EC;
269  SmallString<128> DirNative;
270  llvm::sys::path::native(PCHDir->getName(), DirNative);
271  bool Found = false;
272  for (llvm::sys::fs::directory_iterator Dir(DirNative, EC), DirEnd;
273  Dir != DirEnd && !EC; Dir.increment(EC)) {
274  // Check whether this is an acceptable AST file.
276  Dir->path(), FileMgr, CI.getPCHContainerReader(),
278  SpecificModuleCachePath)) {
279  PPOpts.ImplicitPCHInclude = Dir->path();
280  Found = true;
281  break;
282  }
283  }
284 
285  if (!Found) {
286  CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
287  return true;
288  }
289  }
290  }
291 
292  // Set up the preprocessor if needed. When parsing model files the
293  // preprocessor of the original source is reused.
294  if (!isModelParsingAction())
296 
297  // Inform the diagnostic client we are processing a source file.
299  &CI.getPreprocessor());
300  HasBegunSourceFile = true;
301 
302  // Initialize the action.
303  if (!BeginSourceFileAction(CI, InputFile))
304  goto failure;
305 
306  // Initialize the main file entry. It is important that this occurs after
307  // BeginSourceFileAction, which may change CurrentInput during module builds.
308  if (!CI.InitializeSourceManager(CurrentInput))
309  goto failure;
310 
311  // Create the AST context and consumer unless this is a preprocessor only
312  // action.
313  if (!usesPreprocessorOnly()) {
314  // Parsing a model file should reuse the existing ASTContext.
315  if (!isModelParsingAction())
316  CI.createASTContext();
317 
318  std::unique_ptr<ASTConsumer> Consumer =
319  CreateWrappedASTConsumer(CI, InputFile);
320  if (!Consumer)
321  goto failure;
322 
323  // FIXME: should not overwrite ASTMutationListener when parsing model files?
324  if (!isModelParsingAction())
325  CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
326 
327  if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
328  // Convert headers to PCH and chain them.
329  IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader;
330  source = createChainedIncludesSource(CI, FinalReader);
331  if (!source)
332  goto failure;
333  CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get()));
334  CI.getASTContext().setExternalSource(source);
335  } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
336  // Use PCH.
337  assert(hasPCHSupport() && "This action does not have PCH support!");
338  ASTDeserializationListener *DeserialListener =
339  Consumer->GetASTDeserializationListener();
340  bool DeleteDeserialListener = false;
342  DeserialListener = new DeserializedDeclsDumper(DeserialListener,
343  DeleteDeserialListener);
344  DeleteDeserialListener = true;
345  }
347  DeserialListener = new DeserializedDeclsChecker(
348  CI.getASTContext(),
350  DeserialListener, DeleteDeserialListener);
351  DeleteDeserialListener = true;
352  }
356  CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener,
357  DeleteDeserialListener);
358  if (!CI.getASTContext().getExternalSource())
359  goto failure;
360  }
361 
362  CI.setASTConsumer(std::move(Consumer));
363  if (!CI.hasASTConsumer())
364  goto failure;
365  }
366 
367  // Initialize built-in info as long as we aren't using an external AST
368  // source.
369  if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) {
370  Preprocessor &PP = CI.getPreprocessor();
371 
372  // If modules are enabled, create the module manager before creating
373  // any builtins, so that all declarations know that they might be
374  // extended by an external source.
375  if (CI.getLangOpts().Modules)
376  CI.createModuleManager();
377 
379  PP.getLangOpts());
380  } else {
381  // FIXME: If this is a problem, recover from it by creating a multiplex
382  // source.
383  assert((!CI.getLangOpts().Modules || CI.getModuleManager()) &&
384  "modules enabled but created an external source that "
385  "doesn't support modules");
386  }
387 
388  // If we were asked to load any module map files, do so now.
389  for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
390  if (auto *File = CI.getFileManager().getFile(Filename))
392  File, /*IsSystem*/false);
393  else
394  CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
395  }
396 
397  // If we were asked to load any module files, do so now.
398  for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
399  if (!CI.loadModuleFile(ModuleFile))
400  goto failure;
401 
402  // If there is a layout overrides file, attach an external AST source that
403  // provides the layouts from that file.
404  if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() &&
407  Override(new LayoutOverrideSource(
409  CI.getASTContext().setExternalSource(Override);
410  }
411 
412  return true;
413 
414  // If we failed, reset state since the client will not end up calling the
415  // matching EndSourceFile().
416  failure:
417  if (isCurrentFileAST()) {
418  CI.setASTContext(nullptr);
419  CI.setPreprocessor(nullptr);
420  CI.setSourceManager(nullptr);
421  CI.setFileManager(nullptr);
422  }
423 
424  if (HasBegunSourceFile)
426  CI.clearOutputFiles(/*EraseFiles=*/true);
428  setCompilerInstance(nullptr);
429  return false;
430 }
431 
434 
435  if (CI.hasFrontendTimer()) {
436  llvm::TimeRegion Timer(CI.getFrontendTimer());
437  ExecuteAction();
438  }
439  else ExecuteAction();
440 
441  // If we are supposed to rebuild the global module index, do so now unless
442  // there were any module-build failures.
443  if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
444  CI.hasPreprocessor()) {
448  }
449 
450  return true;
451 }
452 
455 
456  // Inform the diagnostic client we are done with this source file.
458 
459  // Inform the preprocessor we are done.
460  if (CI.hasPreprocessor())
462 
463  // Finalize the action.
465 
466  // Sema references the ast consumer, so reset sema first.
467  //
468  // FIXME: There is more per-file stuff we could just drop here?
469  bool DisableFree = CI.getFrontendOpts().DisableFree;
470  if (DisableFree) {
471  CI.resetAndLeakSema();
473  BuryPointer(CI.takeASTConsumer().get());
474  } else {
475  CI.setSema(nullptr);
476  CI.setASTContext(nullptr);
477  CI.setASTConsumer(nullptr);
478  }
479 
480  if (CI.getFrontendOpts().ShowStats) {
481  llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
486  llvm::errs() << "\n";
487  }
488 
489  // Cleanup the output streams, and erase the output files if instructed by the
490  // FrontendAction.
491  CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
492 
493  if (isCurrentFileAST()) {
494  if (DisableFree) {
498  } else {
499  CI.setPreprocessor(nullptr);
500  CI.setSourceManager(nullptr);
501  CI.setFileManager(nullptr);
502  }
503  }
504 
505  setCompilerInstance(nullptr);
507 }
508 
511 }
512 
513 //===----------------------------------------------------------------------===//
514 // Utility Actions
515 //===----------------------------------------------------------------------===//
516 
519  if (!CI.hasPreprocessor())
520  return;
521 
522  // FIXME: Move the truncation aspect of this into Sema, we delayed this till
523  // here so the source manager would be initialized.
524  if (hasCodeCompletionSupport() &&
527 
528  // Use a code completion consumer?
529  CodeCompleteConsumer *CompletionConsumer = nullptr;
530  if (CI.hasCodeCompletionConsumer())
531  CompletionConsumer = &CI.getCodeCompletionConsumer();
532 
533  if (!CI.hasSema())
534  CI.createSema(getTranslationUnitKind(), CompletionConsumer);
535 
538 }
539 
540 void PluginASTAction::anchor() { }
541 
542 std::unique_ptr<ASTConsumer>
544  StringRef InFile) {
545  llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
546 }
547 
548 std::unique_ptr<ASTConsumer>
550  StringRef InFile) {
551  return WrappedAction->CreateASTConsumer(CI, InFile);
552 }
554  return WrappedAction->BeginInvocation(CI);
555 }
557  StringRef Filename) {
558  WrappedAction->setCurrentInput(getCurrentInput());
559  WrappedAction->setCompilerInstance(&CI);
560  return WrappedAction->BeginSourceFileAction(CI, Filename);
561 }
563  WrappedAction->ExecuteAction();
564 }
566  WrappedAction->EndSourceFileAction();
567 }
568 
570  return WrappedAction->usesPreprocessorOnly();
571 }
573  return WrappedAction->getTranslationUnitKind();
574 }
576  return WrappedAction->hasPCHSupport();
577 }
579  return WrappedAction->hasASTFileSupport();
580 }
582  return WrappedAction->hasIRSupport();
583 }
585  return WrappedAction->hasCodeCompletionSupport();
586 }
587 
589  : WrappedAction(WrappedAction) {}
590 
void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)
Attach an external AST source to the AST context.
Definition: ASTContext.cpp:806
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()
Smart pointer class that efficiently represents Objective-C method names.
std::vector< std::vector< std::string > > AddPluginArgs
Args to pass to the additional plugins.
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
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:125
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?
Abstract base class for actions which can be performed by the frontend.
CompilerInstance & getCompilerInstance() const
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
bool hasCodeCompletionConsumer() const
virtual bool usesPreprocessorOnly() const =0
Does this action only use the preprocessor?
bool hasErrorOccurred() const
Definition: Diagnostic.h:573
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:541
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:62
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1118
bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override
Callback at the start of processing a single input.
bool InitializeSourceManager(const FrontendInputFile &Input)
virtual void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II)
An identifier was deserialized from the AST file.
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:1342
SourceManager & getSourceManager() const
Return the current source manager.
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:688
WrapperFrontendAction(FrontendAction *WrappedAction)
const FrontendInputFile & getCurrentInput() const
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:338
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:89
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:679
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, 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:651
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
bool hasPCHSupport() const override
Does this action support use with PCH?
FrontendOptions & getFrontendOpts()
DiagnosticConsumer & getDiagnosticClient() const
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:683
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
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.
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)
bool hasVirtualFileSystem() const
static ErrorCode writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, StringRef Path)
Write a global index into the given.
AnnotatingParser & P
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.
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:4161
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
bool hasIRSupport() const override
Does this action support use with IR files?
std::string getSpecificModuleCachePath()
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.
const char * getDeclKindName() const
Definition: DeclBase.cpp:87
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()
const PCHContainerReader & getPCHContainerReader() const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:864
bool Execute()
Set the source manager's main input file, and run the action.
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 StringRef getCurrentFile() const
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:685
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:84
InputKind getKind() const
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:602
void createPreprocessor(TranslationUnitKind TUKind)
virtual void TypeRead(serialization::TypeIdx Idx, QualType T)
A type was deserialized from the AST file. The ID here has the qualifier bits already removed...
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:302
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:873
bool isCurrentFileAST() const
virtual bool hasPCHSupport() const
Does this action support use with PCH?
void clearOutputFiles(bool EraseFiles)
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.
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:69
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:159
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:144
llvm::Timer & getFrontendTimer() const
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:163
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()
SourceLocation getLocation() const
Definition: DeclBase.h:372
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:1334
TargetOptions & getTargetOpts()
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:85
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.