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  if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot))
84  return nullptr;
85 
86  std::string OutputFile;
87  std::unique_ptr<raw_pwrite_stream> OS =
88  CreateOutputFile(CI, InFile, /*ref*/ OutputFile);
89  if (!OS)
90  return nullptr;
91 
93  Sysroot.clear();
94 
95  auto Buffer = std::make_shared<PCHBuffer>();
96  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
97  Consumers.push_back(llvm::make_unique<PCHGenerator>(
98  CI.getPreprocessor(), OutputFile, Sysroot,
100  /*AllowASTWithErrors*/CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
101  /*IncludeTimestamps*/
103  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
104  CI, InFile, OutputFile, std::move(OS), Buffer));
105 
106  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
107 }
108 
110  std::string &Sysroot) {
111  Sysroot = CI.getHeaderSearchOpts().Sysroot;
112  if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
113  CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
114  return false;
115  }
116 
117  return true;
118 }
119 
120 std::unique_ptr<llvm::raw_pwrite_stream>
122  std::string &OutputFile) {
123  // We use createOutputFile here because this is exposed via libclang, and we
124  // must disable the RemoveFileOnSignal behavior.
125  // We use a temporary to avoid race conditions.
126  std::unique_ptr<raw_pwrite_stream> OS =
127  CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
128  /*RemoveFileOnSignal=*/false, InFile,
129  /*Extension=*/"", /*useTemporary=*/true);
130  if (!OS)
131  return nullptr;
132 
133  OutputFile = CI.getFrontendOpts().OutputFile;
134  return OS;
135 }
136 
138  if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
139  return false;
141 }
142 
144  CI.getLangOpts().CompilingPCH = true;
145  return true;
146 }
147 
148 std::unique_ptr<ASTConsumer>
150  StringRef InFile) {
151  std::unique_ptr<raw_pwrite_stream> OS = CreateOutputFile(CI, InFile);
152  if (!OS)
153  return nullptr;
154 
155  std::string OutputFile = CI.getFrontendOpts().OutputFile;
156  std::string Sysroot;
157 
158  auto Buffer = std::make_shared<PCHBuffer>();
159  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
160 
161  Consumers.push_back(llvm::make_unique<PCHGenerator>(
162  CI.getPreprocessor(), OutputFile, Sysroot,
164  /*AllowASTWithErrors=*/false,
165  /*IncludeTimestamps=*/
167  Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
168  CI, InFile, OutputFile, std::move(OS), Buffer));
169  return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
170 }
171 
172 bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
173  CompilerInstance &CI) {
174  if (!CI.getLangOpts().Modules) {
175  CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
176  return false;
177  }
178 
180 }
181 
182 std::unique_ptr<raw_pwrite_stream>
183 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
184  StringRef InFile) {
185  // If no output file was provided, figure out where this module would go
186  // in the module cache.
187  if (CI.getFrontendOpts().OutputFile.empty()) {
188  StringRef ModuleMapFile = CI.getFrontendOpts().OriginalModuleMap;
189  if (ModuleMapFile.empty())
190  ModuleMapFile = InFile;
191 
195  ModuleMapFile);
196  }
197 
198  // We use createOutputFile here because this is exposed via libclang, and we
199  // must disable the RemoveFileOnSignal behavior.
200  // We use a temporary to avoid race conditions.
201  return CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
202  /*RemoveFileOnSignal=*/false, InFile,
203  /*Extension=*/"", /*useTemporary=*/true,
204  /*CreateMissingDirectories=*/true);
205 }
206 
207 bool GenerateModuleInterfaceAction::BeginSourceFileAction(
208  CompilerInstance &CI) {
209  if (!CI.getLangOpts().ModulesTS) {
210  CI.getDiagnostics().Report(diag::err_module_interface_requires_modules_ts);
211  return false;
212  }
213 
214  CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
215 
217 }
218 
219 std::unique_ptr<raw_pwrite_stream>
220 GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
221  StringRef InFile) {
222  return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
223 }
224 
226 }
227 
228 std::unique_ptr<ASTConsumer>
230  return llvm::make_unique<ASTConsumer>();
231 }
232 
233 std::unique_ptr<ASTConsumer>
235  StringRef InFile) {
236  return llvm::make_unique<ASTConsumer>();
237 }
238 
239 std::unique_ptr<ASTConsumer>
241  return llvm::make_unique<ASTConsumer>();
242 }
243 
246  bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
247  const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
248  std::unique_ptr<ASTReader> Reader(new ASTReader(
251  Sysroot.empty() ? "" : Sysroot.c_str(),
252  /*DisableValidation*/ false,
253  /*AllowPCHWithCompilerErrors*/ false,
254  /*AllowConfigurationMismatch*/ true,
255  /*ValidateSystemInputs*/ true));
256 
257  Reader->ReadAST(getCurrentFile(),
258  Preamble ? serialization::MK_Preamble
260  SourceLocation(),
262 }
263 
264 namespace {
265  /// \brief AST reader listener that dumps module information for a module
266  /// file.
267  class DumpModuleInfoListener : public ASTReaderListener {
268  llvm::raw_ostream &Out;
269 
270  public:
271  DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { }
272 
273 #define DUMP_BOOLEAN(Value, Text) \
274  Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n"
275 
276  bool ReadFullVersionInformation(StringRef FullVersion) override {
277  Out.indent(2)
278  << "Generated by "
279  << (FullVersion == getClangFullRepositoryVersion()? "this"
280  : "a different")
281  << " Clang: " << FullVersion << "\n";
283  }
284 
285  void ReadModuleName(StringRef ModuleName) override {
286  Out.indent(2) << "Module name: " << ModuleName << "\n";
287  }
288  void ReadModuleMapFile(StringRef ModuleMapPath) override {
289  Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
290  }
291 
292  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
293  bool AllowCompatibleDifferences) override {
294  Out.indent(2) << "Language options:\n";
295 #define LANGOPT(Name, Bits, Default, Description) \
296  DUMP_BOOLEAN(LangOpts.Name, Description);
297 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
298  Out.indent(4) << Description << ": " \
299  << static_cast<unsigned>(LangOpts.get##Name()) << "\n";
300 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
301  Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
302 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
303 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
304 #include "clang/Basic/LangOptions.def"
305 
306  if (!LangOpts.ModuleFeatures.empty()) {
307  Out.indent(4) << "Module features:\n";
308  for (StringRef Feature : LangOpts.ModuleFeatures)
309  Out.indent(6) << Feature << "\n";
310  }
311 
312  return false;
313  }
314 
315  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
316  bool AllowCompatibleDifferences) override {
317  Out.indent(2) << "Target options:\n";
318  Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
319  Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n";
320  Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n";
321 
322  if (!TargetOpts.FeaturesAsWritten.empty()) {
323  Out.indent(4) << "Target features:\n";
324  for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size();
325  I != N; ++I) {
326  Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n";
327  }
328  }
329 
330  return false;
331  }
332 
333  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
334  bool Complain) override {
335  Out.indent(2) << "Diagnostic options:\n";
336 #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
337 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
338  Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
339 #define VALUE_DIAGOPT(Name, Bits, Default) \
340  Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
341 #include "clang/Basic/DiagnosticOptions.def"
342 
343  Out.indent(4) << "Diagnostic flags:\n";
344  for (const std::string &Warning : DiagOpts->Warnings)
345  Out.indent(6) << "-W" << Warning << "\n";
346  for (const std::string &Remark : DiagOpts->Remarks)
347  Out.indent(6) << "-R" << Remark << "\n";
348 
349  return false;
350  }
351 
352  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
353  StringRef SpecificModuleCachePath,
354  bool Complain) override {
355  Out.indent(2) << "Header search options:\n";
356  Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n";
357  Out.indent(4) << "Resource dir [ -resource-dir=]: '" << HSOpts.ResourceDir << "'\n";
358  Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n";
360  "Use builtin include directories [-nobuiltininc]");
362  "Use standard system include directories [-nostdinc]");
364  "Use standard C++ include directories [-nostdinc++]");
365  DUMP_BOOLEAN(HSOpts.UseLibcxx,
366  "Use libc++ (rather than libstdc++) [-stdlib=]");
367  return false;
368  }
369 
370  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
371  bool Complain,
372  std::string &SuggestedPredefines) override {
373  Out.indent(2) << "Preprocessor options:\n";
375  "Uses compiler/target-specific predefines [-undef]");
377  "Uses detailed preprocessing record (for indexing)");
378 
379  if (!PPOpts.Macros.empty()) {
380  Out.indent(4) << "Predefined macros:\n";
381  }
382 
383  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
384  I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end();
385  I != IEnd; ++I) {
386  Out.indent(6);
387  if (I->second)
388  Out << "-U";
389  else
390  Out << "-D";
391  Out << I->first << "\n";
392  }
393  return false;
394  }
395 
396  /// Indicates that a particular module file extension has been read.
397  void readModuleFileExtension(
398  const ModuleFileExtensionMetadata &Metadata) override {
399  Out.indent(2) << "Module file extension '"
400  << Metadata.BlockName << "' " << Metadata.MajorVersion
401  << "." << Metadata.MinorVersion;
402  if (!Metadata.UserInfo.empty()) {
403  Out << ": ";
404  Out.write_escaped(Metadata.UserInfo);
405  }
406 
407  Out << "\n";
408  }
409 #undef DUMP_BOOLEAN
410  };
411 }
412 
414  // The Object file reader also supports raw ast files and there is no point in
415  // being strict about the module file format in -module-file-info mode.
416  CI.getHeaderSearchOpts().ModuleFormat = "obj";
417  return true;
418 }
419 
421  // Set up the output file.
422  std::unique_ptr<llvm::raw_fd_ostream> OutFile;
423  StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
424  if (!OutputFileName.empty() && OutputFileName != "-") {
425  std::error_code EC;
426  OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
427  llvm::sys::fs::F_Text));
428  }
429  llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
430 
431  Out << "Information for module file '" << getCurrentFile() << "':\n";
432  auto &FileMgr = getCompilerInstance().getFileManager();
433  auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
434  StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
435  bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
436  Magic[2] == 'C' && Magic[3] == 'H');
437  Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
438 
440  DumpModuleInfoListener Listener(Out);
441  HeaderSearchOptions &HSOpts =
442  PP.getHeaderSearchInfo().getHeaderSearchOpts();
444  getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(),
445  /*FindModuleFileExtensions=*/true, Listener,
447 }
448 
449 //===----------------------------------------------------------------------===//
450 // Preprocessor Actions
451 //===----------------------------------------------------------------------===//
452 
456 
457  // Start lexing the specified input file.
458  const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
459  Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts());
460  RawLex.SetKeepWhitespaceMode(true);
461 
462  Token RawTok;
463  RawLex.LexFromRawLexer(RawTok);
464  while (RawTok.isNot(tok::eof)) {
465  PP.DumpToken(RawTok, true);
466  llvm::errs() << "\n";
467  RawLex.LexFromRawLexer(RawTok);
468  }
469 }
470 
473  // Start preprocessing the specified input file.
474  Token Tok;
475  PP.EnterMainSourceFile();
476  do {
477  PP.Lex(Tok);
478  PP.DumpToken(Tok, true);
479  llvm::errs() << "\n";
480  } while (Tok.isNot(tok::eof));
481 }
482 
485  std::unique_ptr<raw_pwrite_stream> OS =
487  if (!OS)
488  return;
489 
490  CacheTokens(CI.getPreprocessor(), OS.get());
491 }
492 
495 
496  // Ignore unknown pragmas.
497  PP.IgnorePragmas();
498 
499  Token Tok;
500  // Start parsing the specified input file.
501  PP.EnterMainSourceFile();
502  do {
503  PP.Lex(Tok);
504  } while (Tok.isNot(tok::eof));
505 }
506 
509  // Output file may need to be set to 'Binary', to avoid converting Unix style
510  // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
511  //
512  // Look to see what type of line endings the file uses. If there's a
513  // CRLF, then we won't open the file up in binary mode. If there is
514  // just an LF or CR, then we will open the file up in binary mode.
515  // In this fashion, the output format should match the input format, unless
516  // the input format has inconsistent line endings.
517  //
518  // This should be a relatively fast operation since most files won't have
519  // all of their source code on a single line. However, that is still a
520  // concern, so if we scan for too long, we'll just assume the file should
521  // be opened in binary mode.
522  bool BinaryMode = true;
523  bool InvalidFile = false;
524  const SourceManager& SM = CI.getSourceManager();
525  const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
526  &InvalidFile);
527  if (!InvalidFile) {
528  const char *cur = Buffer->getBufferStart();
529  const char *end = Buffer->getBufferEnd();
530  const char *next = (cur != end) ? cur + 1 : end;
531 
532  // Limit ourselves to only scanning 256 characters into the source
533  // file. This is mostly a sanity check in case the file has no
534  // newlines whatsoever.
535  if (end - cur > 256) end = cur + 256;
536 
537  while (next < end) {
538  if (*cur == 0x0D) { // CR
539  if (*next == 0x0A) // CRLF
540  BinaryMode = false;
541 
542  break;
543  } else if (*cur == 0x0A) // LF
544  break;
545 
546  ++cur;
547  ++next;
548  }
549  }
550 
551  std::unique_ptr<raw_ostream> OS =
552  CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
553  if (!OS) return;
554 
555  // If we're preprocessing a module map, start by dumping the contents of the
556  // module itself before switching to the input buffer.
557  auto &Input = getCurrentInput();
558  if (Input.getKind().getFormat() == InputKind::ModuleMap) {
559  if (Input.isFile()) {
560  (*OS) << "# 1 \"";
561  OS->write_escaped(Input.getFile());
562  (*OS) << "\"\n";
563  }
564  // FIXME: Include additional information here so that we don't need the
565  // original source files to exist on disk.
566  getCurrentModule()->print(*OS);
567  (*OS) << "#pragma clang module contents\n";
568  }
569 
572 }
573 
575  switch (getCurrentFileKind().getLanguage()) {
576  case InputKind::C:
577  case InputKind::CXX:
578  case InputKind::ObjC:
579  case InputKind::ObjCXX:
580  case InputKind::OpenCL:
581  case InputKind::CUDA:
582  break;
583 
584  case InputKind::Unknown:
585  case InputKind::Asm:
586  case InputKind::LLVM_IR:
588  // We can't do anything with these.
589  return;
590  }
591 
592  // We don't expect to find any #include directives in a preprocessed input.
593  if (getCurrentFileKind().isPreprocessed())
594  return;
595 
597  auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
598  if (Buffer) {
599  unsigned Preamble =
600  Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).Size;
601  llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
602  }
603 }
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:77
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:1207
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:1840
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
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1503
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:815
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Languages that the frontend can parse and compile.
static bool ComputeASTConsumerArguments(CompilerInstance &CI, std::string &Sysroot)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
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:821
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:137
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:148
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:131
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.
static PreambleBounds ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines=0)
Compute the preamble of the given file.
Definition: Lexer.cpp:574
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:360
Defines the clang::Preprocessor interface.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
InputKind getCurrentFileKind() const
const SourceManager & SM
Definition: Format.cpp:1337
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:819
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:137
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
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:358
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:129
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:4687
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:213
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:127
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...