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