clang  6.0.0svn
FrontendActions.cpp
Go to the documentation of this file.
1 //===--- FrontendActions.cpp ----------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "clang/AST/ASTConsumer.h"
17 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/HeaderSearch.h"
19 #include "clang/Lex/Preprocessor.h"
23 #include "llvm/Support/FileSystem.h"
24 #include "llvm/Support/MemoryBuffer.h"
25 #include "llvm/Support/Path.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include <memory>
28 #include <system_error>
29 
30 using namespace clang;
31 
32 //===----------------------------------------------------------------------===//
33 // Custom Actions
34 //===----------------------------------------------------------------------===//
35 
36 std::unique_ptr<ASTConsumer>
37 InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
38  return llvm::make_unique<ASTConsumer>();
39 }
40 
41 void InitOnlyAction::ExecuteAction() {
42 }
43 
44 //===----------------------------------------------------------------------===//
45 // AST Consumer Actions
46 //===----------------------------------------------------------------------===//
47 
48 std::unique_ptr<ASTConsumer>
50  if (std::unique_ptr<raw_ostream> OS =
51  CI.createDefaultOutputFile(false, InFile))
52  return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter);
53  return nullptr;
54 }
55 
56 std::unique_ptr<ASTConsumer>
62 }
63 
64 std::unique_ptr<ASTConsumer>
66  return CreateASTDeclNodeLister();
67 }
68 
69 std::unique_ptr<ASTConsumer>
71  return CreateASTViewer();
72 }
73 
74 std::unique_ptr<ASTConsumer>
76  StringRef InFile) {
77  return CreateDeclContextPrinter();
78 }
79 
80 std::unique_ptr<ASTConsumer>
82  std::string Sysroot;
83  std::string OutputFile;
84  std::unique_ptr<raw_pwrite_stream> OS =
85  ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile);
86  if (!OS)
87  return nullptr;
88 
90  Sysroot.clear();
91 
92  auto Buffer = std::make_shared<PCHBuffer>();
93  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
94  Consumers.push_back(llvm::make_unique<PCHGenerator>(
95  CI.getPreprocessor(), OutputFile, Sysroot,
97  /*AllowASTWithErrors*/CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
98  /*IncludeTimestamps*/
100  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
101  CI, InFile, OutputFile, std::move(OS), Buffer));
102 
103  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
104 }
105 
106 std::unique_ptr<raw_pwrite_stream>
108  StringRef InFile,
109  std::string &Sysroot,
110  std::string &OutputFile) {
111  Sysroot = CI.getHeaderSearchOpts().Sysroot;
112  if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
113  CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
114  return nullptr;
115  }
116 
117  // We use createOutputFile here because this is exposed via libclang, and we
118  // must disable the RemoveFileOnSignal behavior.
119  // We use a temporary to avoid race conditions.
120  std::unique_ptr<raw_pwrite_stream> OS =
121  CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
122  /*RemoveFileOnSignal=*/false, InFile,
123  /*Extension=*/"", /*useTemporary=*/true);
124  if (!OS)
125  return nullptr;
126 
127  OutputFile = CI.getFrontendOpts().OutputFile;
128  return OS;
129 }
130 
132  if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
133  return false;
135 }
136 
138  CI.getLangOpts().CompilingPCH = true;
139  return true;
140 }
141 
142 std::unique_ptr<ASTConsumer>
144  StringRef InFile) {
145  std::unique_ptr<raw_pwrite_stream> OS = CreateOutputFile(CI, InFile);
146  if (!OS)
147  return nullptr;
148 
149  std::string OutputFile = CI.getFrontendOpts().OutputFile;
150  std::string Sysroot;
151 
152  auto Buffer = std::make_shared<PCHBuffer>();
153  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
154 
155  Consumers.push_back(llvm::make_unique<PCHGenerator>(
156  CI.getPreprocessor(), OutputFile, Sysroot,
158  /*AllowASTWithErrors=*/false,
159  /*IncludeTimestamps=*/
161  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
162  CI, InFile, OutputFile, std::move(OS), Buffer));
163  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
164 }
165 
166 bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
167  CompilerInstance &CI) {
168  if (!CI.getLangOpts().Modules) {
169  CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
170  return false;
171  }
172 
174 }
175 
176 std::unique_ptr<raw_pwrite_stream>
177 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
178  StringRef InFile) {
179  // If no output file was provided, figure out where this module would go
180  // in the module cache.
181  if (CI.getFrontendOpts().OutputFile.empty()) {
182  StringRef ModuleMapFile = CI.getFrontendOpts().OriginalModuleMap;
183  if (ModuleMapFile.empty())
184  ModuleMapFile = InFile;
185 
189  ModuleMapFile);
190  }
191 
192  // We use createOutputFile here because this is exposed via libclang, and we
193  // must disable the RemoveFileOnSignal behavior.
194  // We use a temporary to avoid race conditions.
195  return CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
196  /*RemoveFileOnSignal=*/false, InFile,
197  /*Extension=*/"", /*useTemporary=*/true,
198  /*CreateMissingDirectories=*/true);
199 }
200 
201 bool GenerateModuleInterfaceAction::BeginSourceFileAction(
202  CompilerInstance &CI) {
203  if (!CI.getLangOpts().ModulesTS) {
204  CI.getDiagnostics().Report(diag::err_module_interface_requires_modules_ts);
205  return false;
206  }
207 
208  CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
209 
211 }
212 
213 std::unique_ptr<raw_pwrite_stream>
214 GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
215  StringRef InFile) {
216  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
217 }
218 
220 }
221 
222 std::unique_ptr<ASTConsumer>
224  return llvm::make_unique<ASTConsumer>();
225 }
226 
227 std::unique_ptr<ASTConsumer>
229  StringRef InFile) {
230  return llvm::make_unique<ASTConsumer>();
231 }
232 
233 std::unique_ptr<ASTConsumer>
235  return llvm::make_unique<ASTConsumer>();
236 }
237 
240  bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
241  const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
242  std::unique_ptr<ASTReader> Reader(new ASTReader(
245  Sysroot.empty() ? "" : Sysroot.c_str(),
246  /*DisableValidation*/ false,
247  /*AllowPCHWithCompilerErrors*/ false,
248  /*AllowConfigurationMismatch*/ true,
249  /*ValidateSystemInputs*/ true));
250 
251  Reader->ReadAST(getCurrentFile(),
252  Preamble ? serialization::MK_Preamble
254  SourceLocation(),
256 }
257 
258 namespace {
259  /// \brief AST reader listener that dumps module information for a module
260  /// file.
261  class DumpModuleInfoListener : public ASTReaderListener {
262  llvm::raw_ostream &Out;
263 
264  public:
265  DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { }
266 
267 #define DUMP_BOOLEAN(Value, Text) \
268  Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n"
269 
270  bool ReadFullVersionInformation(StringRef FullVersion) override {
271  Out.indent(2)
272  << "Generated by "
273  << (FullVersion == getClangFullRepositoryVersion()? "this"
274  : "a different")
275  << " Clang: " << FullVersion << "\n";
277  }
278 
279  void ReadModuleName(StringRef ModuleName) override {
280  Out.indent(2) << "Module name: " << ModuleName << "\n";
281  }
282  void ReadModuleMapFile(StringRef ModuleMapPath) override {
283  Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
284  }
285 
286  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
287  bool AllowCompatibleDifferences) override {
288  Out.indent(2) << "Language options:\n";
289 #define LANGOPT(Name, Bits, Default, Description) \
290  DUMP_BOOLEAN(LangOpts.Name, Description);
291 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
292  Out.indent(4) << Description << ": " \
293  << static_cast<unsigned>(LangOpts.get##Name()) << "\n";
294 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
295  Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
296 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
297 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
298 #include "clang/Basic/LangOptions.def"
299 
300  if (!LangOpts.ModuleFeatures.empty()) {
301  Out.indent(4) << "Module features:\n";
302  for (StringRef Feature : LangOpts.ModuleFeatures)
303  Out.indent(6) << Feature << "\n";
304  }
305 
306  return false;
307  }
308 
309  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
310  bool AllowCompatibleDifferences) override {
311  Out.indent(2) << "Target options:\n";
312  Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
313  Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n";
314  Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n";
315 
316  if (!TargetOpts.FeaturesAsWritten.empty()) {
317  Out.indent(4) << "Target features:\n";
318  for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size();
319  I != N; ++I) {
320  Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n";
321  }
322  }
323 
324  return false;
325  }
326 
327  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
328  bool Complain) override {
329  Out.indent(2) << "Diagnostic options:\n";
330 #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
331 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
332  Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
333 #define VALUE_DIAGOPT(Name, Bits, Default) \
334  Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
335 #include "clang/Basic/DiagnosticOptions.def"
336 
337  Out.indent(4) << "Diagnostic flags:\n";
338  for (const std::string &Warning : DiagOpts->Warnings)
339  Out.indent(6) << "-W" << Warning << "\n";
340  for (const std::string &Remark : DiagOpts->Remarks)
341  Out.indent(6) << "-R" << Remark << "\n";
342 
343  return false;
344  }
345 
346  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
347  StringRef SpecificModuleCachePath,
348  bool Complain) override {
349  Out.indent(2) << "Header search options:\n";
350  Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n";
351  Out.indent(4) << "Resource dir [ -resource-dir=]: '" << HSOpts.ResourceDir << "'\n";
352  Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n";
354  "Use builtin include directories [-nobuiltininc]");
356  "Use standard system include directories [-nostdinc]");
358  "Use standard C++ include directories [-nostdinc++]");
359  DUMP_BOOLEAN(HSOpts.UseLibcxx,
360  "Use libc++ (rather than libstdc++) [-stdlib=]");
361  return false;
362  }
363 
364  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
365  bool Complain,
366  std::string &SuggestedPredefines) override {
367  Out.indent(2) << "Preprocessor options:\n";
369  "Uses compiler/target-specific predefines [-undef]");
371  "Uses detailed preprocessing record (for indexing)");
372 
373  if (!PPOpts.Macros.empty()) {
374  Out.indent(4) << "Predefined macros:\n";
375  }
376 
377  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
378  I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end();
379  I != IEnd; ++I) {
380  Out.indent(6);
381  if (I->second)
382  Out << "-U";
383  else
384  Out << "-D";
385  Out << I->first << "\n";
386  }
387  return false;
388  }
389 
390  /// Indicates that a particular module file extension has been read.
391  void readModuleFileExtension(
392  const ModuleFileExtensionMetadata &Metadata) override {
393  Out.indent(2) << "Module file extension '"
394  << Metadata.BlockName << "' " << Metadata.MajorVersion
395  << "." << Metadata.MinorVersion;
396  if (!Metadata.UserInfo.empty()) {
397  Out << ": ";
398  Out.write_escaped(Metadata.UserInfo);
399  }
400 
401  Out << "\n";
402  }
403 #undef DUMP_BOOLEAN
404  };
405 }
406 
408  // The Object file reader also supports raw ast files and there is no point in
409  // being strict about the module file format in -module-file-info mode.
410  CI.getHeaderSearchOpts().ModuleFormat = "obj";
411  return true;
412 }
413 
415  // Set up the output file.
416  std::unique_ptr<llvm::raw_fd_ostream> OutFile;
417  StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
418  if (!OutputFileName.empty() && OutputFileName != "-") {
419  std::error_code EC;
420  OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
421  llvm::sys::fs::F_Text));
422  }
423  llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
424 
425  Out << "Information for module file '" << getCurrentFile() << "':\n";
426  auto &FileMgr = getCompilerInstance().getFileManager();
427  auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
428  StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
429  bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
430  Magic[2] == 'C' && Magic[3] == 'H');
431  Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
432 
434  DumpModuleInfoListener Listener(Out);
435  HeaderSearchOptions &HSOpts =
436  PP.getHeaderSearchInfo().getHeaderSearchOpts();
438  getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(),
439  /*FindModuleFileExtensions=*/true, Listener,
441 }
442 
443 //===----------------------------------------------------------------------===//
444 // Preprocessor Actions
445 //===----------------------------------------------------------------------===//
446 
450 
451  // Start lexing the specified input file.
452  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
453  Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts());
454  RawLex.SetKeepWhitespaceMode(true);
455 
456  Token RawTok;
457  RawLex.LexFromRawLexer(RawTok);
458  while (RawTok.isNot(tok::eof)) {
459  PP.DumpToken(RawTok, true);
460  llvm::errs() << "\n";
461  RawLex.LexFromRawLexer(RawTok);
462  }
463 }
464 
467  // Start preprocessing the specified input file.
468  Token Tok;
469  PP.EnterMainSourceFile();
470  do {
471  PP.Lex(Tok);
472  PP.DumpToken(Tok, true);
473  llvm::errs() << "\n";
474  } while (Tok.isNot(tok::eof));
475 }
476 
479  std::unique_ptr<raw_pwrite_stream> OS =
481  if (!OS)
482  return;
483 
484  CacheTokens(CI.getPreprocessor(), OS.get());
485 }
486 
489 
490  // Ignore unknown pragmas.
491  PP.IgnorePragmas();
492 
493  Token Tok;
494  // Start parsing the specified input file.
495  PP.EnterMainSourceFile();
496  do {
497  PP.Lex(Tok);
498  } while (Tok.isNot(tok::eof));
499 }
500 
503  // Output file may need to be set to 'Binary', to avoid converting Unix style
504  // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
505  //
506  // Look to see what type of line endings the file uses. If there's a
507  // CRLF, then we won't open the file up in binary mode. If there is
508  // just an LF or CR, then we will open the file up in binary mode.
509  // In this fashion, the output format should match the input format, unless
510  // the input format has inconsistent line endings.
511  //
512  // This should be a relatively fast operation since most files won't have
513  // all of their source code on a single line. However, that is still a
514  // concern, so if we scan for too long, we'll just assume the file should
515  // be opened in binary mode.
516  bool BinaryMode = true;
517  bool InvalidFile = false;
518  const SourceManager& SM = CI.getSourceManager();
519  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
520  &InvalidFile);
521  if (!InvalidFile) {
522  const char *cur = Buffer->getBufferStart();
523  const char *end = Buffer->getBufferEnd();
524  const char *next = (cur != end) ? cur + 1 : end;
525 
526  // Limit ourselves to only scanning 256 characters into the source
527  // file. This is mostly a sanity check in case the file has no
528  // newlines whatsoever.
529  if (end - cur > 256) end = cur + 256;
530 
531  while (next < end) {
532  if (*cur == 0x0D) { // CR
533  if (*next == 0x0A) // CRLF
534  BinaryMode = false;
535 
536  break;
537  } else if (*cur == 0x0A) // LF
538  break;
539 
540  ++cur;
541  ++next;
542  }
543  }
544 
545  std::unique_ptr<raw_ostream> OS =
546  CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
547  if (!OS) return;
548 
549  // If we're preprocessing a module map, start by dumping the contents of the
550  // module itself before switching to the input buffer.
551  auto &Input = getCurrentInput();
552  if (Input.getKind().getFormat() == InputKind::ModuleMap) {
553  if (Input.isFile()) {
554  (*OS) << "# 1 \"";
555  OS->write_escaped(Input.getFile());
556  (*OS) << "\"\n";
557  }
558  // FIXME: Include additional information here so that we don't need the
559  // original source files to exist on disk.
560  getCurrentModule()->print(*OS);
561  (*OS) << "#pragma clang module contents\n";
562  }
563 
566 }
567 
569  switch (getCurrentFileKind().getLanguage()) {
570  case InputKind::C:
571  case InputKind::CXX:
572  case InputKind::ObjC:
573  case InputKind::ObjCXX:
574  case InputKind::OpenCL:
575  case InputKind::CUDA:
576  break;
577 
578  case InputKind::Unknown:
579  case InputKind::Asm:
580  case InputKind::LLVM_IR:
582  // We can't do anything with these.
583  return;
584  }
585 
586  // We don't expect to find any #include directives in a preprocessed input.
587  if (getCurrentFileKind().isPreprocessed())
588  return;
589 
591  auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
592  if (Buffer) {
593  unsigned Preamble =
594  Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).Size;
595  llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
596  }
597 }
std::string OutputFile
The output file, if any.
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...
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:63
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
Defines the clang::FileManager interface and associated types.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1205
static std::unique_ptr< raw_pwrite_stream > ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
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:65
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:1837
Options for controlling the target.
Definition: TargetOptions.h:26
std::unique_ptr< ASTConsumer > CreateASTDumper(StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups)
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
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:35
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1458
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:728
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Languages that the frontend can parse and compile.
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:734
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
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.
void CacheTokens(Preprocessor &PP, raw_pwrite_stream *OS)
Cache tokens for use with PCH. Note that this requires a seekable stream.
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
#define DUMP_BOOLEAN(Value, Text)
HeaderSearchOptions & getHeaderSearchOpts()
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
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:136
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:137
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:130
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.
unsigned UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
static PreambleBounds ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines=0)
Compute the preamble of the given file.
Definition: Lexer.cpp:555
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:349
Defines the clang::Preprocessor interface.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
InputKind getCurrentFileKind() const
const SourceManager & SM
Definition: Format.cpp:1308
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...
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:732
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
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:51
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.
Assembly: we accept this only so that we can preprocess it.
File is a PCH file treated as such.
Definition: Module.h:50
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
unsigned IncludeTimestamps
Whether timestamps should be written to the produced PCH file.
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
void Lex(Token &Result)
Lex the next token for this preprocessor.
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:113
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.
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
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
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:328
FileID getMainFileID() const
Returns the FileID of the main source file.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
virtual std::unique_ptr< ASTConsumer > CreatePCHContainerGenerator(CompilerInstance &CI, const std::string &MainFileName, const std::string &OutputFileName, std::unique_ptr< llvm::raw_pwrite_stream > OS, std::shared_ptr< PCHBuffer > Buffer) const =0
Return an ASTConsumer that can be chained with a PCHGenerator that produces a wrapper file format con...
SourceManager & getSourceManager() const
Return the current source manager.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::string BlockName
The name used to identify this particular extension block within the resulting module file...
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:105
std::unique_ptr< ASTConsumer > CreateDeclContextPrinter()
std::vector< std::shared_ptr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
Create the default output file (from the invocation&#39;s options) and add it to the list of tracked outp...
std::unique_ptr< ASTConsumer > CreateASTViewer()
Metadata for a module file extension.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
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.
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
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.
const StringRef getCurrentFile() const
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
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:4632
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.
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:189
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:29
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:98
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...