clang  15.0.0git
FrontendAction.cpp
Go to the documentation of this file.
1 //===--- FrontendAction.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "clang/AST/ASTConsumer.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/AST/DeclGroup.h"
13 #include "clang/Basic/Builtins.h"
15 #include "clang/Frontend/ASTUnit.h"
21 #include "clang/Frontend/Utils.h"
22 #include "clang/Lex/HeaderSearch.h"
24 #include "clang/Lex/Preprocessor.h"
26 #include "clang/Parse/ParseAST.h"
31 #include "llvm/ADT/ScopeExit.h"
32 #include "llvm/Support/BuryPointer.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/FileSystem.h"
35 #include "llvm/Support/Path.h"
36 #include "llvm/Support/Timer.h"
37 #include "llvm/Support/raw_ostream.h"
38 #include <system_error>
39 using namespace clang;
40 
41 LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
42 
43 namespace {
44 
45 class DelegatingDeserializationListener : public ASTDeserializationListener {
47  bool DeletePrevious;
48 
49 public:
50  explicit DelegatingDeserializationListener(
51  ASTDeserializationListener *Previous, bool DeletePrevious)
52  : Previous(Previous), DeletePrevious(DeletePrevious) {}
53  ~DelegatingDeserializationListener() override {
54  if (DeletePrevious)
55  delete Previous;
56  }
57 
58  void ReaderInitialized(ASTReader *Reader) override {
59  if (Previous)
60  Previous->ReaderInitialized(Reader);
61  }
62  void IdentifierRead(serialization::IdentID ID,
63  IdentifierInfo *II) override {
64  if (Previous)
65  Previous->IdentifierRead(ID, II);
66  }
67  void TypeRead(serialization::TypeIdx Idx, QualType T) override {
68  if (Previous)
69  Previous->TypeRead(Idx, T);
70  }
71  void DeclRead(serialization::DeclID ID, const Decl *D) override {
72  if (Previous)
73  Previous->DeclRead(ID, D);
74  }
75  void SelectorRead(serialization::SelectorID ID, Selector Sel) override {
76  if (Previous)
77  Previous->SelectorRead(ID, Sel);
78  }
79  void MacroDefinitionRead(serialization::PreprocessedEntityID PPID,
80  MacroDefinitionRecord *MD) override {
81  if (Previous)
82  Previous->MacroDefinitionRead(PPID, MD);
83  }
84 };
85 
86 /// Dumps deserialized declarations.
87 class DeserializedDeclsDumper : public DelegatingDeserializationListener {
88 public:
89  explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous,
90  bool DeletePrevious)
91  : DelegatingDeserializationListener(Previous, DeletePrevious) {}
92 
93  void DeclRead(serialization::DeclID ID, const Decl *D) override {
94  llvm::outs() << "PCH DECL: " << D->getDeclKindName();
95  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
96  llvm::outs() << " - ";
97  ND->printQualifiedName(llvm::outs());
98  }
99  llvm::outs() << "\n";
100 
101  DelegatingDeserializationListener::DeclRead(ID, D);
102  }
103 };
104 
105 /// Checks deserialized declarations and emits error if a name
106 /// matches one given in command-line using -error-on-deserialized-decl.
107 class DeserializedDeclsChecker : public DelegatingDeserializationListener {
108  ASTContext &Ctx;
109  std::set<std::string> NamesToCheck;
110 
111 public:
112  DeserializedDeclsChecker(ASTContext &Ctx,
113  const std::set<std::string> &NamesToCheck,
115  bool DeletePrevious)
116  : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx),
117  NamesToCheck(NamesToCheck) {}
118 
119  void DeclRead(serialization::DeclID ID, const Decl *D) override {
120  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
121  if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) {
122  unsigned DiagID
124  "%0 was deserialized");
125  Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID)
126  << ND;
127  }
128 
129  DelegatingDeserializationListener::DeclRead(ID, D);
130  }
131 };
132 
133 } // end anonymous namespace
134 
135 FrontendAction::FrontendAction() : Instance(nullptr) {}
136 
138 
140  std::unique_ptr<ASTUnit> AST) {
141  this->CurrentInput = CurrentInput;
142  CurrentASTUnit = std::move(AST);
143 }
144 
148  CI.getLangOpts().CurrentModule, SourceLocation(), /*AllowSearch*/false);
149 }
150 
151 std::unique_ptr<ASTConsumer>
152 FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
153  StringRef InFile) {
154  std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile);
155  if (!Consumer)
156  return nullptr;
157 
158  // Validate -add-plugin args.
159  bool FoundAllPlugins = true;
160  for (const std::string &Arg : CI.getFrontendOpts().AddPluginActions) {
161  bool Found = false;
162  for (const FrontendPluginRegistry::entry &Plugin :
163  FrontendPluginRegistry::entries()) {
164  if (Plugin.getName() == Arg)
165  Found = true;
166  }
167  if (!Found) {
168  CI.getDiagnostics().Report(diag::err_fe_invalid_plugin_name) << Arg;
169  FoundAllPlugins = false;
170  }
171  }
172  if (!FoundAllPlugins)
173  return nullptr;
174 
175  // If there are no registered plugins we don't need to wrap the consumer
176  if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
177  return Consumer;
178 
179  // If this is a code completion run, avoid invoking the plugin consumers
180  if (CI.hasCodeCompletionConsumer())
181  return Consumer;
182 
183  // Collect the list of plugins that go before the main action (in Consumers)
184  // or after it (in AfterConsumers)
185  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
186  std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers;
187  for (const FrontendPluginRegistry::entry &Plugin :
188  FrontendPluginRegistry::entries()) {
189  std::unique_ptr<PluginASTAction> P = Plugin.instantiate();
190  PluginASTAction::ActionType ActionType = P->getActionType();
191  if (ActionType == PluginASTAction::CmdlineAfterMainAction ||
193  // This is O(|plugins| * |add_plugins|), but since both numbers are
194  // way below 50 in practice, that's ok.
195  if (llvm::any_of(CI.getFrontendOpts().AddPluginActions,
196  [&](const std::string &PluginAction) {
197  return PluginAction == Plugin.getName();
198  })) {
201  else
203  }
204  }
205  if ((ActionType == PluginASTAction::AddBeforeMainAction ||
206  ActionType == PluginASTAction::AddAfterMainAction) &&
207  P->ParseArgs(
208  CI,
209  CI.getFrontendOpts().PluginArgs[std::string(Plugin.getName())])) {
210  std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile);
211  if (ActionType == PluginASTAction::AddBeforeMainAction) {
212  Consumers.push_back(std::move(PluginConsumer));
213  } else {
214  AfterConsumers.push_back(std::move(PluginConsumer));
215  }
216  }
217  }
218 
219  // Add to Consumers the main consumer, then all the plugins that go after it
220  Consumers.push_back(std::move(Consumer));
221  if (!AfterConsumers.empty()) {
222  // If we have plugins after the main consumer, which may be the codegen
223  // action, they likely will need the ASTContext, so don't clear it in the
224  // codegen action.
225  CI.getCodeGenOpts().ClearASTBeforeBackend = false;
226  for (auto &C : AfterConsumers)
227  Consumers.push_back(std::move(C));
228  }
229 
230  return std::make_unique<MultiplexConsumer>(std::move(Consumers));
231 }
232 
233 /// For preprocessed files, if the first line is the linemarker and specifies
234 /// the original source file name, use that name as the input file name.
235 /// Returns the location of the first token after the line marker directive.
236 ///
237 /// \param CI The compiler instance.
238 /// \param InputFile Populated with the filename from the line marker.
239 /// \param IsModuleMap If \c true, add a line note corresponding to this line
240 /// directive. (We need to do this because the directive will not be
241 /// visited by the preprocessor.)
243  std::string &InputFile,
244  bool IsModuleMap = false) {
245  auto &SourceMgr = CI.getSourceManager();
246  auto MainFileID = SourceMgr.getMainFileID();
247 
248  auto MainFileBuf = SourceMgr.getBufferOrNone(MainFileID);
249  if (!MainFileBuf)
250  return SourceLocation();
251 
252  std::unique_ptr<Lexer> RawLexer(
253  new Lexer(MainFileID, *MainFileBuf, SourceMgr, CI.getLangOpts()));
254 
255  // If the first line has the syntax of
256  //
257  // # NUM "FILENAME"
258  //
259  // we use FILENAME as the input file name.
260  Token T;
261  if (RawLexer->LexFromRawLexer(T) || T.getKind() != tok::hash)
262  return SourceLocation();
263  if (RawLexer->LexFromRawLexer(T) || T.isAtStartOfLine() ||
264  T.getKind() != tok::numeric_constant)
265  return SourceLocation();
266 
267  unsigned LineNo;
268  SourceLocation LineNoLoc = T.getLocation();
269  if (IsModuleMap) {
270  llvm::SmallString<16> Buffer;
271  if (Lexer::getSpelling(LineNoLoc, Buffer, SourceMgr, CI.getLangOpts())
272  .getAsInteger(10, LineNo))
273  return SourceLocation();
274  }
275 
276  RawLexer->LexFromRawLexer(T);
277  if (T.isAtStartOfLine() || T.getKind() != tok::string_literal)
278  return SourceLocation();
279 
281  if (Literal.hadError)
282  return SourceLocation();
283  RawLexer->LexFromRawLexer(T);
284  if (T.isNot(tok::eof) && !T.isAtStartOfLine())
285  return SourceLocation();
286  InputFile = Literal.GetString().str();
287 
288  if (IsModuleMap)
290  LineNoLoc, LineNo, SourceMgr.getLineTableFilenameID(InputFile), false,
291  false, SrcMgr::C_User_ModuleMap);
292 
293  return T.getLocation();
294 }
295 
296 static SmallVectorImpl<char> &
297 operator+=(SmallVectorImpl<char> &Includes, StringRef RHS) {
298  Includes.append(RHS.begin(), RHS.end());
299  return Includes;
300 }
301 
302 static void addHeaderInclude(StringRef HeaderName,
303  SmallVectorImpl<char> &Includes,
304  const LangOptions &LangOpts,
305  bool IsExternC) {
306  if (IsExternC && LangOpts.CPlusPlus)
307  Includes += "extern \"C\" {\n";
308  if (LangOpts.ObjC)
309  Includes += "#import \"";
310  else
311  Includes += "#include \"";
312 
313  Includes += HeaderName;
314 
315  Includes += "\"\n";
316  if (IsExternC && LangOpts.CPlusPlus)
317  Includes += "}\n";
318 }
319 
320 /// Collect the set of header includes needed to construct the given
321 /// module and update the TopHeaders file set of the module.
322 ///
323 /// \param Module The module we're collecting includes from.
324 ///
325 /// \param Includes Will be augmented with the set of \#includes or \#imports
326 /// needed to load all of the named headers.
327 static std::error_code collectModuleHeaderIncludes(
328  const LangOptions &LangOpts, FileManager &FileMgr, DiagnosticsEngine &Diag,
329  ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl<char> &Includes) {
330  // Don't collect any headers for unavailable modules.
331  if (!Module->isAvailable())
332  return std::error_code();
333 
334  // Resolve all lazy header directives to header files.
335  ModMap.resolveHeaderDirectives(Module, /*File=*/llvm::None);
336 
337  // If any headers are missing, we can't build this module. In most cases,
338  // diagnostics for this should have already been produced; we only get here
339  // if explicit stat information was provided.
340  // FIXME: If the name resolves to a file with different stat information,
341  // produce a better diagnostic.
342  if (!Module->MissingHeaders.empty()) {
343  auto &MissingHeader = Module->MissingHeaders.front();
344  Diag.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
345  << MissingHeader.IsUmbrella << MissingHeader.FileName;
346  return std::error_code();
347  }
348 
349  // Add includes for each of these headers.
350  for (auto HK : {Module::HK_Normal, Module::HK_Private}) {
351  for (Module::Header &H : Module->Headers[HK]) {
352  Module->addTopHeader(H.Entry);
353  // Use the path as specified in the module map file. We'll look for this
354  // file relative to the module build directory (the directory containing
355  // the module map file) so this will find the same file that we found
356  // while parsing the module map.
357  addHeaderInclude(H.PathRelativeToRootModuleDirectory, Includes, LangOpts,
358  Module->IsExternC);
359  }
360  }
361  // Note that Module->PrivateHeaders will not be a TopHeader.
362 
363  if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) {
364  Module->addTopHeader(UmbrellaHeader.Entry);
365  if (Module->Parent)
366  // Include the umbrella header for submodules.
367  addHeaderInclude(UmbrellaHeader.PathRelativeToRootModuleDirectory,
368  Includes, LangOpts, Module->IsExternC);
369  } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) {
370  // Add all of the headers we find in this subdirectory.
371  std::error_code EC;
372  SmallString<128> DirNative;
373  llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
374 
375  llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
377  for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
378  Dir != End && !EC; Dir.increment(EC)) {
379  // Check whether this entry has an extension typically associated with
380  // headers.
381  if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
382  .Cases(".h", ".H", ".hh", ".hpp", true)
383  .Default(false))
384  continue;
385 
386  auto Header = FileMgr.getFile(Dir->path());
387  // FIXME: This shouldn't happen unless there is a file system race. Is
388  // that worth diagnosing?
389  if (!Header)
390  continue;
391 
392  // If this header is marked 'unavailable' in this module, don't include
393  // it.
394  if (ModMap.isHeaderUnavailableInModule(*Header, Module))
395  continue;
396 
397  // Compute the relative path from the directory to this file.
398  SmallVector<StringRef, 16> Components;
399  auto PathIt = llvm::sys::path::rbegin(Dir->path());
400  for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt)
401  Components.push_back(*PathIt);
402  SmallString<128> RelativeHeader(
403  UmbrellaDir.PathRelativeToRootModuleDirectory);
404  for (auto It = Components.rbegin(), End = Components.rend(); It != End;
405  ++It)
406  llvm::sys::path::append(RelativeHeader, *It);
407 
408  std::string RelName = RelativeHeader.c_str();
409  Headers.push_back(std::make_pair(RelName, *Header));
410  }
411 
412  if (EC)
413  return EC;
414 
415  // Sort header paths and make the header inclusion order deterministic
416  // across different OSs and filesystems.
417  llvm::sort(Headers.begin(), Headers.end(), llvm::less_first());
418  for (auto &H : Headers) {
419  // Include this header as part of the umbrella directory.
420  Module->addTopHeader(H.second);
421  addHeaderInclude(H.first, Includes, LangOpts, Module->IsExternC);
422  }
423  }
424 
425  // Recurse into submodules.
427  SubEnd = Module->submodule_end();
428  Sub != SubEnd; ++Sub)
429  if (std::error_code Err = collectModuleHeaderIncludes(
430  LangOpts, FileMgr, Diag, ModMap, *Sub, Includes))
431  return Err;
432 
433  return std::error_code();
434 }
435 
436 static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
437  bool IsPreprocessed,
438  std::string &PresumedModuleMapFile,
439  unsigned &Offset) {
440  auto &SrcMgr = CI.getSourceManager();
442 
443  // Map the current input to a file.
444  FileID ModuleMapID = SrcMgr.getMainFileID();
445  const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
446 
447  // If the module map is preprocessed, handle the initial line marker;
448  // line directives are not part of the module map syntax in general.
449  Offset = 0;
450  if (IsPreprocessed) {
451  SourceLocation EndOfLineMarker =
452  ReadOriginalFileName(CI, PresumedModuleMapFile, /*IsModuleMap*/ true);
453  if (EndOfLineMarker.isValid())
454  Offset = CI.getSourceManager().getDecomposedLoc(EndOfLineMarker).second;
455  }
456 
457  // Load the module map file.
458  if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
459  PresumedModuleMapFile))
460  return true;
461 
462  if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
463  Offset = 0;
464 
465  // Infer framework module if possible.
466  if (HS.getModuleMap().canInferFrameworkModule(ModuleMap->getDir())) {
467  SmallString<128> InferredFrameworkPath = ModuleMap->getDir()->getName();
468  llvm::sys::path::append(InferredFrameworkPath,
469  CI.getLangOpts().ModuleName + ".framework");
470  if (auto Dir = CI.getFileManager().getDirectory(InferredFrameworkPath))
471  (void)HS.getModuleMap().inferFrameworkModule(*Dir, IsSystem, nullptr);
472  }
473 
474  return false;
475 }
476 
478  StringRef ModuleMapFilename) {
479  if (CI.getLangOpts().CurrentModule.empty()) {
480  CI.getDiagnostics().Report(diag::err_missing_module_name);
481 
482  // FIXME: Eventually, we could consider asking whether there was just
483  // a single module described in the module map, and use that as a
484  // default. Then it would be fairly trivial to just "compile" a module
485  // map with a single module (the common case).
486  return nullptr;
487  }
488 
489  // Dig out the module definition.
492  /*AllowSearch=*/true);
493  if (!M) {
494  CI.getDiagnostics().Report(diag::err_missing_module)
495  << CI.getLangOpts().CurrentModule << ModuleMapFilename;
496 
497  return nullptr;
498  }
499 
500  // Check whether we can build this module at all.
502  CI.getDiagnostics(), M))
503  return nullptr;
504 
505  // Inform the preprocessor that includes from within the input buffer should
506  // be resolved relative to the build directory of the module map file.
508 
509  // If the module was inferred from a different module map (via an expanded
510  // umbrella module definition), track that fact.
511  // FIXME: It would be preferable to fill this in as part of processing
512  // the module map, rather than adding it after the fact.
513  StringRef OriginalModuleMapName = CI.getFrontendOpts().OriginalModuleMap;
514  if (!OriginalModuleMapName.empty()) {
515  auto OriginalModuleMap =
516  CI.getFileManager().getFile(OriginalModuleMapName,
517  /*openFile*/ true);
518  if (!OriginalModuleMap) {
519  CI.getDiagnostics().Report(diag::err_module_map_not_found)
520  << OriginalModuleMapName;
521  return nullptr;
522  }
523  if (*OriginalModuleMap != CI.getSourceManager().getFileEntryForID(
525  M->IsInferred = true;
527  .setInferredModuleAllowedBy(M, *OriginalModuleMap);
528  }
529  }
530 
531  // If we're being run from the command-line, the module build stack will not
532  // have been filled in yet, so complete it now in order to allow us to detect
533  // module cycles.
534  SourceManager &SourceMgr = CI.getSourceManager();
535  if (SourceMgr.getModuleBuildStack().empty())
537  FullSourceLoc(SourceLocation(), SourceMgr));
538  return M;
539 }
540 
541 /// Compute the input buffer that should be used to build the specified module.
542 static std::unique_ptr<llvm::MemoryBuffer>
544  FileManager &FileMgr = CI.getFileManager();
545 
546  // Collect the set of #includes we need to build the module.
547  SmallString<256> HeaderContents;
548  std::error_code Err = std::error_code();
549  if (Module::Header UmbrellaHeader = M->getUmbrellaHeader())
550  addHeaderInclude(UmbrellaHeader.PathRelativeToRootModuleDirectory,
551  HeaderContents, CI.getLangOpts(), M->IsExternC);
553  CI.getLangOpts(), FileMgr, CI.getDiagnostics(),
555  HeaderContents);
556 
557  if (Err) {
558  CI.getDiagnostics().Report(diag::err_module_cannot_create_includes)
559  << M->getFullModuleName() << Err.message();
560  return nullptr;
561  }
562 
563  return llvm::MemoryBuffer::getMemBufferCopy(
564  HeaderContents, Module::getModuleInputBufferName());
565 }
566 
568  const FrontendInputFile &RealInput) {
569  FrontendInputFile Input(RealInput);
570  assert(!Instance && "Already processing a source file!");
571  assert(!Input.isEmpty() && "Unexpected empty filename!");
572  setCurrentInput(Input);
573  setCompilerInstance(&CI);
574 
575  bool HasBegunSourceFile = false;
576  bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
578 
579  // If we fail, reset state since the client will not end up calling the
580  // matching EndSourceFile(). All paths that return true should release this.
581  auto FailureCleanup = llvm::make_scope_exit([&]() {
582  if (HasBegunSourceFile)
584  CI.clearOutputFiles(/*EraseFiles=*/true);
585  CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
587  setCompilerInstance(nullptr);
588  });
589 
590  if (!BeginInvocation(CI))
591  return false;
592 
593  // If we're replaying the build of an AST file, import it and set up
594  // the initial state from its build.
595  if (ReplayASTFile) {
597 
598  // The AST unit populates its own diagnostics engine rather than ours.
600  new DiagnosticsEngine(Diags->getDiagnosticIDs(),
601  &Diags->getDiagnosticOptions()));
602  ASTDiags->setClient(Diags->getClient(), /*OwnsClient*/false);
603 
604  // FIXME: What if the input is a memory buffer?
605  StringRef InputFile = Input.getFile();
606 
607  std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
608  std::string(InputFile), CI.getPCHContainerReader(),
610  CI.getCodeGenOpts().DebugTypeExtRefs);
611  if (!AST)
612  return false;
613 
614  // Options relating to how we treat the input (but not what we do with it)
615  // are inherited from the AST unit.
616  CI.getHeaderSearchOpts() = AST->getHeaderSearchOpts();
617  CI.getPreprocessorOpts() = AST->getPreprocessorOpts();
618  CI.getLangOpts() = AST->getLangOpts();
619 
620  // Set the shared objects, these are reset when we finish processing the
621  // file, otherwise the CompilerInstance will happily destroy them.
622  CI.setFileManager(&AST->getFileManager());
624  CI.getSourceManager().initializeForReplay(AST->getSourceManager());
625 
626  // Preload all the module files loaded transitively by the AST unit. Also
627  // load all module map files that were parsed as part of building the AST
628  // unit.
629  if (auto ASTReader = AST->getASTReader()) {
630  auto &MM = ASTReader->getModuleManager();
631  auto &PrimaryModule = MM.getPrimaryModule();
632 
633  for (serialization::ModuleFile &MF : MM)
634  if (&MF != &PrimaryModule)
635  CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName);
636 
638  PrimaryModule, [&](const FileEntry *FE) {
639  CI.getFrontendOpts().ModuleMapFiles.push_back(
640  std::string(FE->getName()));
641  });
642  }
643 
644  // Set up the input file for replay purposes.
645  auto Kind = AST->getInputKind();
646  if (Kind.getFormat() == InputKind::ModuleMap) {
647  Module *ASTModule =
648  AST->getPreprocessor().getHeaderSearchInfo().lookupModule(
649  AST->getLangOpts().CurrentModule, SourceLocation(),
650  /*AllowSearch*/ false);
651  assert(ASTModule && "module file does not define its own module");
652  Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind);
653  } else {
654  auto &OldSM = AST->getSourceManager();
655  FileID ID = OldSM.getMainFileID();
656  if (auto *File = OldSM.getFileEntryForID(ID))
657  Input = FrontendInputFile(File->getName(), Kind);
658  else
659  Input = FrontendInputFile(OldSM.getBufferOrFake(ID), Kind);
660  }
661  setCurrentInput(Input, std::move(AST));
662  }
663 
664  // AST files follow a very different path, since they share objects via the
665  // AST unit.
666  if (Input.getKind().getFormat() == InputKind::Precompiled) {
667  assert(!usesPreprocessorOnly() && "this case was handled above");
668  assert(hasASTFileSupport() &&
669  "This action does not have AST file support!");
670 
672 
673  // FIXME: What if the input is a memory buffer?
674  StringRef InputFile = Input.getFile();
675 
676  std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
677  std::string(InputFile), CI.getPCHContainerReader(),
679  CI.getCodeGenOpts().DebugTypeExtRefs);
680 
681  if (!AST)
682  return false;
683 
684  // Inform the diagnostic client we are processing a source file.
685  CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
686  HasBegunSourceFile = true;
687 
688  // Set the shared objects, these are reset when we finish processing the
689  // file, otherwise the CompilerInstance will happily destroy them.
690  CI.setFileManager(&AST->getFileManager());
691  CI.setSourceManager(&AST->getSourceManager());
692  CI.setPreprocessor(AST->getPreprocessorPtr());
693  Preprocessor &PP = CI.getPreprocessor();
695  PP.getLangOpts());
696  CI.setASTContext(&AST->getASTContext());
697 
698  setCurrentInput(Input, std::move(AST));
699 
700  // Initialize the action.
701  if (!BeginSourceFileAction(CI))
702  return false;
703 
704  // Create the AST consumer.
705  CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
706  if (!CI.hasASTConsumer())
707  return false;
708 
709  FailureCleanup.release();
710  return true;
711  }
712 
713  // Set up the file and source managers, if needed.
714  if (!CI.hasFileManager()) {
715  if (!CI.createFileManager()) {
716  return false;
717  }
718  }
719  if (!CI.hasSourceManager())
721 
722  // Set up embedding for any specified files. Do this before we load any
723  // source files, including the primary module map for the compilation.
724  for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) {
725  if (auto FE = CI.getFileManager().getFile(F, /*openFile*/true))
727  else
728  CI.getDiagnostics().Report(diag::err_modules_embed_file_not_found) << F;
729  }
732 
733  // IR files bypass the rest of initialization.
734  if (Input.getKind().getLanguage() == Language::LLVM_IR) {
735  assert(hasIRSupport() &&
736  "This action does not have IR file support!");
737 
738  // Inform the diagnostic client we are processing a source file.
739  CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
740  HasBegunSourceFile = true;
741 
742  // Initialize the action.
743  if (!BeginSourceFileAction(CI))
744  return false;
745 
746  // Initialize the main file entry.
747  if (!CI.InitializeSourceManager(CurrentInput))
748  return false;
749 
750  FailureCleanup.release();
751  return true;
752  }
753 
754  // If the implicit PCH include is actually a directory, rather than
755  // a single file, search for a suitable PCH file in that directory.
756  if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
757  FileManager &FileMgr = CI.getFileManager();
759  StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
760  std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath();
761  if (auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude)) {
762  std::error_code EC;
763  SmallString<128> DirNative;
764  llvm::sys::path::native(PCHDir->getName(), DirNative);
765  bool Found = false;
766  llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
767  for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC),
768  DirEnd;
769  Dir != DirEnd && !EC; Dir.increment(EC)) {
770  // Check whether this is an acceptable AST file.
772  Dir->path(), FileMgr, CI.getPCHContainerReader(),
774  SpecificModuleCachePath)) {
775  PPOpts.ImplicitPCHInclude = std::string(Dir->path());
776  Found = true;
777  break;
778  }
779  }
780 
781  if (!Found) {
782  CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
783  return false;
784  }
785  }
786  }
787 
788  // Set up the preprocessor if needed. When parsing model files the
789  // preprocessor of the original source is reused.
790  if (!isModelParsingAction())
792 
793  // Inform the diagnostic client we are processing a source file.
795  &CI.getPreprocessor());
796  HasBegunSourceFile = true;
797 
798  // Handle C++20 header units.
799  // Here, the user has the option to specify that the header name should be
800  // looked up in the pre-processor search paths (and the main filename as
801  // passed by the driver might therefore be incomplete until that look-up).
802  if (CI.getLangOpts().CPlusPlusModules && Input.getKind().isHeaderUnit() &&
803  !Input.getKind().isPreprocessed()) {
804  StringRef FileName = Input.getFile();
805  InputKind Kind = Input.getKind();
806  if (Kind.getHeaderUnitKind() != InputKind::HeaderUnit_Abs) {
807  assert(CI.hasPreprocessor() &&
808  "trying to build a header unit without a Pre-processor?");
810  // Relative searches begin from CWD.
811  const DirectoryEntry *Dir = nullptr;
812  if (auto DirOrErr = CI.getFileManager().getDirectory("."))
813  Dir = *DirOrErr;
815  CWD.push_back({nullptr, Dir});
817  HS.LookupFile(FileName, SourceLocation(),
818  /*Angled*/ Input.getKind().getHeaderUnitKind() ==
820  nullptr, nullptr, CWD, nullptr, nullptr, nullptr,
821  nullptr, nullptr, nullptr);
822  if (!FE) {
823  CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
824  << FileName;
825  return false;
826  }
827  // We now have the filename...
828  FileName = FE->getFileEntry().getName();
829  // ... still a header unit, but now use the path as written.
831  Input = FrontendInputFile(FileName, Kind, Input.isSystem());
832  }
833  // Unless the user has overridden the name, the header unit module name is
834  // the pathname for the file.
835  if (CI.getLangOpts().ModuleName.empty())
836  CI.getLangOpts().ModuleName = std::string(FileName);
838  }
839 
840  if (!CI.InitializeSourceManager(Input))
841  return false;
842 
843  if (CI.getLangOpts().CPlusPlusModules && Input.getKind().isHeaderUnit() &&
844  Input.getKind().isPreprocessed() && !usesPreprocessorOnly()) {
845  // We have an input filename like foo.iih, but we want to find the right
846  // module name (and original file, to build the map entry).
847  // Check if the first line specifies the original source file name with a
848  // linemarker.
849  std::string PresumedInputFile = std::string(getCurrentFileOrBufferName());
850  ReadOriginalFileName(CI, PresumedInputFile);
851  // Unless the user overrides this, the module name is the name by which the
852  // original file was known.
853  if (CI.getLangOpts().ModuleName.empty())
854  CI.getLangOpts().ModuleName = std::string(PresumedInputFile);
856  }
857 
858  // For module map files, we first parse the module map and synthesize a
859  // "<module-includes>" buffer before more conventional processing.
860  if (Input.getKind().getFormat() == InputKind::ModuleMap) {
861  CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleMap);
862 
863  std::string PresumedModuleMapFile;
864  unsigned OffsetToContents;
865  if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
866  Input.isPreprocessed(),
867  PresumedModuleMapFile, OffsetToContents))
868  return false;
869 
870  auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
871  if (!CurrentModule)
872  return false;
873 
874  CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
875 
876  if (OffsetToContents)
877  // If the module contents are in the same file, skip to them.
878  CI.getPreprocessor().setSkipMainFilePreamble(OffsetToContents, true);
879  else {
880  // Otherwise, convert the module description to a suitable input buffer.
881  auto Buffer = getInputBufferForModule(CI, CurrentModule);
882  if (!Buffer)
883  return false;
884 
885  // Reinitialize the main file entry to refer to the new input.
886  auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User;
887  auto &SourceMgr = CI.getSourceManager();
888  auto BufferID = SourceMgr.createFileID(std::move(Buffer), Kind);
889  assert(BufferID.isValid() && "couldn't create module buffer ID");
890  SourceMgr.setMainFileID(BufferID);
891  }
892  }
893 
894  // Initialize the action.
895  if (!BeginSourceFileAction(CI))
896  return false;
897 
898  // If we were asked to load any module map files, do so now.
899  for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
900  if (auto File = CI.getFileManager().getFile(Filename))
902  *File, /*IsSystem*/false);
903  else
904  CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
905  }
906 
907  // Add a module declaration scope so that modules from -fmodule-map-file
908  // arguments may shadow modules found implicitly in search paths.
909  CI.getPreprocessor()
911  .getModuleMap()
913 
914  // Create the AST context and consumer unless this is a preprocessor only
915  // action.
916  if (!usesPreprocessorOnly()) {
917  // Parsing a model file should reuse the existing ASTContext.
918  if (!isModelParsingAction())
919  CI.createASTContext();
920 
921  // For preprocessed files, check if the first line specifies the original
922  // source file name with a linemarker.
923  std::string PresumedInputFile = std::string(getCurrentFileOrBufferName());
924  if (Input.isPreprocessed())
925  ReadOriginalFileName(CI, PresumedInputFile);
926 
927  std::unique_ptr<ASTConsumer> Consumer =
928  CreateWrappedASTConsumer(CI, PresumedInputFile);
929  if (!Consumer)
930  return false;
931 
932  // FIXME: should not overwrite ASTMutationListener when parsing model files?
933  if (!isModelParsingAction())
934  CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
935 
936  if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
937  // Convert headers to PCH and chain them.
938  IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader;
939  source = createChainedIncludesSource(CI, FinalReader);
940  if (!source)
941  return false;
942  CI.setASTReader(static_cast<ASTReader *>(FinalReader.get()));
943  CI.getASTContext().setExternalSource(source);
944  } else if (CI.getLangOpts().Modules ||
945  !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
946  // Use PCM or PCH.
947  assert(hasPCHSupport() && "This action does not have PCH support!");
948  ASTDeserializationListener *DeserialListener =
949  Consumer->GetASTDeserializationListener();
950  bool DeleteDeserialListener = false;
952  DeserialListener = new DeserializedDeclsDumper(DeserialListener,
953  DeleteDeserialListener);
954  DeleteDeserialListener = true;
955  }
957  DeserialListener = new DeserializedDeclsChecker(
958  CI.getASTContext(),
960  DeserialListener, DeleteDeserialListener);
961  DeleteDeserialListener = true;
962  }
963  if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
968  DeserialListener, DeleteDeserialListener);
969  if (!CI.getASTContext().getExternalSource())
970  return false;
971  }
972  // If modules are enabled, create the AST reader before creating
973  // any builtins, so that all declarations know that they might be
974  // extended by an external source.
975  if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
977  CI.createASTReader();
978  CI.getASTReader()->setDeserializationListener(DeserialListener,
979  DeleteDeserialListener);
980  }
981  }
982 
983  CI.setASTConsumer(std::move(Consumer));
984  if (!CI.hasASTConsumer())
985  return false;
986  }
987 
988  // Initialize built-in info as long as we aren't using an external AST
989  // source.
990  if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
992  Preprocessor &PP = CI.getPreprocessor();
994  PP.getLangOpts());
995  } else {
996  // FIXME: If this is a problem, recover from it by creating a multiplex
997  // source.
998  assert((!CI.getLangOpts().Modules || CI.getASTReader()) &&
999  "modules enabled but created an external source that "
1000  "doesn't support modules");
1001  }
1002 
1003  // If we were asked to load any module files, do so now.
1004  for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
1005  if (!CI.loadModuleFile(ModuleFile))
1006  return false;
1007 
1008  // If there is a layout overrides file, attach an external AST source that
1009  // provides the layouts from that file.
1010  if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() &&
1011  CI.hasASTContext() && !CI.getASTContext().getExternalSource()) {
1013  Override(new LayoutOverrideSource(
1015  CI.getASTContext().setExternalSource(Override);
1016  }
1017 
1018  // Setup HLSL External Sema Source
1019  if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
1021  new HLSLExternalSemaSource());
1022  CI.getASTContext().setExternalSource(HLSLSema);
1023  }
1024 
1025  FailureCleanup.release();
1026  return true;
1027 }
1028 
1031 
1032  if (CI.hasFrontendTimer()) {
1033  llvm::TimeRegion Timer(CI.getFrontendTimer());
1034  ExecuteAction();
1035  }
1036  else ExecuteAction();
1037 
1038  // If we are supposed to rebuild the global module index, do so now unless
1039  // there were any module-build failures.
1040  if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
1041  CI.hasPreprocessor()) {
1042  StringRef Cache =
1044  if (!Cache.empty()) {
1045  if (llvm::Error Err = GlobalModuleIndex::writeIndex(
1047  // FIXME this drops the error on the floor, but
1048  // Index/pch-from-libclang.c seems to rely on dropping at least some of
1049  // the error conditions!
1050  consumeError(std::move(Err));
1051  }
1052  }
1053  }
1054 
1055  return llvm::Error::success();
1056 }
1057 
1060 
1061  // Inform the diagnostic client we are done with this source file.
1063 
1064  // Inform the preprocessor we are done.
1065  if (CI.hasPreprocessor())
1067 
1068  // Finalize the action.
1070 
1071  // Sema references the ast consumer, so reset sema first.
1072  //
1073  // FIXME: There is more per-file stuff we could just drop here?
1074  bool DisableFree = CI.getFrontendOpts().DisableFree;
1075  if (DisableFree) {
1076  CI.resetAndLeakSema();
1078  llvm::BuryPointer(CI.takeASTConsumer().get());
1079  } else {
1080  CI.setSema(nullptr);
1081  CI.setASTContext(nullptr);
1082  CI.setASTConsumer(nullptr);
1083  }
1084 
1085  if (CI.getFrontendOpts().ShowStats) {
1086  llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFileOrBufferName() << "':\n";
1087  CI.getPreprocessor().PrintStats();
1091  llvm::errs() << "\n";
1092  }
1093 
1094  // Cleanup the output streams, and erase the output files if instructed by the
1095  // FrontendAction.
1096  CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
1097 
1098  if (isCurrentFileAST()) {
1099  if (DisableFree) {
1103  llvm::BuryPointer(std::move(CurrentASTUnit));
1104  } else {
1105  CI.setPreprocessor(nullptr);
1106  CI.setSourceManager(nullptr);
1107  CI.setFileManager(nullptr);
1108  }
1109  }
1110 
1111  setCompilerInstance(nullptr);
1113  CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
1114 }
1115 
1118 }
1119 
1120 //===----------------------------------------------------------------------===//
1121 // Utility Actions
1122 //===----------------------------------------------------------------------===//
1123 
1126  if (!CI.hasPreprocessor())
1127  return;
1128 
1129  // FIXME: Move the truncation aspect of this into Sema, we delayed this till
1130  // here so the source manager would be initialized.
1131  if (hasCodeCompletionSupport() &&
1134 
1135  // Use a code completion consumer?
1136  CodeCompleteConsumer *CompletionConsumer = nullptr;
1137  if (CI.hasCodeCompletionConsumer())
1138  CompletionConsumer = &CI.getCodeCompletionConsumer();
1139 
1140  if (!CI.hasSema())
1141  CI.createSema(getTranslationUnitKind(), CompletionConsumer);
1142 
1145 }
1146 
1147 void PluginASTAction::anchor() { }
1148 
1149 std::unique_ptr<ASTConsumer>
1151  StringRef InFile) {
1152  llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
1153 }
1154 
1156  return WrappedAction->PrepareToExecuteAction(CI);
1157 }
1158 std::unique_ptr<ASTConsumer>
1160  StringRef InFile) {
1161  return WrappedAction->CreateASTConsumer(CI, InFile);
1162 }
1164  return WrappedAction->BeginInvocation(CI);
1165 }
1167  WrappedAction->setCurrentInput(getCurrentInput());
1168  WrappedAction->setCompilerInstance(&CI);
1169  auto Ret = WrappedAction->BeginSourceFileAction(CI);
1170  // BeginSourceFileAction may change CurrentInput, e.g. during module builds.
1171  setCurrentInput(WrappedAction->getCurrentInput());
1172  return Ret;
1173 }
1175  WrappedAction->ExecuteAction();
1176 }
1179  WrappedAction->EndSourceFileAction();
1180 }
1182  return WrappedAction->shouldEraseOutputFiles();
1183 }
1184 
1186  return WrappedAction->usesPreprocessorOnly();
1187 }
1189  return WrappedAction->getTranslationUnitKind();
1190 }
1192  return WrappedAction->hasPCHSupport();
1193 }
1195  return WrappedAction->hasASTFileSupport();
1196 }
1198  return WrappedAction->hasIRSupport();
1199 }
1201  return WrappedAction->hasCodeCompletionSupport();
1202 }
1203 
1205  std::unique_ptr<FrontendAction> WrappedAction)
1206  : WrappedAction(std::move(WrappedAction)) {}
1207 
clang::CompilerInstance::setASTConsumer
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value.
Definition: CompilerInstance.cpp:185
clang::WrapperFrontendAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendAction.cpp:1174
clang::ModuleMap::finishModuleDeclarationScope
void finishModuleDeclarationScope()
Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...
Definition: ModuleMap.h:586
clang::CompilerInstance::hasSema
bool hasSema() const
Definition: CompilerInstance.h:501
clang::FrontendOptions::ModuleMapFiles
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.
Definition: FrontendOptions.h:467
Builtins.h
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:417
clang::Preprocessor::setSkipMainFilePreamble
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
Definition: Preprocessor.h:1810
clang::FrontendOptions::AddPluginActions
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
Definition: FrontendOptions.h:458
FrontendPluginRegistry.h
clang::serialization::TypeIdx
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:88
clang::Preprocessor::PrintStats
void PrintStats()
Definition: Preprocessor.cpp:280
clang::GlobalModuleIndex::writeIndex
static llvm::Error writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, llvm::StringRef Path)
Write a global index into the given.
Definition: GlobalModuleIndex.cpp:852
clang::CompilerInstance::hasASTConsumer
bool hasASTConsumer() const
Definition: CompilerInstance.h:483
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:368
loadModuleMapForModuleBuild
static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, bool IsPreprocessed, std::string &PresumedModuleMapFile, unsigned &Offset)
Definition: FrontendAction.cpp:436
clang::DeclaratorContext::File
@ File
clang::Module::getUmbrellaDir
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:244
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:65
clang::InputKind::isHeaderUnit
bool isHeaderUnit() const
Definition: FrontendOptions.h:189
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::FrontendInputFile::getKind
InputKind getKind() const
Definition: FrontendOptions.h:244
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:79
clang::PluginASTAction::AddAfterMainAction
@ AddAfterMainAction
Execute the action after the main action.
Definition: FrontendAction.h:279
clang::ASTUnit::LoadFromASTFile
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowASTWithCompilerErrors=false, bool UserFilesAreVolatile=false, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=llvm::vfs::getRealFileSystem())
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:757
clang::FrontendOptions::ShowStats
unsigned ShowStats
Show frontend performance metrics and statistics.
Definition: FrontendOptions.h:281
clang::Lexer::getSpelling
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
Definition: Lexer.cpp:404
clang::FrontendAction::WrapperFrontendAction
friend class WrapperFrontendAction
Definition: FrontendAction.h:41
llvm::SmallVector
Definition: LLVM.h:38
clang::FrontendAction::isModelParsingAction
virtual bool isModelParsingAction() const
Is this action invoked on a model file?
Definition: FrontendAction.h:179
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::WrapperFrontendAction::hasCodeCompletionSupport
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
Definition: FrontendAction.cpp:1200
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::CompilerInstance::setSema
void setSema(Sema *S)
Replace the current Sema; the compiler instance takes ownership of S.
Definition: CompilerInstance.cpp:181
clang::serialization::IdentID
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:134
clang::PreprocessorFrontendAction::CreateASTConsumer
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...
Definition: FrontendAction.cpp:1150
addHeaderInclude
static void addHeaderInclude(StringRef HeaderName, SmallVectorImpl< char > &Includes, const LangOptions &LangOpts, bool IsExternC)
Definition: FrontendAction.cpp:302
clang::FrontendOptions::PluginArgs
std::map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
Definition: FrontendOptions.h:455
clang::FrontendOptions::SkipFunctionBodies
unsigned SkipFunctionBodies
Skip over function bodies to speed up parsing in cases you do not need them (e.g.
Definition: FrontendOptions.h:309
clang::FrontendAction::hasIRSupport
virtual bool hasIRSupport() const
Does this action support use with IR files?
Definition: FrontendAction.h:197
clang::ASTContext::getFullLoc
FullSourceLoc getFullLoc(SourceLocation Loc) const
Definition: ASTContext.h:806
clang::WrapperFrontendAction::getTranslationUnitKind
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
Definition: FrontendAction.cpp:1188
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:731
clang::FrontendAction::EndSourceFile
virtual void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
Definition: FrontendAction.cpp:1058
clang::Module::submodule_begin
submodule_iterator submodule_begin()
Definition: Module.h:685
clang::CompilerInstance::InitializeSourceManager
bool InitializeSourceManager(const FrontendInputFile &Input)
InitializeSourceManager - Initialize the source manager to set InputFile as the main file.
Definition: CompilerInstance.cpp:938
clang::CompilerInstance::getLangOpts
LangOptions & getLangOpts()
Definition: CompilerInstance.h:299
clang::WrapperFrontendAction::hasPCHSupport
bool hasPCHSupport() const override
Does this action support use with PCH?
Definition: FrontendAction.cpp:1191
Filename
StringRef Filename
Definition: Format.cpp:2572
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
clang::FrontendAction::getCurrentModule
Module * getCurrentModule() const
Definition: FrontendAction.cpp:145
clang::CompilerInstance::hasFrontendTimer
bool hasFrontendTimer() const
Definition: CompilerInstance.h:574
clang::FrontendAction::hasCodeCompletionSupport
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
Definition: FrontendAction.h:200
clang::FrontendInputFile
An input file for the front end.
Definition: FrontendOptions.h:221
clang::Token::isAtStartOfLine
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:267
collectModuleHeaderIncludes
static std::error_code collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, DiagnosticsEngine &Diag, ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl< char > &Includes)
Collect the set of header includes needed to construct the given module and update the TopHeaders fil...
Definition: FrontendAction.cpp:327
clang::InputKind::withHeaderUnit
InputKind withHeaderUnit(HeaderUnitKind HU) const
Definition: FrontendOptions.h:209
clang::LangOptions::CMK_ModuleMap
@ CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:108
clang::FrontendAction::BeginInvocation
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: FrontendAction.h:79
llvm::Optional< FileEntryRef >
clang::SourceManager::PrintStats
void PrintStats() const
Print statistics to stderr.
Definition: SourceManager.cpp:2122
clang::PreprocessorOptions::DumpDeserializedPCHDecls
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
Definition: PreprocessorOptions.h:115
clang::TypePropertyCache
The type-property cache.
Definition: Type.cpp:3839
clang::CompilerInstance::getFileSystemOpts
FileSystemOptions & getFileSystemOpts()
Definition: CompilerInstance.h:275
clang::SourceManager::AddLineNote
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
Definition: SourceManager.cpp:272
ASTDeserializationListener.h
clang::SourceManager::pushModuleBuildStack
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
Definition: SourceManager.h:832
FrontendAction.h
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1771
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::InputKind
The kind of a file that we've been handed as an input.
Definition: FrontendOptions.h:151
clang::FileManager::getOptionalDirectoryRef
llvm::Optional< DirectoryEntryRef > getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)
Get a DirectoryEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:170
clang::CompilerInstance::getCodeGenOpts
CodeGenOptions & getCodeGenOpts()
Definition: CompilerInstance.h:254
LiteralSupport.h
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::frontend::PluginAction
@ PluginAction
Run a plugin action,.
Definition: FrontendOptions.h:115
clang::FrontendInputFile::getFile
StringRef getFile() const
Definition: FrontendOptions.h:256
clang::CompilerInstance::getPCHContainerReader
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
Definition: CompilerInstance.h:542
clang::CompilerInstance::createCodeCompletionConsumer
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
Definition: CompilerInstance.cpp:710
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:1013
clang::Module::isAvailable
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition: Module.h:466
clang::FrontendAction::hasASTFileSupport
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
Definition: FrontendAction.h:194
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
clang::ModuleMap::setInferredModuleAllowedBy
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap)
Definition: ModuleMap.cpp:1292
clang::ParsedSourceLocation::FileName
std::string FileName
Definition: CommandLineSourceLoc.h:25
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:1006
Preprocessor.h
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:223
clang::CompilerInstance::resetAndLeakSourceManager
void resetAndLeakSourceManager()
Definition: CompilerInstance.h:427
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:78
Offset
unsigned Offset
Definition: Format.cpp:2574
clang::FrontendOptions::OverrideRecordLayoutsFile
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
Definition: FrontendOptions.h:485
clang::SourceManager::setAllFilesAreTransient
void setAllFilesAreTransient(bool Transient)
Specify that all files that are read during this compilation are transient.
Definition: SourceManager.h:1004
clang::FrontendOptions::ModulesEmbedAllFiles
unsigned ModulesEmbedAllFiles
Whether we should embed all used files into the PCM file.
Definition: FrontendOptions.h:336
clang::dataflow::Literal
uint32_t Literal
Literals are represented as positive integers.
Definition: WatchedLiteralsSolver.cpp:55
clang::CompilerInstance::getFileManager
FileManager & getFileManager() const
Return the current file manager to the caller.
Definition: CompilerInstance.h:402
clang::PluginASTAction::AddBeforeMainAction
@ AddBeforeMainAction
Execute the action before the main action.
Definition: FrontendAction.h:278
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1183
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::WrapperFrontendAction::hasIRSupport
bool hasIRSupport() const override
Does this action support use with IR files?
Definition: FrontendAction.cpp:1197
clang::FileManager::getVirtualFileSystem
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:245
clang::FrontendAction::~FrontendAction
virtual ~FrontendAction()
Definition: FrontendAction.cpp:137
clang::FrontendAction::getCurrentFileOrBufferName
StringRef getCurrentFileOrBufferName() const
Definition: FrontendAction.h:144
clang::Preprocessor::EndSourceFile
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
Definition: Preprocessor.cpp:699
clang::LangOptions::CMK_None
@ CMK_None
Not compiling a module interface at all.
Definition: LangOptions.h:105
clang::CompilerInstance::resetAndLeakFileManager
void resetAndLeakFileManager()
Definition: CompilerInstance.h:407
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: DirectoryEntry.h:34
clang::ASTReader::getModuleManager
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition: ASTReader.h:1706
clang::CompilerInstance::createASTReader
void createASTReader()
Definition: CompilerInstance.cpp:1632
clang::DiagnosticsEngine::hasErrorOccurred
bool hasErrorOccurred() const
Definition: Diagnostic.h:838
clang::FrontendAction::BeginSourceFile
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
Definition: FrontendAction.cpp:567
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
clang::HeaderSearch::loadModuleMapFile
bool loadModuleMapFile(const FileEntry *File, bool IsSystem, FileID ID=FileID(), unsigned *Offset=nullptr, StringRef OriginalModuleMapFile=StringRef())
Read the contents of the given module map file.
Definition: HeaderSearch.cpp:1628
clang::PreprocessorOptions::ChainedIncludes
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
Definition: PreprocessorOptions.h:100
clang::SourceManager::getMainFileID
FileID getMainFileID() const
Returns the FileID of the main source file.
Definition: SourceManager.h:841
clang::CompilerInstance::getSema
Sema & getSema() const
Definition: CompilerInstance.h:503
clang::DiagnosticsEngine::Error
@ Error
Definition: Diagnostic.h:200
Utils.h
clang::LayoutOverrideSource
An external AST source that overrides the layout of a specified set of record types.
Definition: LayoutOverrideSource.h:24
clang::InputKind::HeaderUnit_Abs
@ HeaderUnit_Abs
Definition: FrontendOptions.h:174
clang::ASTContext::setExternalSource
void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)
Attach an external AST source to the AST context.
Definition: ASTContext.cpp:1044
clang::FrontendAction::hasPCHSupport
virtual bool hasPCHSupport() const
Does this action support use with PCH?
Definition: FrontendAction.h:191
clang::InputKind::getLanguage
Language getLanguage() const
Definition: FrontendOptions.h:182
clang::HeaderSearch::lookupModule
Module * lookupModule(StringRef ModuleName, SourceLocation ImportLoc=SourceLocation(), bool AllowSearch=true, bool AllowExtraModuleMapSearch=false)
Lookup a module Search for a module with the given name.
Definition: HeaderSearch.cpp:278
HLSLExternalSemaSource.h
clang::InputKind::Precompiled
@ Precompiled
Definition: FrontendOptions.h:164
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:148
clang::FrontendAction::CreateASTConsumer
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile)=0
Create the AST consumer object for this action, if supported.
clang::PreprocessorOptions::AllowPCHWithCompilerErrors
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
Definition: PreprocessorOptions.h:108
clang::FrontendAction::getCompilerInstance
CompilerInstance & getCompilerInstance() const
Definition: FrontendAction.h:119
llvm::SmallString< 16 >
clang::PreprocessorOptions::DisablePCHOrModuleValidation
DisableValidationForModuleKind DisablePCHOrModuleValidation
Whether to disable most of the normal validation performed on precompiled headers and module files.
Definition: PreprocessorOptions.h:104
clang::CompilerInstance::resetAndLeakPreprocessor
void resetAndLeakPreprocessor()
Definition: CompilerInstance.h:449
ASTContext.h
clang::FrontendAction::shouldEraseOutputFiles
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
Definition: FrontendAction.cpp:1116
clang::CompilerInstance::getPreprocessor
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Definition: CompilerInstance.h:442
clang::Module::MissingHeaders
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
Definition: Module.h:250
clang::FrontendAction::getTranslationUnitKind
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
Definition: FrontendAction.h:188
clang::FrontendOptions::ModulesEmbedFiles
std::vector< std::string > ModulesEmbedFiles
The list of files to embed into the compiled module file.
Definition: FrontendOptions.h:474
clang::CompilerInstance::getASTContext
ASTContext & getASTContext() const
Definition: CompilerInstance.h:462
clang::SrcMgr::C_User
@ C_User
Definition: SourceManager.h:80
clang::CompilerInstance::hasFileManager
bool hasFileManager() const
Definition: CompilerInstance.h:399
clang::FrontendAction::setCurrentInput
void setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
Definition: FrontendAction.cpp:139
clang::ASTReader::visitTopLevelModuleMaps
void visitTopLevelModuleMaps(serialization::ModuleFile &MF, llvm::function_ref< void(const FileEntry *)> Visitor)
Visit all the top-level module maps loaded when building the given module file.
Definition: ASTReader.cpp:9173
prepareToBuildModule
static Module * prepareToBuildModule(CompilerInstance &CI, StringRef ModuleMapFilename)
Definition: FrontendAction.cpp:477
DeclGroup.h
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:330
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1241
clang::ModuleMap
Definition: ModuleMap.h:75
clang::CompilerInstance::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts()
Definition: CompilerInstance.h:306
clang::InputKind::getFormat
Format getFormat() const
Definition: FrontendOptions.h:183
clang::FrontendInputFile::isSystem
bool isSystem() const
Definition: FrontendOptions.h:245
clang::WrapperFrontendAction::BeginInvocation
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: FrontendAction.cpp:1163
clang::Module::Parent
Module * Parent
The parent of this module.
Definition: Module.h:133
clang::serialization::PreprocessedEntityID
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:168
clang::Module::PresumedModuleMapFile
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:142
clang::CompilerInstance::setPreprocessor
void setPreprocessor(std::shared_ptr< Preprocessor > Value)
Replace the current preprocessor.
Definition: CompilerInstance.cpp:170
clang::CompilerInstance::setASTReader
void setASTReader(IntrusiveRefCntPtr< ASTReader > Reader)
Definition: CompilerInstance.cpp:203
clang::FrontendAction::getCurrentInput
const FrontendInputFile & getCurrentInput() const
Definition: FrontendAction.h:135
clang::InputKind::ModuleMap
@ ModuleMap
Definition: FrontendOptions.h:163
clang::FrontendAction::EndSourceFileAction
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
Definition: FrontendAction.h:100
clang::Module::submodule_iterator
std::vector< Module * >::iterator submodule_iterator
Definition: Module.h:682
clang::CompilerInstance::getTargetOpts
TargetOptions & getTargetOpts()
Definition: CompilerInstance.h:320
clang::Module::HK_Normal
@ HK_Normal
Definition: Module.h:201
ParseAST.h
clang::FrontendAction::FrontendAction
FrontendAction()
Definition: FrontendAction.cpp:135
clang::CompilerInstance::takeASTConsumer
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
Definition: CompilerInstance.h:492
clang::CompilerInstance::loadModuleFile
bool loadModuleFile(StringRef FileName)
Definition: CompilerInstance.cpp:1683
clang::Module::HK_Private
@ HK_Private
Definition: Module.h:203
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::FrontendInputFile::isPreprocessed
bool isPreprocessed() const
Definition: FrontendOptions.h:250
clang::Module::Directory
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:138
clang::Module::Headers
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:230
clang::DiagnosticConsumer::BeginSourceFile
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:1763
clang::CompilerInstance::getDiagnosticClient
DiagnosticConsumer & getDiagnosticClient() const
Definition: CompilerInstance.h:342
clang::Preprocessor::getBuiltinInfo
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:1016
clang::ASTDeserializationListener
Definition: ASTDeserializationListener.h:30
clang::CompilerInstance::hasPreprocessor
bool hasPreprocessor() const
Definition: CompilerInstance.h:439
clang::WrapperFrontendAction::BeginSourceFileAction
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
Definition: FrontendAction.cpp:1166
LangStandard.h
clang::WrapperFrontendAction::usesPreprocessorOnly
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
Definition: FrontendAction.cpp:1185
clang::HeaderSearch::getModuleCachePath
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:406
clang::CompilerInstance::hasCodeCompletionConsumer
bool hasCodeCompletionConsumer() const
Definition: CompilerInstance.h:558
clang::Language::LLVM_IR
@ LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::ASTUnit::LoadPreprocessorOnly
@ LoadPreprocessorOnly
Load options and the preprocessor state.
Definition: ASTUnit.h:672
getInputBufferForModule
static std::unique_ptr< llvm::MemoryBuffer > getInputBufferForModule(CompilerInstance &CI, Module *M)
Compute the input buffer that should be used to build the specified module.
Definition: FrontendAction.cpp:543
clang::CompilerInstance::getFrontendTimer
llvm::Timer & getFrontendTimer() const
Definition: CompilerInstance.h:576
HeaderSearch.h
clang::FrontendAction::Execute
llvm::Error Execute()
Set the source manager's main input file, and run the action.
Definition: FrontendAction.cpp:1029
ASTUnit.h
clang::CodeCompleteConsumer
Abstract interface for a consumer of code-completion information.
Definition: CodeCompleteConsumer.h:1003
clang::PreprocessorOptions::DeserializedPCHDeclsToErrorOn
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...
Definition: PreprocessorOptions.h:119
GlobalModuleIndex.h
clang::ModuleMap::resolveHeaderDirectives
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
Definition: ModuleMap.cpp:1202
clang::FrontendPluginRegistry
llvm::Registry< PluginASTAction > FrontendPluginRegistry
The frontend plugin registry.
Definition: FrontendPluginRegistry.h:22
ASTConsumer.h
clang::serialization::ModuleManager::getPrimaryModule
ModuleFile & getPrimaryModule()
Returns the primary module associated with the manager, that is, the first module loaded.
Definition: ModuleManager.h:168
clang::CompilerInstance::resetAndLeakASTContext
void resetAndLeakASTContext()
Definition: CompilerInstance.h:467
clang::CompilerInstance::hasSourceManager
bool hasSourceManager() const
Definition: CompilerInstance.h:419
clang::WrapperFrontendAction::shouldEraseOutputFiles
bool shouldEraseOutputFiles() override
Callback at the end of processing a single input, to determine if the output files should be erased o...
Definition: FrontendAction.cpp:1181
clang::FrontendAction::ExecuteAction
virtual void ExecuteAction()=0
Callback to run the program action, using the initialized compiler instance.
clang::ModuleMap::isHeaderUnavailableInModule
bool isHeaderUnavailableInModule(const FileEntry *Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
Definition: ModuleMap.cpp:695
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:125
LayoutOverrideSource.h
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:78
clang::FrontendInputFile::isEmpty
bool isEmpty() const
Definition: FrontendOptions.h:247
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:341
clang::HLSLExternalSemaSource
Definition: HLSLExternalSemaSource.h:21
std
Definition: Format.h:4303
clang::TranslationUnitKind
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:887
clang::FrontendOptions::ModuleFiles
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input.
Definition: FrontendOptions.h:471
clang::FrontendOptions::OriginalModuleMap
std::string OriginalModuleMap
When the input is a module map, the original module map file from which that map was inferred,...
Definition: FrontendOptions.h:430
clang::SourceManager::initializeForReplay
void initializeForReplay(const SourceManager &Old)
Initialize this source manager suitably to replay the compilation described by Old.
Definition: SourceManager.cpp:361
clang::CompilerInstance::getTarget
TargetInfo & getTarget() const
Definition: CompilerInstance.h:369
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:868
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::createChainedIncludesSource
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
The ChainedIncludesSource class converts headers to chained PCHs in memory, mainly for testing.
Definition: ChainedIncludesSource.cpp:113
clang
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::SourceManager::createFileID
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
Definition: SourceManager.cpp:532
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:752
clang::Module::getModuleInputBufferName
static StringRef getModuleInputBufferName()
Definition: Module.h:703
clang::CompilerInstance::resetAndLeakSema
void resetAndLeakSema()
Definition: CompilerInstance.cpp:2277
clang::IdentifierTable::PrintStats
void PrintStats() const
Print some statistics to stderr that indicate how well the hashing is doing.
Definition: IdentifierTable.cpp:383
FrontendDiagnostic.h
clang::FrontendAction::isCurrentFileAST
bool isCurrentFileAST() const
Definition: FrontendAction.h:130
operator+=
static SmallVectorImpl< char > & operator+=(SmallVectorImpl< char > &Includes, StringRef RHS)
Definition: FrontendAction.cpp:297
ASTReader.h
clang::CompilerInstance::getCodeCompletionConsumer
CodeCompleteConsumer & getCodeCompletionConsumer() const
Definition: CompilerInstance.h:560
clang::FileEntry::getName
StringRef getName() const
Definition: FileEntry.h:361
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::Module::getUmbrellaHeader
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:613
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::InputKind::getHeaderUnitKind
HeaderUnitKind getHeaderUnitKind() const
Definition: FrontendOptions.h:184
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1035
clang::CompilerInstance::createASTContext
void createASTContext()
Create the AST context.
Definition: CompilerInstance.cpp:552
clang::WrapperFrontendAction::WrappedAction
std::unique_ptr< FrontendAction > WrappedAction
Definition: FrontendAction.h:307
clang::Module::IsExternC
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition: Module.h:295
clang::Module::submodule_end
submodule_iterator submodule_end()
Definition: Module.h:687
clang::WrapperFrontendAction::PrepareToExecuteAction
bool PrepareToExecuteAction(CompilerInstance &CI) override
Prepare to execute the action on the given CompilerInstance.
Definition: FrontendAction.cpp:1155
clang::FrontendAction::BeginSourceFileAction
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
Definition: FrontendAction.h:85
clang::FileManager::getDirectory
llvm::ErrorOr< const DirectoryEntry * > getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
Definition: FileManager.cpp:189
clang::CompilerInstance::setFileManager
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
Definition: CompilerInstance.cpp:162
clang::ASTUnit::LoadEverything
@ LoadEverything
Load everything, including Sema.
Definition: ASTUnit.h:678
clang::SourceManager::getModuleBuildStack
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
Definition: SourceManager.h:821
clang::FileManager::getFile
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:197
clang::ASTFrontendAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
Definition: FrontendAction.cpp:1124
CompilerInstance.h
clang::WrapperFrontendAction::EndSourceFile
void EndSourceFile() override
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
Definition: FrontendAction.cpp:1177
clang::CompilerInstance::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInstance.h:282
clang::WrapperFrontendAction::hasASTFileSupport
bool hasASTFileSupport() const override
Does this action support use with AST files?
Definition: FrontendAction.cpp:1194
clang::CompilerInstance::getASTReader
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition: CompilerInstance.cpp:200
clang::CompilerInstance::setASTContext
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
Definition: CompilerInstance.cpp:174
clang::FrontendOptions::DisableFree
unsigned DisableFree
Disable memory freeing on exit.
Definition: FrontendOptions.h:271
clang::Module::addTopHeader
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
Definition: Module.cpp:252
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
clang::Preprocessor::checkModuleIsAvailable
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
Definition: PPDirectives.cpp:1888
clang::CompilerInstance::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Definition: CompilerInstance.h:334
clang::CompilerInstance::getSourceManager
SourceManager & getSourceManager() const
Return the current source manager.
Definition: CompilerInstance.h:422
llvm::SmallVectorImpl< char >
clang::PluginASTAction::CmdlineAfterMainAction
@ CmdlineAfterMainAction
Execute the action after the main action if on the command line.
Definition: FrontendAction.h:275
clang::FrontendAction::setCompilerInstance
void setCompilerInstance(CompilerInstance *Value)
Definition: FrontendAction.h:124
clang::InputKind::HeaderUnit_System
@ HeaderUnit_System
Definition: FrontendOptions.h:173
clang::SrcMgr::C_System
@ C_System
Definition: SourceManager.h:81
clang::WrapperFrontendAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendAction.cpp:1159
clang::CompilerInstance::createFileManager
FileManager * createFileManager(IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create the file manager and replace any existing one with it.
Definition: CompilerInstance.cpp:372
clang::CompilerInstance::getSpecificModuleCachePath
std::string getSpecificModuleCachePath(StringRef ModuleHash)
Definition: CompilerInstance.cpp:542
clang::CompilerInstance::createSema
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
Definition: CompilerInstance.cpp:746
clang::FrontendAction::usesPreprocessorOnly
virtual bool usesPreprocessorOnly() const =0
Does this action only use the preprocessor?
Previous
StateNode * Previous
Definition: UnwrappedLineFormatter.cpp:1128
PreprocessorOptions.h
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::CompilerInstance::setSourceManager
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
Definition: CompilerInstance.cpp:166
clang::CompilerInstance::createPreprocessor
void createPreprocessor(TranslationUnitKind TUKind)
Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...
Definition: CompilerInstance.cpp:447
clang::ParseAST
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:99
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:1011
clang::serialization::DeclID
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:68
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:218
clang::ASTReader::isAcceptableASTFile
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, StringRef ExistingModuleCachePath)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
Definition: ASTReader.cpp:5447
ReadOriginalFileName
static SourceLocation ReadOriginalFileName(CompilerInstance &CI, std::string &InputFile, bool IsModuleMap=false)
For preprocessed files, if the first line is the linemarker and specifies the original source file na...
Definition: FrontendAction.cpp:242
clang::serialization::SelectorID
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:153
clang::SrcMgr::C_User_ModuleMap
@ C_User_ModuleMap
Definition: SourceManager.h:83
clang::InputKind::isPreprocessed
bool isPreprocessed() const
Definition: FrontendOptions.h:187
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::WrapperFrontendAction::EndSourceFileAction
void EndSourceFileAction() override
Callback at the end of processing a single input.
Definition: FrontendAction.cpp:1178
clang::CompilerInstance::clearOutputFiles
void clearOutputFiles(bool EraseFiles)
clearOutputFiles - Clear the output file list.
Definition: CompilerInstance.cpp:759
clang::CompilerInstance::shouldBuildGlobalModuleIndex
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
Definition: CompilerInstance.cpp:78
clang::CompilerInstance::createSourceManager
void createSourceManager(FileManager &FileMgr)
Create the source manager and replace any existing one with it.
Definition: CompilerInstance.cpp:385
clang::Builtin::Context::initializeBuiltins
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:102
clang::LangOptions::ModuleName
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:410
clang::serialization::ModuleFile
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:111
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:776
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:142
clang::FrontendOptions::CodeCompletionAt
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
Definition: FrontendOptions.h:442
clang::HeaderSearch::PrintStats
void PrintStats()
Definition: HeaderSearch.cpp:90
clang::CompilerInstance::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts()
Definition: CompilerInstance.h:289
clang::CompilerInstance::createPCHExternalASTSource
void createPCHExternalASTSource(StringRef Path, DisableValidationForModuleKind DisableValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
Create an external AST source to read a PCH file and attach it to the AST context.
Definition: CompilerInstance.cpp:611
clang::Preprocessor::setMainFileDir
void setMainFileDir(const DirectoryEntry *Dir)
Set the directory in which the main file should be considered to have been found, if it is not a real...
Definition: Preprocessor.h:1800
clang::Module::IsInferred
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition: Module.h:298
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
clang::PreprocessorOptions::ImplicitPCHInclude
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Definition: PreprocessorOptions.h:97
clang::ASTContext::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: ASTContext.cpp:1499
clang::ASTContext::setASTMutationListener
void setASTMutationListener(ASTMutationListener *Listener)
Attach an AST mutation listener to the AST context.
Definition: ASTContext.h:1192
clang::PluginASTAction::CmdlineBeforeMainAction
@ CmdlineBeforeMainAction
Execute the action before the main action if on the command line.
Definition: FrontendAction.h:273
clang::PluginASTAction::ActionType
ActionType
Definition: FrontendAction.h:272
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1537
clang::HeaderSearch::LookupFile
Optional< FileEntryRef > LookupFile(StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef< std::pair< const FileEntry *, const DirectoryEntry * >> Includers, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool BuildSystemModule=false)
Given a "foo" or <foo> reference, look up the indicated file, return null on failure.
Definition: HeaderSearch.cpp:836
clang::Decl::getDeclKindName
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
clang::CompilerInstance::hasASTContext
bool hasASTContext() const
Definition: CompilerInstance.h:460
clang::SourceManager::setFileIsTransient
void setFileIsTransient(const FileEntry *SourceFile)
Specify that a file is transient.
Definition: SourceManager.cpp:721
clang::ModuleMap::canInferFrameworkModule
bool canInferFrameworkModule(const DirectoryEntry *Dir) const
Check whether a framework module can be inferred in the given directory.
Definition: ModuleMap.h:595
MultiplexConsumer.h