clang  9.0.0svn
FrontendActions.cpp
Go to the documentation of this file.
1 //===--- FrontendActions.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"
16 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/HeaderSearch.h"
19 #include "clang/Lex/Preprocessor.h"
24 #include "llvm/Support/FileSystem.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include "llvm/Support/Path.h"
27 #include "llvm/Support/YAMLTraits.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include <memory>
30 #include <system_error>
31 
32 using namespace clang;
33 
34 namespace {
35 CodeCompleteConsumer *GetCodeCompletionConsumer(CompilerInstance &CI) {
37  : nullptr;
38 }
39 
40 void EnsureSemaIsCreated(CompilerInstance &CI, FrontendAction &Action) {
41  if (Action.hasCodeCompletionSupport() &&
44 
45  if (!CI.hasSema())
47  GetCodeCompletionConsumer(CI));
48 }
49 } // namespace
50 
51 //===----------------------------------------------------------------------===//
52 // Custom Actions
53 //===----------------------------------------------------------------------===//
54 
55 std::unique_ptr<ASTConsumer>
56 InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
57  return llvm::make_unique<ASTConsumer>();
58 }
59 
60 void InitOnlyAction::ExecuteAction() {
61 }
62 
63 //===----------------------------------------------------------------------===//
64 // AST Consumer Actions
65 //===----------------------------------------------------------------------===//
66 
67 std::unique_ptr<ASTConsumer>
69  if (std::unique_ptr<raw_ostream> OS =
70  CI.createDefaultOutputFile(false, InFile))
71  return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter);
72  return nullptr;
73 }
74 
75 std::unique_ptr<ASTConsumer>
77  const FrontendOptions &Opts = CI.getFrontendOpts();
78  return CreateASTDumper(nullptr /*Dump to stdout.*/, Opts.ASTDumpFilter,
79  Opts.ASTDumpDecls, Opts.ASTDumpAll,
80  Opts.ASTDumpLookups, Opts.ASTDumpFormat);
81 }
82 
83 std::unique_ptr<ASTConsumer>
85  return CreateASTDeclNodeLister();
86 }
87 
88 std::unique_ptr<ASTConsumer>
90  return CreateASTViewer();
91 }
92 
93 std::unique_ptr<ASTConsumer>
95  std::string Sysroot;
96  if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot))
97  return nullptr;
98 
99  std::string OutputFile;
100  std::unique_ptr<raw_pwrite_stream> OS =
101  CreateOutputFile(CI, InFile, /*ref*/ OutputFile);
102  if (!OS)
103  return nullptr;
104 
106  Sysroot.clear();
107 
108  const auto &FrontendOpts = CI.getFrontendOpts();
109  auto Buffer = std::make_shared<PCHBuffer>();
110  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
111  Consumers.push_back(llvm::make_unique<PCHGenerator>(
112  CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
113  FrontendOpts.ModuleFileExtensions,
115  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
116  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
117  CI, InFile, OutputFile, std::move(OS), Buffer));
118 
119  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
120 }
121 
123  std::string &Sysroot) {
124  Sysroot = CI.getHeaderSearchOpts().Sysroot;
125  if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
126  CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
127  return false;
128  }
129 
130  return true;
131 }
132 
133 std::unique_ptr<llvm::raw_pwrite_stream>
135  std::string &OutputFile) {
136  // We use createOutputFile here because this is exposed via libclang, and we
137  // must disable the RemoveFileOnSignal behavior.
138  // We use a temporary to avoid race conditions.
139  std::unique_ptr<raw_pwrite_stream> OS =
140  CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
141  /*RemoveFileOnSignal=*/false, InFile,
142  /*Extension=*/"", /*UseTemporary=*/true);
143  if (!OS)
144  return nullptr;
145 
146  OutputFile = CI.getFrontendOpts().OutputFile;
147  return OS;
148 }
149 
151  if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
152  return false;
154 }
155 
157  CI.getLangOpts().CompilingPCH = true;
158  return true;
159 }
160 
161 std::unique_ptr<ASTConsumer>
163  StringRef InFile) {
164  std::unique_ptr<raw_pwrite_stream> OS = CreateOutputFile(CI, InFile);
165  if (!OS)
166  return nullptr;
167 
168  std::string OutputFile = CI.getFrontendOpts().OutputFile;
169  std::string Sysroot;
170 
171  auto Buffer = std::make_shared<PCHBuffer>();
172  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
173 
174  Consumers.push_back(llvm::make_unique<PCHGenerator>(
175  CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
177  /*AllowASTWithErrors=*/false,
178  /*IncludeTimestamps=*/
180  /*ShouldCacheASTInMemory=*/
182  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
183  CI, InFile, OutputFile, std::move(OS), Buffer));
184  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
185 }
186 
187 bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
188  CompilerInstance &CI) {
189  if (!CI.getLangOpts().Modules) {
190  CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
191  return false;
192  }
193 
195 }
196 
197 std::unique_ptr<raw_pwrite_stream>
198 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
199  StringRef InFile) {
200  // If no output file was provided, figure out where this module would go
201  // in the module cache.
202  if (CI.getFrontendOpts().OutputFile.empty()) {
203  StringRef ModuleMapFile = CI.getFrontendOpts().OriginalModuleMap;
204  if (ModuleMapFile.empty())
205  ModuleMapFile = InFile;
206 
210  ModuleMapFile);
211  }
212 
213  // We use createOutputFile here because this is exposed via libclang, and we
214  // must disable the RemoveFileOnSignal behavior.
215  // We use a temporary to avoid race conditions.
216  return CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
217  /*RemoveFileOnSignal=*/false, InFile,
218  /*Extension=*/"", /*UseTemporary=*/true,
219  /*CreateMissingDirectories=*/true);
220 }
221 
222 bool GenerateModuleInterfaceAction::BeginSourceFileAction(
223  CompilerInstance &CI) {
224  if (!CI.getLangOpts().ModulesTS && !CI.getLangOpts().CPlusPlusModules) {
225  CI.getDiagnostics().Report(diag::err_module_interface_requires_cpp_modules);
226  return false;
227  }
228 
229  CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
230 
232 }
233 
234 std::unique_ptr<raw_pwrite_stream>
235 GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
236  StringRef InFile) {
237  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
238 }
239 
240 bool GenerateHeaderModuleAction::PrepareToExecuteAction(
241  CompilerInstance &CI) {
242  if (!CI.getLangOpts().Modules) {
243  CI.getDiagnostics().Report(diag::err_header_module_requires_modules);
244  return false;
245  }
246 
247  auto &Inputs = CI.getFrontendOpts().Inputs;
248  if (Inputs.empty())
250 
251  auto Kind = Inputs[0].getKind();
252 
253  // Convert the header file inputs into a single module input buffer.
254  SmallString<256> HeaderContents;
255  ModuleHeaders.reserve(Inputs.size());
256  for (const FrontendInputFile &FIF : Inputs) {
257  // FIXME: We should support re-compiling from an AST file.
258  if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
259  CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
260  << (FIF.isFile() ? FIF.getFile()
261  : FIF.getBuffer()->getBufferIdentifier());
262  return true;
263  }
264 
265  HeaderContents += "#include \"";
266  HeaderContents += FIF.getFile();
267  HeaderContents += "\"\n";
268  ModuleHeaders.push_back(FIF.getFile());
269  }
270  Buffer = llvm::MemoryBuffer::getMemBufferCopy(
271  HeaderContents, Module::getModuleInputBufferName());
272 
273  // Set that buffer up as our "real" input.
274  Inputs.clear();
275  Inputs.push_back(FrontendInputFile(Buffer.get(), Kind, /*IsSystem*/false));
276 
278 }
279 
280 bool GenerateHeaderModuleAction::BeginSourceFileAction(
281  CompilerInstance &CI) {
282  CI.getLangOpts().setCompilingModule(LangOptions::CMK_HeaderModule);
283 
284  // Synthesize a Module object for the given headers.
285  auto &HS = CI.getPreprocessor().getHeaderSearchInfo();
287  for (StringRef Name : ModuleHeaders) {
288  const DirectoryLookup *CurDir = nullptr;
289  const FileEntry *FE = HS.LookupFile(
290  Name, SourceLocation(), /*Angled*/ false, nullptr, CurDir,
291  None, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
292  if (!FE) {
293  CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
294  << Name;
295  continue;
296  }
297  Headers.push_back({Name, FE});
298  }
299  HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
300 
302 }
303 
304 std::unique_ptr<raw_pwrite_stream>
305 GenerateHeaderModuleAction::CreateOutputFile(CompilerInstance &CI,
306  StringRef InFile) {
307  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
308 }
309 
311 }
312 
313 std::unique_ptr<ASTConsumer>
315  return llvm::make_unique<ASTConsumer>();
316 }
317 
318 std::unique_ptr<ASTConsumer>
320  StringRef InFile) {
321  return llvm::make_unique<ASTConsumer>();
322 }
323 
324 std::unique_ptr<ASTConsumer>
326  return llvm::make_unique<ASTConsumer>();
327 }
328 
332  const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
333  std::unique_ptr<ASTReader> Reader(new ASTReader(
334  CI.getPreprocessor(), CI.getModuleCache(), &CI.getASTContext(),
336  Sysroot.empty() ? "" : Sysroot.c_str(),
337  /*DisableValidation*/ false,
338  /*AllowPCHWithCompilerErrors*/ false,
339  /*AllowConfigurationMismatch*/ true,
340  /*ValidateSystemInputs*/ true));
341 
342  Reader->ReadAST(getCurrentFile(),
343  Preamble ? serialization::MK_Preamble
345  SourceLocation(),
347 }
348 
349 namespace {
350 struct TemplightEntry {
351  std::string Name;
352  std::string Kind;
353  std::string Event;
354  std::string DefinitionLocation;
355  std::string PointOfInstantiation;
356 };
357 } // namespace
358 
359 namespace llvm {
360 namespace yaml {
361 template <> struct MappingTraits<TemplightEntry> {
362  static void mapping(IO &io, TemplightEntry &fields) {
363  io.mapRequired("name", fields.Name);
364  io.mapRequired("kind", fields.Kind);
365  io.mapRequired("event", fields.Event);
366  io.mapRequired("orig", fields.DefinitionLocation);
367  io.mapRequired("poi", fields.PointOfInstantiation);
368  }
369 };
370 } // namespace yaml
371 } // namespace llvm
372 
373 namespace {
374 class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
375  using CodeSynthesisContext = Sema::CodeSynthesisContext;
376 
377 public:
378  void initialize(const Sema &) override {}
379 
380  void finalize(const Sema &) override {}
381 
382  void atTemplateBegin(const Sema &TheSema,
383  const CodeSynthesisContext &Inst) override {
384  displayTemplightEntry<true>(llvm::outs(), TheSema, Inst);
385  }
386 
387  void atTemplateEnd(const Sema &TheSema,
388  const CodeSynthesisContext &Inst) override {
389  displayTemplightEntry<false>(llvm::outs(), TheSema, Inst);
390  }
391 
392 private:
393  static std::string toString(CodeSynthesisContext::SynthesisKind Kind) {
394  switch (Kind) {
395  case CodeSynthesisContext::TemplateInstantiation:
396  return "TemplateInstantiation";
397  case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
398  return "DefaultTemplateArgumentInstantiation";
399  case CodeSynthesisContext::DefaultFunctionArgumentInstantiation:
400  return "DefaultFunctionArgumentInstantiation";
401  case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution:
402  return "ExplicitTemplateArgumentSubstitution";
403  case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
404  return "DeducedTemplateArgumentSubstitution";
405  case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
406  return "PriorTemplateArgumentSubstitution";
407  case CodeSynthesisContext::DefaultTemplateArgumentChecking:
408  return "DefaultTemplateArgumentChecking";
409  case CodeSynthesisContext::ExceptionSpecEvaluation:
410  return "ExceptionSpecEvaluation";
411  case CodeSynthesisContext::ExceptionSpecInstantiation:
412  return "ExceptionSpecInstantiation";
413  case CodeSynthesisContext::DeclaringSpecialMember:
414  return "DeclaringSpecialMember";
415  case CodeSynthesisContext::DefiningSynthesizedFunction:
416  return "DefiningSynthesizedFunction";
417  case CodeSynthesisContext::Memoization:
418  return "Memoization";
419  }
420  return "";
421  }
422 
423  template <bool BeginInstantiation>
424  static void displayTemplightEntry(llvm::raw_ostream &Out, const Sema &TheSema,
425  const CodeSynthesisContext &Inst) {
426  std::string YAML;
427  {
428  llvm::raw_string_ostream OS(YAML);
429  llvm::yaml::Output YO(OS);
430  TemplightEntry Entry =
431  getTemplightEntry<BeginInstantiation>(TheSema, Inst);
432  llvm::yaml::EmptyContext Context;
433  llvm::yaml::yamlize(YO, Entry, true, Context);
434  }
435  Out << "---" << YAML << "\n";
436  }
437 
438  template <bool BeginInstantiation>
439  static TemplightEntry getTemplightEntry(const Sema &TheSema,
440  const CodeSynthesisContext &Inst) {
441  TemplightEntry Entry;
442  Entry.Kind = toString(Inst.Kind);
443  Entry.Event = BeginInstantiation ? "Begin" : "End";
444  if (auto *NamedTemplate = dyn_cast_or_null<NamedDecl>(Inst.Entity)) {
445  llvm::raw_string_ostream OS(Entry.Name);
446  NamedTemplate->getNameForDiagnostic(OS, TheSema.getLangOpts(), true);
447  const PresumedLoc DefLoc =
448  TheSema.getSourceManager().getPresumedLoc(Inst.Entity->getLocation());
449  if(!DefLoc.isInvalid())
450  Entry.DefinitionLocation = std::string(DefLoc.getFilename()) + ":" +
451  std::to_string(DefLoc.getLine()) + ":" +
452  std::to_string(DefLoc.getColumn());
453  }
454  const PresumedLoc PoiLoc =
455  TheSema.getSourceManager().getPresumedLoc(Inst.PointOfInstantiation);
456  if (!PoiLoc.isInvalid()) {
457  Entry.PointOfInstantiation = std::string(PoiLoc.getFilename()) + ":" +
458  std::to_string(PoiLoc.getLine()) + ":" +
459  std::to_string(PoiLoc.getColumn());
460  }
461  return Entry;
462  }
463 };
464 } // namespace
465 
466 std::unique_ptr<ASTConsumer>
468  return llvm::make_unique<ASTConsumer>();
469 }
470 
473 
474  // This part is normally done by ASTFrontEndAction, but needs to happen
475  // before Templight observers can be created
476  // FIXME: Move the truncation aspect of this into Sema, we delayed this till
477  // here so the source manager would be initialized.
478  EnsureSemaIsCreated(CI, *this);
479 
480  CI.getSema().TemplateInstCallbacks.push_back(
481  llvm::make_unique<DefaultTemplateInstCallback>());
483 }
484 
485 namespace {
486  /// AST reader listener that dumps module information for a module
487  /// file.
488  class DumpModuleInfoListener : public ASTReaderListener {
489  llvm::raw_ostream &Out;
490 
491  public:
492  DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { }
493 
494 #define DUMP_BOOLEAN(Value, Text) \
495  Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n"
496 
497  bool ReadFullVersionInformation(StringRef FullVersion) override {
498  Out.indent(2)
499  << "Generated by "
500  << (FullVersion == getClangFullRepositoryVersion()? "this"
501  : "a different")
502  << " Clang: " << FullVersion << "\n";
504  }
505 
506  void ReadModuleName(StringRef ModuleName) override {
507  Out.indent(2) << "Module name: " << ModuleName << "\n";
508  }
509  void ReadModuleMapFile(StringRef ModuleMapPath) override {
510  Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
511  }
512 
513  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
514  bool AllowCompatibleDifferences) override {
515  Out.indent(2) << "Language options:\n";
516 #define LANGOPT(Name, Bits, Default, Description) \
517  DUMP_BOOLEAN(LangOpts.Name, Description);
518 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
519  Out.indent(4) << Description << ": " \
520  << static_cast<unsigned>(LangOpts.get##Name()) << "\n";
521 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
522  Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
523 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
524 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
525 #include "clang/Basic/LangOptions.def"
526 
527  if (!LangOpts.ModuleFeatures.empty()) {
528  Out.indent(4) << "Module features:\n";
529  for (StringRef Feature : LangOpts.ModuleFeatures)
530  Out.indent(6) << Feature << "\n";
531  }
532 
533  return false;
534  }
535 
536  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
537  bool AllowCompatibleDifferences) override {
538  Out.indent(2) << "Target options:\n";
539  Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
540  Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n";
541  Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n";
542 
543  if (!TargetOpts.FeaturesAsWritten.empty()) {
544  Out.indent(4) << "Target features:\n";
545  for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size();
546  I != N; ++I) {
547  Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n";
548  }
549  }
550 
551  return false;
552  }
553 
554  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
555  bool Complain) override {
556  Out.indent(2) << "Diagnostic options:\n";
557 #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
558 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
559  Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
560 #define VALUE_DIAGOPT(Name, Bits, Default) \
561  Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
562 #include "clang/Basic/DiagnosticOptions.def"
563 
564  Out.indent(4) << "Diagnostic flags:\n";
565  for (const std::string &Warning : DiagOpts->Warnings)
566  Out.indent(6) << "-W" << Warning << "\n";
567  for (const std::string &Remark : DiagOpts->Remarks)
568  Out.indent(6) << "-R" << Remark << "\n";
569 
570  return false;
571  }
572 
573  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
574  StringRef SpecificModuleCachePath,
575  bool Complain) override {
576  Out.indent(2) << "Header search options:\n";
577  Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n";
578  Out.indent(4) << "Resource dir [ -resource-dir=]: '" << HSOpts.ResourceDir << "'\n";
579  Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n";
581  "Use builtin include directories [-nobuiltininc]");
583  "Use standard system include directories [-nostdinc]");
585  "Use standard C++ include directories [-nostdinc++]");
586  DUMP_BOOLEAN(HSOpts.UseLibcxx,
587  "Use libc++ (rather than libstdc++) [-stdlib=]");
588  return false;
589  }
590 
591  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
592  bool Complain,
593  std::string &SuggestedPredefines) override {
594  Out.indent(2) << "Preprocessor options:\n";
596  "Uses compiler/target-specific predefines [-undef]");
598  "Uses detailed preprocessing record (for indexing)");
599 
600  if (!PPOpts.Macros.empty()) {
601  Out.indent(4) << "Predefined macros:\n";
602  }
603 
604  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
605  I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end();
606  I != IEnd; ++I) {
607  Out.indent(6);
608  if (I->second)
609  Out << "-U";
610  else
611  Out << "-D";
612  Out << I->first << "\n";
613  }
614  return false;
615  }
616 
617  /// Indicates that a particular module file extension has been read.
618  void readModuleFileExtension(
619  const ModuleFileExtensionMetadata &Metadata) override {
620  Out.indent(2) << "Module file extension '"
621  << Metadata.BlockName << "' " << Metadata.MajorVersion
622  << "." << Metadata.MinorVersion;
623  if (!Metadata.UserInfo.empty()) {
624  Out << ": ";
625  Out.write_escaped(Metadata.UserInfo);
626  }
627 
628  Out << "\n";
629  }
630 
631  /// Tells the \c ASTReaderListener that we want to receive the
632  /// input files of the AST file via \c visitInputFile.
633  bool needsInputFileVisitation() override { return true; }
634 
635  /// Tells the \c ASTReaderListener that we want to receive the
636  /// input files of the AST file via \c visitInputFile.
637  bool needsSystemInputFileVisitation() override { return true; }
638 
639  /// Indicates that the AST file contains particular input file.
640  ///
641  /// \returns true to continue receiving the next input file, false to stop.
642  bool visitInputFile(StringRef Filename, bool isSystem,
643  bool isOverridden, bool isExplicitModule) override {
644 
645  Out.indent(2) << "Input file: " << Filename;
646 
647  if (isSystem || isOverridden || isExplicitModule) {
648  Out << " [";
649  if (isSystem) {
650  Out << "System";
651  if (isOverridden || isExplicitModule)
652  Out << ", ";
653  }
654  if (isOverridden) {
655  Out << "Overridden";
656  if (isExplicitModule)
657  Out << ", ";
658  }
659  if (isExplicitModule)
660  Out << "ExplicitModule";
661 
662  Out << "]";
663  }
664 
665  Out << "\n";
666 
667  return true;
668  }
669 
670  /// Returns true if this \c ASTReaderListener wants to receive the
671  /// imports of the AST file via \c visitImport, false otherwise.
672  bool needsImportVisitation() const override { return true; }
673 
674  /// If needsImportVisitation returns \c true, this is called for each
675  /// AST file imported by this AST file.
676  void visitImport(StringRef ModuleName, StringRef Filename) override {
677  Out.indent(2) << "Imports module '" << ModuleName
678  << "': " << Filename.str() << "\n";
679  }
680 #undef DUMP_BOOLEAN
681  };
682 }
683 
685  // The Object file reader also supports raw ast files and there is no point in
686  // being strict about the module file format in -module-file-info mode.
687  CI.getHeaderSearchOpts().ModuleFormat = "obj";
688  return true;
689 }
690 
692  // Set up the output file.
693  std::unique_ptr<llvm::raw_fd_ostream> OutFile;
694  StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
695  if (!OutputFileName.empty() && OutputFileName != "-") {
696  std::error_code EC;
697  OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
698  llvm::sys::fs::F_Text));
699  }
700  llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
701 
702  Out << "Information for module file '" << getCurrentFile() << "':\n";
703  auto &FileMgr = getCompilerInstance().getFileManager();
704  auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
705  StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
706  bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
707  Magic[2] == 'C' && Magic[3] == 'H');
708  Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
709 
711  DumpModuleInfoListener Listener(Out);
712  HeaderSearchOptions &HSOpts =
713  PP.getHeaderSearchInfo().getHeaderSearchOpts();
715  getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(),
716  /*FindModuleFileExtensions=*/true, Listener,
718 }
719 
720 //===----------------------------------------------------------------------===//
721 // Preprocessor Actions
722 //===----------------------------------------------------------------------===//
723 
727 
728  // Start lexing the specified input file.
729  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
730  Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts());
731  RawLex.SetKeepWhitespaceMode(true);
732 
733  Token RawTok;
734  RawLex.LexFromRawLexer(RawTok);
735  while (RawTok.isNot(tok::eof)) {
736  PP.DumpToken(RawTok, true);
737  llvm::errs() << "\n";
738  RawLex.LexFromRawLexer(RawTok);
739  }
740 }
741 
744  // Start preprocessing the specified input file.
745  Token Tok;
746  PP.EnterMainSourceFile();
747  do {
748  PP.Lex(Tok);
749  PP.DumpToken(Tok, true);
750  llvm::errs() << "\n";
751  } while (Tok.isNot(tok::eof));
752 }
753 
756 
757  // Ignore unknown pragmas.
758  PP.IgnorePragmas();
759 
760  Token Tok;
761  // Start parsing the specified input file.
762  PP.EnterMainSourceFile();
763  do {
764  PP.Lex(Tok);
765  } while (Tok.isNot(tok::eof));
766 }
767 
770  // Output file may need to be set to 'Binary', to avoid converting Unix style
771  // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
772  //
773  // Look to see what type of line endings the file uses. If there's a
774  // CRLF, then we won't open the file up in binary mode. If there is
775  // just an LF or CR, then we will open the file up in binary mode.
776  // In this fashion, the output format should match the input format, unless
777  // the input format has inconsistent line endings.
778  //
779  // This should be a relatively fast operation since most files won't have
780  // all of their source code on a single line. However, that is still a
781  // concern, so if we scan for too long, we'll just assume the file should
782  // be opened in binary mode.
783  bool BinaryMode = true;
784  bool InvalidFile = false;
785  const SourceManager& SM = CI.getSourceManager();
786  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
787  &InvalidFile);
788  if (!InvalidFile) {
789  const char *cur = Buffer->getBufferStart();
790  const char *end = Buffer->getBufferEnd();
791  const char *next = (cur != end) ? cur + 1 : end;
792 
793  // Limit ourselves to only scanning 256 characters into the source
794  // file. This is mostly a sanity check in case the file has no
795  // newlines whatsoever.
796  if (end - cur > 256) end = cur + 256;
797 
798  while (next < end) {
799  if (*cur == 0x0D) { // CR
800  if (*next == 0x0A) // CRLF
801  BinaryMode = false;
802 
803  break;
804  } else if (*cur == 0x0A) // LF
805  break;
806 
807  ++cur;
808  ++next;
809  }
810  }
811 
812  std::unique_ptr<raw_ostream> OS =
814  if (!OS) return;
815 
816  // If we're preprocessing a module map, start by dumping the contents of the
817  // module itself before switching to the input buffer.
818  auto &Input = getCurrentInput();
819  if (Input.getKind().getFormat() == InputKind::ModuleMap) {
820  if (Input.isFile()) {
821  (*OS) << "# 1 \"";
822  OS->write_escaped(Input.getFile());
823  (*OS) << "\"\n";
824  }
825  getCurrentModule()->print(*OS);
826  (*OS) << "#pragma clang module contents\n";
827  }
828 
831 }
832 
834  switch (getCurrentFileKind().getLanguage()) {
835  case InputKind::C:
836  case InputKind::CXX:
837  case InputKind::ObjC:
838  case InputKind::ObjCXX:
839  case InputKind::OpenCL:
840  case InputKind::CUDA:
841  case InputKind::HIP:
842  break;
843 
844  case InputKind::Unknown:
845  case InputKind::Asm:
846  case InputKind::LLVM_IR:
848  // We can't do anything with these.
849  return;
850  }
851 
852  // We don't expect to find any #include directives in a preprocessed input.
853  if (getCurrentFileKind().isPreprocessed())
854  return;
855 
857  auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
858  if (Buffer) {
859  unsigned Preamble =
860  Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).Size;
861  llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
862  }
863 }
864 
865 void DumpCompilerOptionsAction::ExecuteAction() {
867  std::unique_ptr<raw_ostream> OSP =
869  if (!OSP)
870  return;
871 
872  raw_ostream &OS = *OSP;
873  const Preprocessor &PP = CI.getPreprocessor();
874  const LangOptions &LangOpts = PP.getLangOpts();
875 
876  // FIXME: Rather than manually format the JSON (which is awkward due to
877  // needing to remove trailing commas), this should make use of a JSON library.
878  // FIXME: Instead of printing enums as an integral value and specifying the
879  // type as a separate field, use introspection to print the enumerator.
880 
881  OS << "{\n";
882  OS << "\n\"features\" : [\n";
883  {
885 #define FEATURE(Name, Predicate) \
886  ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
887  .toVector(Str);
888 #include "clang/Basic/Features.def"
889 #undef FEATURE
890  // Remove the newline and comma from the last entry to ensure this remains
891  // valid JSON.
892  OS << Str.substr(0, Str.size() - 2);
893  }
894  OS << "\n],\n";
895 
896  OS << "\n\"extensions\" : [\n";
897  {
899 #define EXTENSION(Name, Predicate) \
900  ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
901  .toVector(Str);
902 #include "clang/Basic/Features.def"
903 #undef EXTENSION
904  // Remove the newline and comma from the last entry to ensure this remains
905  // valid JSON.
906  OS << Str.substr(0, Str.size() - 2);
907  }
908  OS << "\n]\n";
909 
910  OS << "}";
911 }
912 
916  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
917 
921  FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(),
923  assert(CI.getDiagnostics().hasErrorOccurred() &&
924  "no errors reported for failure");
925 
926  // Preprocess the source when verifying the diagnostics to capture the
927  // 'expected' comments.
928  if (CI.getDiagnosticOpts().VerifyDiagnostics) {
929  // Make sure we don't emit new diagnostics!
932  PP.EnterMainSourceFile();
933  Token Tok;
934  do {
935  PP.Lex(Tok);
936  } while (Tok.isNot(tok::eof));
937  }
938  return;
939  }
940  llvm::outs() << Output;
941 }
std::string OutputFile
The output file, if any.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
LangOptions & getLangOpts()
std::string OriginalModuleMap
When the input is a module map, the original module map file from which that map was inferred...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
PreprocessorOptions & getPreprocessorOpts()
bool shouldEraseOutputFiles() override
Callback at the end of processing a single input, to determine if the output files should be erased o...
bool minimizeSourceToDependencyDirectives(llvm::StringRef Input, llvm::SmallVectorImpl< char > &Output, llvm::SmallVectorImpl< minimize_source_to_dependency_directives::Token > &Tokens, DiagnosticsEngine *Diags=nullptr, SourceLocation InputSourceLoc=SourceLocation())
Minimize the input down to the preprocessor directives that might have an effect on the dependencies ...
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
std::vector< std::pair< std::string, bool > > Macros
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:76
bool hasErrorOccurred() const
Definition: Diagnostic.h:749
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained)...
Definition: Sema.h:7641
Defines the clang::FileManager interface and associated types.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
Abstract base class for actions which can be performed by the frontend.
DiagnosticOptions & getDiagnosticOpts()
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1297
InMemoryModuleCache & getModuleCache() const
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
std::string ASTDumpFilter
If given, filter dumped AST Decl nodes by this substring.
ASTContext & getASTContext() const
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:84
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:1893
Options for controlling the target.
Definition: TargetOptions.h:26
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition: Sema.h:7466
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
static StringRef getModuleInputBufferName()
Definition: Module.h:581
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Module * getCurrentModule() const
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1522
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:903
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Languages that the frontend can parse and compile.
static bool ComputeASTConsumerArguments(CompilerInstance &CI, std::string &Sysroot)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
This is a base class for callbacks that will be notified at every template instantiation.
CompilerInstance & getCompilerInstance() const
std::string UserInfo
A string containing additional user information that will be stored with the metadata.
const PCHContainerWriter & getPCHContainerWriter() const
Return the appropriate PCHContainerWriter depending on the current CodeGenOptions.
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:908
std::string getCachedModuleFileName(Module *Module)
Retrieve the name of the cached module file that should be used to load the given module...
FrontendOptions & getFrontendOpts()
const FormatToken & Tok
static void mapping(IO &io, TemplightEntry &fields)
StringRef getCurrentFileOrBufferName() const
PreprocessorOutputOptions & getPreprocessorOutputOpts()
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
#define DUMP_BOOLEAN(Value, Text)
const LangOptions & getLangOpts() const
Definition: Sema.h:1285
HeaderSearchOptions & getHeaderSearchOpts()
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
CodeCompleteConsumer & getCodeCompletionConsumer() const
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:233
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:158
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:328
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:227
StringRef Filename
Definition: Format.cpp:1711
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
unsigned ASTDumpAll
Whether we deserialize all decls when forming AST dumps.
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
static PreambleBounds ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines=0)
Compute the preamble of the given file.
Definition: Lexer.cpp:573
bool isInvalid() const
Return true if this object is invalid or uninitialized.
unsigned getLine() const
Return the presumed line number of this location.
Compiling a module from a list of header files.
Definition: LangOptions.h:81
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
void print(raw_ostream &OS, unsigned Indent=0) const
Print the module map for this module to the given stream.
Definition: Module.cpp:419
Defines the clang::Preprocessor interface.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
Represents an unpacked "presumed" location which can be presented to the user.
An input file for the front end.
InputKind getCurrentFileKind() const
const SourceManager & SM
Definition: Format.cpp:1572
unsigned MajorVersion
The major version of the extension data.
std::unique_ptr< raw_pwrite_stream > createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, StringRef BaseInput, StringRef Extension, bool UseTemporary, bool CreateMissingDirectories=false)
Create a new output file and add it to the list of tracked output files, optionally deriving the outp...
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
unsigned MinorVersion
The minor version of the extension data.
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:36
SourceManager & getSourceManager() const
Definition: Preprocessor.h:907
const char * getFilename() const
Return the presumed filename of this location.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Kind
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:42
File is a PCH file treated as the preamble.
Definition: Module.h:53
unsigned getColumn() const
Return the presumed column number of this location.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Assembly: we accept this only so that we can preprocess it.
File is a PCH file treated as such.
Definition: Module.h:50
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we&#39;re handling.
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
std::vector< FrontendInputFile > Inputs
The input files and their types.
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:89
void Lex(Token &Result)
Lex the next token for this preprocessor.
virtual bool PrepareToExecuteAction(CompilerInstance &CI)
Prepare to execute the action on the given CompilerInstance.
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:134
unsigned ASTDumpLookups
Whether we include lookup table dumps in AST dumps.
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:51
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Abstract interface for a consumer of code-completion information.
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
ASTDumpOutputFormat ASTDumpFormat
Specifies the output format of the AST.
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
Dataflow Directional Tag Classes.
FileManager & getFileManager() const
Return the current file manager to the caller.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
const FrontendInputFile & getCurrentInput() const
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:354
FileID getMainFileID() const
Returns the FileID of the main source file.
StringRef getCurrentFile() const
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
virtual std::unique_ptr< ASTConsumer > CreatePCHContainerGenerator(CompilerInstance &CI, const std::string &MainFileName, const std::string &OutputFileName, std::unique_ptr< llvm::raw_pwrite_stream > OS, std::shared_ptr< PCHBuffer > Buffer) const =0
Return an ASTConsumer that can be chained with a PCHGenerator that produces a wrapper file format con...
SourceManager & getSourceManager() const
Return the current source manager.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
FrontendOptions - Options for controlling the behavior of the frontend.
std::string BlockName
The name used to identify this particular extension block within the resulting module file...
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:126
std::vector< std::shared_ptr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
Create the default output file (from the invocation&#39;s options) and add it to the list of tracked outp...
std::unique_ptr< ASTConsumer > CreateASTViewer()
Metadata for a module file extension.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
bool hasCodeCompletionConsumer() const
std::unique_ptr< ASTConsumer > CreateASTDeclNodeLister()
void setSuppressAllDiagnostics(bool Val=true)
Suppress all diagnostics, to silence the front end when we know that we don&#39;t want any more diagnosti...
Definition: Diagnostic.h:635
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
unsigned ASTDumpDecls
Whether we include declaration dumps in AST dumps.
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
SourceManager & getSourceManager() const
Definition: Sema.h:1290
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions)
Read the control block for the named AST file.
Definition: ASTReader.cpp:5030
This is the interface for minimizing header and source files to the minimum necessary preprocessor di...
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
static std::unique_ptr< llvm::raw_pwrite_stream > CreateOutputFile(CompilerInstance &CI, StringRef InFile, std::string &OutputFile)
Creates file to write the PCH into and returns a stream to write it into.
std::unique_ptr< ASTConsumer > CreateASTPrinter(std::unique_ptr< raw_ostream > OS, StringRef FilterString)
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
void SetKeepWhitespaceMode(bool Val)
SetKeepWhitespaceMode - This method lets clients enable or disable whitespace retention mode...
Definition: Lexer.h:212
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:29
std::unique_ptr< ASTConsumer > CreateASTDumper(std::unique_ptr< raw_ostream > OS, StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups, ASTDumpOutputFormat Format)
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:82
This class handles loading and caching of source files into memory.
std::string ModuleFormat
The module/pch container format.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:124
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...