clang  10.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"
17 #include "clang/Frontend/Utils.h"
19 #include "clang/Lex/HeaderSearch.h"
20 #include "clang/Lex/Preprocessor.h"
25 #include "llvm/Support/FileSystem.h"
26 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/YAMLTraits.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include <memory>
31 #include <system_error>
32 
33 using namespace clang;
34 
35 namespace {
36 CodeCompleteConsumer *GetCodeCompletionConsumer(CompilerInstance &CI) {
38  : nullptr;
39 }
40 
41 void EnsureSemaIsCreated(CompilerInstance &CI, FrontendAction &Action) {
42  if (Action.hasCodeCompletionSupport() &&
45 
46  if (!CI.hasSema())
48  GetCodeCompletionConsumer(CI));
49 }
50 } // namespace
51 
52 //===----------------------------------------------------------------------===//
53 // Custom Actions
54 //===----------------------------------------------------------------------===//
55 
56 std::unique_ptr<ASTConsumer>
57 InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
58  return std::make_unique<ASTConsumer>();
59 }
60 
61 void InitOnlyAction::ExecuteAction() {
62 }
63 
64 //===----------------------------------------------------------------------===//
65 // AST Consumer Actions
66 //===----------------------------------------------------------------------===//
67 
68 std::unique_ptr<ASTConsumer>
70  if (std::unique_ptr<raw_ostream> OS =
71  CI.createDefaultOutputFile(false, InFile))
72  return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter);
73  return nullptr;
74 }
75 
76 std::unique_ptr<ASTConsumer>
78  const FrontendOptions &Opts = CI.getFrontendOpts();
79  return CreateASTDumper(nullptr /*Dump to stdout.*/, Opts.ASTDumpFilter,
80  Opts.ASTDumpDecls, Opts.ASTDumpAll,
81  Opts.ASTDumpLookups, Opts.ASTDumpFormat);
82 }
83 
84 std::unique_ptr<ASTConsumer>
86  return CreateASTDeclNodeLister();
87 }
88 
89 std::unique_ptr<ASTConsumer>
91  return CreateASTViewer();
92 }
93 
94 std::unique_ptr<ASTConsumer>
96  std::string Sysroot;
97  if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot))
98  return nullptr;
99 
100  std::string OutputFile;
101  std::unique_ptr<raw_pwrite_stream> OS =
102  CreateOutputFile(CI, InFile, /*ref*/ OutputFile);
103  if (!OS)
104  return nullptr;
105 
107  Sysroot.clear();
108 
109  const auto &FrontendOpts = CI.getFrontendOpts();
110  auto Buffer = std::make_shared<PCHBuffer>();
111  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
112  Consumers.push_back(std::make_unique<PCHGenerator>(
113  CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
114  FrontendOpts.ModuleFileExtensions,
116  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
117  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
118  CI, InFile, OutputFile, std::move(OS), Buffer));
119 
120  return std::make_unique<MultiplexConsumer>(std::move(Consumers));
121 }
122 
124  std::string &Sysroot) {
125  Sysroot = CI.getHeaderSearchOpts().Sysroot;
126  if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
127  CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
128  return false;
129  }
130 
131  return true;
132 }
133 
134 std::unique_ptr<llvm::raw_pwrite_stream>
136  std::string &OutputFile) {
137  // We use createOutputFile here because this is exposed via libclang, and we
138  // must disable the RemoveFileOnSignal behavior.
139  // We use a temporary to avoid race conditions.
140  std::unique_ptr<raw_pwrite_stream> OS =
141  CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
142  /*RemoveFileOnSignal=*/false, InFile,
143  /*Extension=*/"", /*UseTemporary=*/true);
144  if (!OS)
145  return nullptr;
146 
147  OutputFile = CI.getFrontendOpts().OutputFile;
148  return OS;
149 }
150 
152  if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
153  return false;
155 }
156 
158  CI.getLangOpts().CompilingPCH = true;
159  return true;
160 }
161 
162 std::unique_ptr<ASTConsumer>
164  StringRef InFile) {
165  std::unique_ptr<raw_pwrite_stream> OS = CreateOutputFile(CI, InFile);
166  if (!OS)
167  return nullptr;
168 
169  std::string OutputFile = CI.getFrontendOpts().OutputFile;
170  std::string Sysroot;
171 
172  auto Buffer = std::make_shared<PCHBuffer>();
173  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
174 
175  Consumers.push_back(std::make_unique<PCHGenerator>(
176  CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
178  /*AllowASTWithErrors=*/false,
179  /*IncludeTimestamps=*/
181  /*ShouldCacheASTInMemory=*/
183  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
184  CI, InFile, OutputFile, std::move(OS), Buffer));
185  return std::make_unique<MultiplexConsumer>(std::move(Consumers));
186 }
187 
188 bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
189  CompilerInstance &CI) {
190  if (!CI.getLangOpts().Modules) {
191  CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
192  return false;
193  }
194 
196 }
197 
198 std::unique_ptr<raw_pwrite_stream>
199 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
200  StringRef InFile) {
201  // If no output file was provided, figure out where this module would go
202  // in the module cache.
203  if (CI.getFrontendOpts().OutputFile.empty()) {
204  StringRef ModuleMapFile = CI.getFrontendOpts().OriginalModuleMap;
205  if (ModuleMapFile.empty())
206  ModuleMapFile = InFile;
207 
211  ModuleMapFile);
212  }
213 
214  // We use createOutputFile here because this is exposed via libclang, and we
215  // must disable the RemoveFileOnSignal behavior.
216  // We use a temporary to avoid race conditions.
217  return CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
218  /*RemoveFileOnSignal=*/false, InFile,
219  /*Extension=*/"", /*UseTemporary=*/true,
220  /*CreateMissingDirectories=*/true);
221 }
222 
223 bool GenerateModuleInterfaceAction::BeginSourceFileAction(
224  CompilerInstance &CI) {
225  if (!CI.getLangOpts().ModulesTS && !CI.getLangOpts().CPlusPlusModules) {
226  CI.getDiagnostics().Report(diag::err_module_interface_requires_cpp_modules);
227  return false;
228  }
229 
230  CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
231 
233 }
234 
235 std::unique_ptr<raw_pwrite_stream>
236 GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
237  StringRef InFile) {
238  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
239 }
240 
241 bool GenerateHeaderModuleAction::PrepareToExecuteAction(
242  CompilerInstance &CI) {
243  if (!CI.getLangOpts().Modules) {
244  CI.getDiagnostics().Report(diag::err_header_module_requires_modules);
245  return false;
246  }
247 
248  auto &Inputs = CI.getFrontendOpts().Inputs;
249  if (Inputs.empty())
251 
252  auto Kind = Inputs[0].getKind();
253 
254  // Convert the header file inputs into a single module input buffer.
255  SmallString<256> HeaderContents;
256  ModuleHeaders.reserve(Inputs.size());
257  for (const FrontendInputFile &FIF : Inputs) {
258  // FIXME: We should support re-compiling from an AST file.
259  if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
260  CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
261  << (FIF.isFile() ? FIF.getFile()
262  : FIF.getBuffer()->getBufferIdentifier());
263  return true;
264  }
265 
266  HeaderContents += "#include \"";
267  HeaderContents += FIF.getFile();
268  HeaderContents += "\"\n";
269  ModuleHeaders.push_back(FIF.getFile());
270  }
271  Buffer = llvm::MemoryBuffer::getMemBufferCopy(
272  HeaderContents, Module::getModuleInputBufferName());
273 
274  // Set that buffer up as our "real" input.
275  Inputs.clear();
276  Inputs.push_back(FrontendInputFile(Buffer.get(), Kind, /*IsSystem*/false));
277 
279 }
280 
281 bool GenerateHeaderModuleAction::BeginSourceFileAction(
282  CompilerInstance &CI) {
283  CI.getLangOpts().setCompilingModule(LangOptions::CMK_HeaderModule);
284 
285  // Synthesize a Module object for the given headers.
286  auto &HS = CI.getPreprocessor().getHeaderSearchInfo();
288  for (StringRef Name : ModuleHeaders) {
289  const DirectoryLookup *CurDir = nullptr;
290  Optional<FileEntryRef> FE = HS.LookupFile(
291  Name, SourceLocation(), /*Angled*/ false, nullptr, CurDir, None,
292  nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
293  if (!FE) {
294  CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
295  << Name;
296  continue;
297  }
298  Headers.push_back({Name, &FE->getFileEntry()});
299  }
300  HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
301 
303 }
304 
305 std::unique_ptr<raw_pwrite_stream>
306 GenerateHeaderModuleAction::CreateOutputFile(CompilerInstance &CI,
307  StringRef InFile) {
308  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
309 }
310 
312 }
313 
314 std::unique_ptr<ASTConsumer>
316  return std::make_unique<ASTConsumer>();
317 }
318 
319 std::unique_ptr<ASTConsumer>
321  StringRef InFile) {
322  return std::make_unique<ASTConsumer>();
323 }
324 
325 std::unique_ptr<ASTConsumer>
327  return std::make_unique<ASTConsumer>();
328 }
329 
333  const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
334  std::unique_ptr<ASTReader> Reader(new ASTReader(
335  CI.getPreprocessor(), CI.getModuleCache(), &CI.getASTContext(),
337  Sysroot.empty() ? "" : Sysroot.c_str(),
338  /*DisableValidation*/ false,
339  /*AllowPCHWithCompilerErrors*/ false,
340  /*AllowConfigurationMismatch*/ true,
341  /*ValidateSystemInputs*/ true));
342 
343  Reader->ReadAST(getCurrentFile(),
344  Preamble ? serialization::MK_Preamble
346  SourceLocation(),
348 }
349 
350 namespace {
351 struct TemplightEntry {
352  std::string Name;
353  std::string Kind;
354  std::string Event;
355  std::string DefinitionLocation;
356  std::string PointOfInstantiation;
357 };
358 } // namespace
359 
360 namespace llvm {
361 namespace yaml {
362 template <> struct MappingTraits<TemplightEntry> {
363  static void mapping(IO &io, TemplightEntry &fields) {
364  io.mapRequired("name", fields.Name);
365  io.mapRequired("kind", fields.Kind);
366  io.mapRequired("event", fields.Event);
367  io.mapRequired("orig", fields.DefinitionLocation);
368  io.mapRequired("poi", fields.PointOfInstantiation);
369  }
370 };
371 } // namespace yaml
372 } // namespace llvm
373 
374 namespace {
375 class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
376  using CodeSynthesisContext = Sema::CodeSynthesisContext;
377 
378 public:
379  void initialize(const Sema &) override {}
380 
381  void finalize(const Sema &) override {}
382 
383  void atTemplateBegin(const Sema &TheSema,
384  const CodeSynthesisContext &Inst) override {
385  displayTemplightEntry<true>(llvm::outs(), TheSema, Inst);
386  }
387 
388  void atTemplateEnd(const Sema &TheSema,
389  const CodeSynthesisContext &Inst) override {
390  displayTemplightEntry<false>(llvm::outs(), TheSema, Inst);
391  }
392 
393 private:
394  static std::string toString(CodeSynthesisContext::SynthesisKind Kind) {
395  switch (Kind) {
396  case CodeSynthesisContext::TemplateInstantiation:
397  return "TemplateInstantiation";
398  case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
399  return "DefaultTemplateArgumentInstantiation";
400  case CodeSynthesisContext::DefaultFunctionArgumentInstantiation:
401  return "DefaultFunctionArgumentInstantiation";
402  case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution:
403  return "ExplicitTemplateArgumentSubstitution";
404  case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
405  return "DeducedTemplateArgumentSubstitution";
406  case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
407  return "PriorTemplateArgumentSubstitution";
408  case CodeSynthesisContext::DefaultTemplateArgumentChecking:
409  return "DefaultTemplateArgumentChecking";
410  case CodeSynthesisContext::ExceptionSpecEvaluation:
411  return "ExceptionSpecEvaluation";
412  case CodeSynthesisContext::ExceptionSpecInstantiation:
413  return "ExceptionSpecInstantiation";
414  case CodeSynthesisContext::DeclaringSpecialMember:
415  return "DeclaringSpecialMember";
416  case CodeSynthesisContext::DefiningSynthesizedFunction:
417  return "DefiningSynthesizedFunction";
418  case CodeSynthesisContext::RewritingOperatorAsSpaceship:
419  return "RewritingOperatorAsSpaceship";
420  case CodeSynthesisContext::Memoization:
421  return "Memoization";
422  case CodeSynthesisContext::ConstraintsCheck:
423  return "ConstraintsCheck";
424  case CodeSynthesisContext::ConstraintSubstitution:
425  return "ConstraintSubstitution";
426  }
427  return "";
428  }
429 
430  template <bool BeginInstantiation>
431  static void displayTemplightEntry(llvm::raw_ostream &Out, const Sema &TheSema,
432  const CodeSynthesisContext &Inst) {
433  std::string YAML;
434  {
435  llvm::raw_string_ostream OS(YAML);
436  llvm::yaml::Output YO(OS);
437  TemplightEntry Entry =
438  getTemplightEntry<BeginInstantiation>(TheSema, Inst);
439  llvm::yaml::EmptyContext Context;
440  llvm::yaml::yamlize(YO, Entry, true, Context);
441  }
442  Out << "---" << YAML << "\n";
443  }
444 
445  template <bool BeginInstantiation>
446  static TemplightEntry getTemplightEntry(const Sema &TheSema,
447  const CodeSynthesisContext &Inst) {
448  TemplightEntry Entry;
449  Entry.Kind = toString(Inst.Kind);
450  Entry.Event = BeginInstantiation ? "Begin" : "End";
451  if (auto *NamedTemplate = dyn_cast_or_null<NamedDecl>(Inst.Entity)) {
452  llvm::raw_string_ostream OS(Entry.Name);
453  NamedTemplate->getNameForDiagnostic(OS, TheSema.getLangOpts(), true);
454  const PresumedLoc DefLoc =
455  TheSema.getSourceManager().getPresumedLoc(Inst.Entity->getLocation());
456  if(!DefLoc.isInvalid())
457  Entry.DefinitionLocation = std::string(DefLoc.getFilename()) + ":" +
458  std::to_string(DefLoc.getLine()) + ":" +
459  std::to_string(DefLoc.getColumn());
460  }
461  const PresumedLoc PoiLoc =
462  TheSema.getSourceManager().getPresumedLoc(Inst.PointOfInstantiation);
463  if (!PoiLoc.isInvalid()) {
464  Entry.PointOfInstantiation = std::string(PoiLoc.getFilename()) + ":" +
465  std::to_string(PoiLoc.getLine()) + ":" +
466  std::to_string(PoiLoc.getColumn());
467  }
468  return Entry;
469  }
470 };
471 } // namespace
472 
473 std::unique_ptr<ASTConsumer>
475  return std::make_unique<ASTConsumer>();
476 }
477 
480 
481  // This part is normally done by ASTFrontEndAction, but needs to happen
482  // before Templight observers can be created
483  // FIXME: Move the truncation aspect of this into Sema, we delayed this till
484  // here so the source manager would be initialized.
485  EnsureSemaIsCreated(CI, *this);
486 
487  CI.getSema().TemplateInstCallbacks.push_back(
488  std::make_unique<DefaultTemplateInstCallback>());
490 }
491 
492 namespace {
493  /// AST reader listener that dumps module information for a module
494  /// file.
495  class DumpModuleInfoListener : public ASTReaderListener {
496  llvm::raw_ostream &Out;
497 
498  public:
499  DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { }
500 
501 #define DUMP_BOOLEAN(Value, Text) \
502  Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n"
503 
504  bool ReadFullVersionInformation(StringRef FullVersion) override {
505  Out.indent(2)
506  << "Generated by "
507  << (FullVersion == getClangFullRepositoryVersion()? "this"
508  : "a different")
509  << " Clang: " << FullVersion << "\n";
511  }
512 
513  void ReadModuleName(StringRef ModuleName) override {
514  Out.indent(2) << "Module name: " << ModuleName << "\n";
515  }
516  void ReadModuleMapFile(StringRef ModuleMapPath) override {
517  Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
518  }
519 
520  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
521  bool AllowCompatibleDifferences) override {
522  Out.indent(2) << "Language options:\n";
523 #define LANGOPT(Name, Bits, Default, Description) \
524  DUMP_BOOLEAN(LangOpts.Name, Description);
525 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
526  Out.indent(4) << Description << ": " \
527  << static_cast<unsigned>(LangOpts.get##Name()) << "\n";
528 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
529  Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
530 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
531 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
532 #include "clang/Basic/LangOptions.def"
533 
534  if (!LangOpts.ModuleFeatures.empty()) {
535  Out.indent(4) << "Module features:\n";
536  for (StringRef Feature : LangOpts.ModuleFeatures)
537  Out.indent(6) << Feature << "\n";
538  }
539 
540  return false;
541  }
542 
543  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
544  bool AllowCompatibleDifferences) override {
545  Out.indent(2) << "Target options:\n";
546  Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
547  Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n";
548  Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n";
549 
550  if (!TargetOpts.FeaturesAsWritten.empty()) {
551  Out.indent(4) << "Target features:\n";
552  for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size();
553  I != N; ++I) {
554  Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n";
555  }
556  }
557 
558  return false;
559  }
560 
561  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
562  bool Complain) override {
563  Out.indent(2) << "Diagnostic options:\n";
564 #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
565 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
566  Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
567 #define VALUE_DIAGOPT(Name, Bits, Default) \
568  Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
569 #include "clang/Basic/DiagnosticOptions.def"
570 
571  Out.indent(4) << "Diagnostic flags:\n";
572  for (const std::string &Warning : DiagOpts->Warnings)
573  Out.indent(6) << "-W" << Warning << "\n";
574  for (const std::string &Remark : DiagOpts->Remarks)
575  Out.indent(6) << "-R" << Remark << "\n";
576 
577  return false;
578  }
579 
580  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
581  StringRef SpecificModuleCachePath,
582  bool Complain) override {
583  Out.indent(2) << "Header search options:\n";
584  Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n";
585  Out.indent(4) << "Resource dir [ -resource-dir=]: '" << HSOpts.ResourceDir << "'\n";
586  Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n";
588  "Use builtin include directories [-nobuiltininc]");
590  "Use standard system include directories [-nostdinc]");
592  "Use standard C++ include directories [-nostdinc++]");
593  DUMP_BOOLEAN(HSOpts.UseLibcxx,
594  "Use libc++ (rather than libstdc++) [-stdlib=]");
595  return false;
596  }
597 
598  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
599  bool Complain,
600  std::string &SuggestedPredefines) override {
601  Out.indent(2) << "Preprocessor options:\n";
603  "Uses compiler/target-specific predefines [-undef]");
605  "Uses detailed preprocessing record (for indexing)");
606 
607  if (!PPOpts.Macros.empty()) {
608  Out.indent(4) << "Predefined macros:\n";
609  }
610 
611  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
612  I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end();
613  I != IEnd; ++I) {
614  Out.indent(6);
615  if (I->second)
616  Out << "-U";
617  else
618  Out << "-D";
619  Out << I->first << "\n";
620  }
621  return false;
622  }
623 
624  /// Indicates that a particular module file extension has been read.
625  void readModuleFileExtension(
626  const ModuleFileExtensionMetadata &Metadata) override {
627  Out.indent(2) << "Module file extension '"
628  << Metadata.BlockName << "' " << Metadata.MajorVersion
629  << "." << Metadata.MinorVersion;
630  if (!Metadata.UserInfo.empty()) {
631  Out << ": ";
632  Out.write_escaped(Metadata.UserInfo);
633  }
634 
635  Out << "\n";
636  }
637 
638  /// Tells the \c ASTReaderListener that we want to receive the
639  /// input files of the AST file via \c visitInputFile.
640  bool needsInputFileVisitation() override { return true; }
641 
642  /// Tells the \c ASTReaderListener that we want to receive the
643  /// input files of the AST file via \c visitInputFile.
644  bool needsSystemInputFileVisitation() override { return true; }
645 
646  /// Indicates that the AST file contains particular input file.
647  ///
648  /// \returns true to continue receiving the next input file, false to stop.
649  bool visitInputFile(StringRef Filename, bool isSystem,
650  bool isOverridden, bool isExplicitModule) override {
651 
652  Out.indent(2) << "Input file: " << Filename;
653 
654  if (isSystem || isOverridden || isExplicitModule) {
655  Out << " [";
656  if (isSystem) {
657  Out << "System";
658  if (isOverridden || isExplicitModule)
659  Out << ", ";
660  }
661  if (isOverridden) {
662  Out << "Overridden";
663  if (isExplicitModule)
664  Out << ", ";
665  }
666  if (isExplicitModule)
667  Out << "ExplicitModule";
668 
669  Out << "]";
670  }
671 
672  Out << "\n";
673 
674  return true;
675  }
676 
677  /// Returns true if this \c ASTReaderListener wants to receive the
678  /// imports of the AST file via \c visitImport, false otherwise.
679  bool needsImportVisitation() const override { return true; }
680 
681  /// If needsImportVisitation returns \c true, this is called for each
682  /// AST file imported by this AST file.
683  void visitImport(StringRef ModuleName, StringRef Filename) override {
684  Out.indent(2) << "Imports module '" << ModuleName
685  << "': " << Filename.str() << "\n";
686  }
687 #undef DUMP_BOOLEAN
688  };
689 }
690 
692  // The Object file reader also supports raw ast files and there is no point in
693  // being strict about the module file format in -module-file-info mode.
694  CI.getHeaderSearchOpts().ModuleFormat = "obj";
695  return true;
696 }
697 
699  // Set up the output file.
700  std::unique_ptr<llvm::raw_fd_ostream> OutFile;
701  StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
702  if (!OutputFileName.empty() && OutputFileName != "-") {
703  std::error_code EC;
704  OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
705  llvm::sys::fs::OF_Text));
706  }
707  llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
708 
709  Out << "Information for module file '" << getCurrentFile() << "':\n";
710  auto &FileMgr = getCompilerInstance().getFileManager();
711  auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
712  StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
713  bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
714  Magic[2] == 'C' && Magic[3] == 'H');
715  Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
716 
718  DumpModuleInfoListener Listener(Out);
719  HeaderSearchOptions &HSOpts =
720  PP.getHeaderSearchInfo().getHeaderSearchOpts();
722  getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(),
723  /*FindModuleFileExtensions=*/true, Listener,
725 }
726 
727 //===----------------------------------------------------------------------===//
728 // Preprocessor Actions
729 //===----------------------------------------------------------------------===//
730 
734 
735  // Start lexing the specified input file.
736  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
737  Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts());
738  RawLex.SetKeepWhitespaceMode(true);
739 
740  Token RawTok;
741  RawLex.LexFromRawLexer(RawTok);
742  while (RawTok.isNot(tok::eof)) {
743  PP.DumpToken(RawTok, true);
744  llvm::errs() << "\n";
745  RawLex.LexFromRawLexer(RawTok);
746  }
747 }
748 
751  // Start preprocessing the specified input file.
752  Token Tok;
753  PP.EnterMainSourceFile();
754  do {
755  PP.Lex(Tok);
756  PP.DumpToken(Tok, true);
757  llvm::errs() << "\n";
758  } while (Tok.isNot(tok::eof));
759 }
760 
763 
764  // Ignore unknown pragmas.
765  PP.IgnorePragmas();
766 
767  Token Tok;
768  // Start parsing the specified input file.
769  PP.EnterMainSourceFile();
770  do {
771  PP.Lex(Tok);
772  } while (Tok.isNot(tok::eof));
773 }
774 
777  // Output file may need to be set to 'Binary', to avoid converting Unix style
778  // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
779  //
780  // Look to see what type of line endings the file uses. If there's a
781  // CRLF, then we won't open the file up in binary mode. If there is
782  // just an LF or CR, then we will open the file up in binary mode.
783  // In this fashion, the output format should match the input format, unless
784  // the input format has inconsistent line endings.
785  //
786  // This should be a relatively fast operation since most files won't have
787  // all of their source code on a single line. However, that is still a
788  // concern, so if we scan for too long, we'll just assume the file should
789  // be opened in binary mode.
790  bool BinaryMode = true;
791  bool InvalidFile = false;
792  const SourceManager& SM = CI.getSourceManager();
793  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
794  &InvalidFile);
795  if (!InvalidFile) {
796  const char *cur = Buffer->getBufferStart();
797  const char *end = Buffer->getBufferEnd();
798  const char *next = (cur != end) ? cur + 1 : end;
799 
800  // Limit ourselves to only scanning 256 characters into the source
801  // file. This is mostly a sanity check in case the file has no
802  // newlines whatsoever.
803  if (end - cur > 256) end = cur + 256;
804 
805  while (next < end) {
806  if (*cur == 0x0D) { // CR
807  if (*next == 0x0A) // CRLF
808  BinaryMode = false;
809 
810  break;
811  } else if (*cur == 0x0A) // LF
812  break;
813 
814  ++cur;
815  ++next;
816  }
817  }
818 
819  std::unique_ptr<raw_ostream> OS =
821  if (!OS) return;
822 
823  // If we're preprocessing a module map, start by dumping the contents of the
824  // module itself before switching to the input buffer.
825  auto &Input = getCurrentInput();
826  if (Input.getKind().getFormat() == InputKind::ModuleMap) {
827  if (Input.isFile()) {
828  (*OS) << "# 1 \"";
829  OS->write_escaped(Input.getFile());
830  (*OS) << "\"\n";
831  }
832  getCurrentModule()->print(*OS);
833  (*OS) << "#pragma clang module contents\n";
834  }
835 
838 }
839 
841  switch (getCurrentFileKind().getLanguage()) {
842  case Language::C:
843  case Language::CXX:
844  case Language::ObjC:
845  case Language::ObjCXX:
846  case Language::OpenCL:
847  case Language::CUDA:
848  case Language::HIP:
849  break;
850 
851  case Language::Unknown:
852  case Language::Asm:
853  case Language::LLVM_IR:
855  // We can't do anything with these.
856  return;
857  }
858 
859  // We don't expect to find any #include directives in a preprocessed input.
860  if (getCurrentFileKind().isPreprocessed())
861  return;
862 
864  auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
865  if (Buffer) {
866  unsigned Preamble =
867  Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).Size;
868  llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
869  }
870 }
871 
872 void DumpCompilerOptionsAction::ExecuteAction() {
874  std::unique_ptr<raw_ostream> OSP =
876  if (!OSP)
877  return;
878 
879  raw_ostream &OS = *OSP;
880  const Preprocessor &PP = CI.getPreprocessor();
881  const LangOptions &LangOpts = PP.getLangOpts();
882 
883  // FIXME: Rather than manually format the JSON (which is awkward due to
884  // needing to remove trailing commas), this should make use of a JSON library.
885  // FIXME: Instead of printing enums as an integral value and specifying the
886  // type as a separate field, use introspection to print the enumerator.
887 
888  OS << "{\n";
889  OS << "\n\"features\" : [\n";
890  {
892 #define FEATURE(Name, Predicate) \
893  ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
894  .toVector(Str);
895 #include "clang/Basic/Features.def"
896 #undef FEATURE
897  // Remove the newline and comma from the last entry to ensure this remains
898  // valid JSON.
899  OS << Str.substr(0, Str.size() - 2);
900  }
901  OS << "\n],\n";
902 
903  OS << "\n\"extensions\" : [\n";
904  {
906 #define EXTENSION(Name, Predicate) \
907  ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
908  .toVector(Str);
909 #include "clang/Basic/Features.def"
910 #undef EXTENSION
911  // Remove the newline and comma from the last entry to ensure this remains
912  // valid JSON.
913  OS << Str.substr(0, Str.size() - 2);
914  }
915  OS << "\n]\n";
916 
917  OS << "}";
918 }
919 
923  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
924 
928  FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(),
930  assert(CI.getDiagnostics().hasErrorOccurred() &&
931  "no errors reported for failure");
932 
933  // Preprocess the source when verifying the diagnostics to capture the
934  // 'expected' comments.
935  if (CI.getDiagnosticOpts().VerifyDiagnostics) {
936  // Make sure we don't emit new diagnostics!
939  PP.EnterMainSourceFile();
940  Token Tok;
941  do {
942  PP.Lex(Tok);
943  } while (Tok.isNot(tok::eof));
944  }
945  return;
946  }
947  llvm::outs() << Output;
948 }
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:747
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:7807
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:1290
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:1908
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:7620
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:1530
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:904
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.
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:909
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:1288
HeaderSearchOptions & getHeaderSearchOpts()
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Languages that the frontend can parse and compile.
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:249
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:331
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:243
StringRef Filename
Definition: Format.cpp:1807
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:582
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:1667
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:908
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)
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.
std::vector< FrontendInputFile > Inputs
The input files and their types.
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
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...
Assembly: we accept this only so that we can preprocess it.
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.
void setSuppressAllDiagnostics(bool Val)
Suppress all diagnostics, to silence the front end when we know that we don&#39;t want any more diagnosti...
Definition: Diagnostic.h:635
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()
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:1293
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...
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
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:5096
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.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
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:125
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...