clang  5.0.0
CompilerInstance.h
Go to the documentation of this file.
1 //===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
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 
10 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
11 #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
12 
13 #include "clang/AST/ASTConsumer.h"
14 #include "clang/Basic/Diagnostic.h"
18 #include "clang/Frontend/Utils.h"
20 #include "clang/Lex/ModuleLoader.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include "llvm/ADT/StringRef.h"
25 #include <cassert>
26 #include <list>
27 #include <memory>
28 #include <string>
29 #include <utility>
30 
31 namespace llvm {
32 class raw_fd_ostream;
33 class Timer;
34 class TimerGroup;
35 }
36 
37 namespace clang {
38 class ASTContext;
39 class ASTReader;
40 class CodeCompleteConsumer;
41 class DiagnosticsEngine;
42 class DiagnosticConsumer;
43 class ExternalASTSource;
44 class FileEntry;
45 class FileManager;
46 class FrontendAction;
47 class MemoryBufferCache;
48 class Module;
49 class Preprocessor;
50 class Sema;
51 class SourceManager;
52 class TargetInfo;
53 
54 /// CompilerInstance - Helper class for managing a single instance of the Clang
55 /// compiler.
56 ///
57 /// The CompilerInstance serves two purposes:
58 /// (1) It manages the various objects which are necessary to run the compiler,
59 /// for example the preprocessor, the target information, and the AST
60 /// context.
61 /// (2) It provides utility routines for constructing and manipulating the
62 /// common Clang objects.
63 ///
64 /// The compiler instance generally owns the instance of all the objects that it
65 /// manages. However, clients can still share objects by manually setting the
66 /// object and retaking ownership prior to destroying the CompilerInstance.
67 ///
68 /// The compiler instance is intended to simplify clients, but not to lock them
69 /// in to the compiler instance for everything. When possible, utility functions
70 /// come in two forms; a short form that reuses the CompilerInstance objects,
71 /// and a long form that takes explicit instances of any required objects.
73  /// The options used in this compiler instance.
74  std::shared_ptr<CompilerInvocation> Invocation;
75 
76  /// The diagnostics engine instance.
78 
79  /// The target being compiled for.
81 
82  /// Auxiliary Target info.
84 
85  /// The virtual file system.
86  IntrusiveRefCntPtr<vfs::FileSystem> VirtualFileSystem;
87 
88  /// The file manager.
90 
91  /// The source manager.
93 
94  /// The cache of PCM files.
96 
97  /// The preprocessor.
98  std::shared_ptr<Preprocessor> PP;
99 
100  /// The AST context.
102 
103  /// An optional sema source that will be attached to sema.
105 
106  /// The AST consumer.
107  std::unique_ptr<ASTConsumer> Consumer;
108 
109  /// The code completion consumer.
110  std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
111 
112  /// \brief The semantic analysis object.
113  std::unique_ptr<Sema> TheSema;
114 
115  /// \brief The frontend timer group.
116  std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
117 
118  /// \brief The frontend timer.
119  std::unique_ptr<llvm::Timer> FrontendTimer;
120 
121  /// \brief The ASTReader, if one exists.
122  IntrusiveRefCntPtr<ASTReader> ModuleManager;
123 
124  /// \brief The module dependency collector for crashdumps
125  std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
126 
127  /// \brief The module provider.
128  std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
129 
130  /// \brief The dependency file generator.
131  std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
132 
133  std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
134 
135  /// \brief The set of top-level modules that has already been loaded,
136  /// along with the module map
137  llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
138 
139  /// \brief The set of top-level modules that has already been built on the
140  /// fly as part of this overall compilation action.
141  std::map<std::string, std::string> BuiltModules;
142 
143  /// Should we delete the BuiltModules when we're done?
144  bool DeleteBuiltModules = true;
145 
146  /// \brief The location of the module-import keyword for the last module
147  /// import.
148  SourceLocation LastModuleImportLoc;
149 
150  /// \brief The result of the last module import.
151  ///
152  ModuleLoadResult LastModuleImportResult;
153 
154  /// \brief Whether we should (re)build the global module index once we
155  /// have finished with this translation unit.
156  bool BuildGlobalModuleIndex = false;
157 
158  /// \brief We have a full global module index, with all modules.
159  bool HaveFullGlobalModuleIndex = false;
160 
161  /// \brief One or more modules failed to build.
162  bool ModuleBuildFailed = false;
163 
164  /// \brief Holds information about the output file.
165  ///
166  /// If TempFilename is not empty we must rename it to Filename at the end.
167  /// TempFilename may be empty and Filename non-empty if creating the temporary
168  /// failed.
169  struct OutputFile {
170  std::string Filename;
171  std::string TempFilename;
172 
173  OutputFile(std::string filename, std::string tempFilename)
174  : Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
175  }
176  };
177 
178  /// If the output doesn't support seeking (terminal, pipe). we switch
179  /// the stream to a buffer_ostream. These are the buffer and the original
180  /// stream.
181  std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
182 
183  /// The list of active output files.
184  std::list<OutputFile> OutputFiles;
185 
186  CompilerInstance(const CompilerInstance &) = delete;
187  void operator=(const CompilerInstance &) = delete;
188 public:
189  explicit CompilerInstance(
190  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
191  std::make_shared<PCHContainerOperations>(),
192  MemoryBufferCache *SharedPCMCache = nullptr);
193  ~CompilerInstance() override;
194 
195  /// @name High-Level Operations
196  /// {
197 
198  /// ExecuteAction - Execute the provided action against the compiler's
199  /// CompilerInvocation object.
200  ///
201  /// This function makes the following assumptions:
202  ///
203  /// - The invocation options should be initialized. This function does not
204  /// handle the '-help' or '-version' options, clients should handle those
205  /// directly.
206  ///
207  /// - The diagnostics engine should have already been created by the client.
208  ///
209  /// - No other CompilerInstance state should have been initialized (this is
210  /// an unchecked error).
211  ///
212  /// - Clients should have initialized any LLVM target features that may be
213  /// required.
214  ///
215  /// - Clients should eventually call llvm_shutdown() upon the completion of
216  /// this routine to ensure that any managed objects are properly destroyed.
217  ///
218  /// Note that this routine may write output to 'stderr'.
219  ///
220  /// \param Act - The action to execute.
221  /// \return - True on success.
222  //
223  // FIXME: This function should take the stream to write any debugging /
224  // verbose output to as an argument.
225  //
226  // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
227  // of the context or else not CompilerInstance specific.
228  bool ExecuteAction(FrontendAction &Act);
229 
230  /// }
231  /// @name Compiler Invocation and Options
232  /// {
233 
234  bool hasInvocation() const { return Invocation != nullptr; }
235 
237  assert(Invocation && "Compiler instance has no invocation!");
238  return *Invocation;
239  }
240 
241  /// setInvocation - Replace the current invocation.
242  void setInvocation(std::shared_ptr<CompilerInvocation> Value);
243 
244  /// \brief Indicates whether we should (re)build the global module index.
245  bool shouldBuildGlobalModuleIndex() const;
246 
247  /// \brief Set the flag indicating whether we should (re)build the global
248  /// module index.
249  void setBuildGlobalModuleIndex(bool Build) {
250  BuildGlobalModuleIndex = Build;
251  }
252 
253  /// }
254  /// @name Forwarding Methods
255  /// {
256 
258  return Invocation->getAnalyzerOpts();
259  }
260 
262  return Invocation->getCodeGenOpts();
263  }
265  return Invocation->getCodeGenOpts();
266  }
267 
269  return Invocation->getDependencyOutputOpts();
270  }
272  return Invocation->getDependencyOutputOpts();
273  }
274 
276  return Invocation->getDiagnosticOpts();
277  }
279  return Invocation->getDiagnosticOpts();
280  }
281 
283  return Invocation->getFileSystemOpts();
284  }
286  return Invocation->getFileSystemOpts();
287  }
288 
290  return Invocation->getFrontendOpts();
291  }
293  return Invocation->getFrontendOpts();
294  }
295 
297  return Invocation->getHeaderSearchOpts();
298  }
300  return Invocation->getHeaderSearchOpts();
301  }
302  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
303  return Invocation->getHeaderSearchOptsPtr();
304  }
305 
307  return *Invocation->getLangOpts();
308  }
309  const LangOptions &getLangOpts() const {
310  return *Invocation->getLangOpts();
311  }
312 
314  return Invocation->getPreprocessorOpts();
315  }
317  return Invocation->getPreprocessorOpts();
318  }
319 
321  return Invocation->getPreprocessorOutputOpts();
322  }
324  return Invocation->getPreprocessorOutputOpts();
325  }
326 
328  return Invocation->getTargetOpts();
329  }
330  const TargetOptions &getTargetOpts() const {
331  return Invocation->getTargetOpts();
332  }
333 
334  /// }
335  /// @name Diagnostics Engine
336  /// {
337 
338  bool hasDiagnostics() const { return Diagnostics != nullptr; }
339 
340  /// Get the current diagnostics engine.
342  assert(Diagnostics && "Compiler instance has no diagnostics!");
343  return *Diagnostics;
344  }
345 
346  /// setDiagnostics - Replace the current diagnostics engine.
348 
350  assert(Diagnostics && Diagnostics->getClient() &&
351  "Compiler instance has no diagnostic client!");
352  return *Diagnostics->getClient();
353  }
354 
355  /// }
356  /// @name Target Info
357  /// {
358 
359  bool hasTarget() const { return Target != nullptr; }
360 
362  assert(Target && "Compiler instance has no target!");
363  return *Target;
364  }
365 
366  /// Replace the current Target.
367  void setTarget(TargetInfo *Value);
368 
369  /// }
370  /// @name AuxTarget Info
371  /// {
372 
373  TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
374 
375  /// Replace the current AuxTarget.
377 
378  /// }
379  /// @name Virtual File System
380  /// {
381 
382  bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; }
383 
385  assert(hasVirtualFileSystem() &&
386  "Compiler instance has no virtual file system");
387  return *VirtualFileSystem;
388  }
389 
390  /// \brief Replace the current virtual file system.
391  ///
392  /// \note Most clients should use setFileManager, which will implicitly reset
393  /// the virtual file system to the one contained in the file manager.
395  VirtualFileSystem = std::move(FS);
396  }
397 
398  /// }
399  /// @name File Manager
400  /// {
401 
402  bool hasFileManager() const { return FileMgr != nullptr; }
403 
404  /// Return the current file manager to the caller.
406  assert(FileMgr && "Compiler instance has no file manager!");
407  return *FileMgr;
408  }
409 
411  BuryPointer(FileMgr.get());
412  FileMgr.resetWithoutRelease();
413  }
414 
415  /// \brief Replace the current file manager and virtual file system.
417 
418  /// }
419  /// @name Source Manager
420  /// {
421 
422  bool hasSourceManager() const { return SourceMgr != nullptr; }
423 
424  /// Return the current source manager.
426  assert(SourceMgr && "Compiler instance has no source manager!");
427  return *SourceMgr;
428  }
429 
431  BuryPointer(SourceMgr.get());
432  SourceMgr.resetWithoutRelease();
433  }
434 
435  /// setSourceManager - Replace the current source manager.
437 
438  /// }
439  /// @name Preprocessor
440  /// {
441 
442  bool hasPreprocessor() const { return PP != nullptr; }
443 
444  /// Return the current preprocessor.
446  assert(PP && "Compiler instance has no preprocessor!");
447  return *PP;
448  }
449 
450  std::shared_ptr<Preprocessor> getPreprocessorPtr() { return PP; }
451 
453  BuryPointer(new std::shared_ptr<Preprocessor>(PP));
454  }
455 
456  /// Replace the current preprocessor.
457  void setPreprocessor(std::shared_ptr<Preprocessor> Value);
458 
459  /// }
460  /// @name ASTContext
461  /// {
462 
463  bool hasASTContext() const { return Context != nullptr; }
464 
466  assert(Context && "Compiler instance has no AST context!");
467  return *Context;
468  }
469 
471  BuryPointer(Context.get());
472  Context.resetWithoutRelease();
473  }
474 
475  /// setASTContext - Replace the current AST context.
477 
478  /// \brief Replace the current Sema; the compiler instance takes ownership
479  /// of S.
480  void setSema(Sema *S);
481 
482  /// }
483  /// @name ASTConsumer
484  /// {
485 
486  bool hasASTConsumer() const { return (bool)Consumer; }
487 
489  assert(Consumer && "Compiler instance has no AST consumer!");
490  return *Consumer;
491  }
492 
493  /// takeASTConsumer - Remove the current AST consumer and give ownership to
494  /// the caller.
495  std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
496 
497  /// setASTConsumer - Replace the current AST consumer; the compiler instance
498  /// takes ownership of \p Value.
499  void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
500 
501  /// }
502  /// @name Semantic analysis
503  /// {
504  bool hasSema() const { return (bool)TheSema; }
505 
506  Sema &getSema() const {
507  assert(TheSema && "Compiler instance has no Sema object!");
508  return *TheSema;
509  }
510 
511  std::unique_ptr<Sema> takeSema();
512  void resetAndLeakSema();
513 
514  /// }
515  /// @name Module Management
516  /// {
517 
520 
521  std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
523  std::shared_ptr<ModuleDependencyCollector> Collector);
524 
525  std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
526  return ThePCHContainerOperations;
527  }
528 
529  /// Return the appropriate PCHContainerWriter depending on the
530  /// current CodeGenOptions.
532  assert(Invocation && "cannot determine module format without invocation");
533  StringRef Format = getHeaderSearchOpts().ModuleFormat;
534  auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
535  if (!Writer) {
536  if (Diagnostics)
537  Diagnostics->Report(diag::err_module_format_unhandled) << Format;
538  llvm::report_fatal_error("unknown module format");
539  }
540  return *Writer;
541  }
542 
543  /// Return the appropriate PCHContainerReader depending on the
544  /// current CodeGenOptions.
546  assert(Invocation && "cannot determine module format without invocation");
547  StringRef Format = getHeaderSearchOpts().ModuleFormat;
548  auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
549  if (!Reader) {
550  if (Diagnostics)
551  Diagnostics->Report(diag::err_module_format_unhandled) << Format;
552  llvm::report_fatal_error("unknown module format");
553  }
554  return *Reader;
555  }
556 
557  /// }
558  /// @name Code Completion
559  /// {
560 
561  bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
562 
564  assert(CompletionConsumer &&
565  "Compiler instance has no code completion consumer!");
566  return *CompletionConsumer;
567  }
568 
569  /// setCodeCompletionConsumer - Replace the current code completion consumer;
570  /// the compiler instance takes ownership of \p Value.
572 
573  /// }
574  /// @name Frontend timer
575  /// {
576 
577  bool hasFrontendTimer() const { return (bool)FrontendTimer; }
578 
579  llvm::Timer &getFrontendTimer() const {
580  assert(FrontendTimer && "Compiler instance has no frontend timer!");
581  return *FrontendTimer;
582  }
583 
584  /// }
585  /// @name Output Files
586  /// {
587 
588  /// addOutputFile - Add an output file onto the list of tracked output files.
589  ///
590  /// \param OutFile - The output file info.
591  void addOutputFile(OutputFile &&OutFile);
592 
593  /// clearOutputFiles - Clear the output file list. The underlying output
594  /// streams must have been closed beforehand.
595  ///
596  /// \param EraseFiles - If true, attempt to erase the files from disk.
597  void clearOutputFiles(bool EraseFiles);
598 
599  /// }
600  /// @name Construction Utility Methods
601  /// {
602 
603  /// Create the diagnostics engine using the invocation's diagnostic options
604  /// and replace any existing one with it.
605  ///
606  /// Note that this routine also replaces the diagnostic client,
607  /// allocating one if one is not provided.
608  ///
609  /// \param Client If non-NULL, a diagnostic client that will be
610  /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
611  /// unit.
612  ///
613  /// \param ShouldOwnClient If Client is non-NULL, specifies whether
614  /// the diagnostic object should take ownership of the client.
615  void createDiagnostics(DiagnosticConsumer *Client = nullptr,
616  bool ShouldOwnClient = true);
617 
618  /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
619  ///
620  /// If no diagnostic client is provided, this creates a
621  /// DiagnosticConsumer that is owned by the returned diagnostic
622  /// object, if using directly the caller is responsible for
623  /// releasing the returned DiagnosticsEngine's client eventually.
624  ///
625  /// \param Opts - The diagnostic options; note that the created text
626  /// diagnostic object contains a reference to these options.
627  ///
628  /// \param Client If non-NULL, a diagnostic client that will be
629  /// attached to (and, then, owned by) the returned DiagnosticsEngine
630  /// object.
631  ///
632  /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
633  /// used by some diagnostics printers (for logging purposes only).
634  ///
635  /// \return The new object on success, or null on failure.
638  DiagnosticConsumer *Client = nullptr,
639  bool ShouldOwnClient = true,
640  const CodeGenOptions *CodeGenOpts = nullptr);
641 
642  /// Create the file manager and replace any existing one with it.
643  void createFileManager();
644 
645  /// Create the source manager and replace any existing one with it.
646  void createSourceManager(FileManager &FileMgr);
647 
648  /// Create the preprocessor, using the invocation, file, and source managers,
649  /// and replace any existing one with it.
651 
652  std::string getSpecificModuleCachePath();
653 
654  /// Create the AST context.
655  void createASTContext();
656 
657  /// Create an external AST source to read a PCH file and attach it to the AST
658  /// context.
659  void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation,
660  bool AllowPCHWithCompilerErrors,
661  void *DeserializationListener,
662  bool OwnDeserializationListener);
663 
664  /// Create an external AST source to read a PCH file.
665  ///
666  /// \return - The new object on success, or null on failure.
668  StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
669  bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
670  const PCHContainerReader &PCHContainerRdr,
671  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
672  DependencyFileGenerator *DependencyFile,
673  ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
674  void *DeserializationListener, bool OwnDeserializationListener,
675  bool Preamble, bool UseGlobalModuleIndex);
676 
677  /// Create a code completion consumer using the invocation; note that this
678  /// will cause the source manager to truncate the input source file at the
679  /// completion point.
681 
682  /// Create a code completion consumer to print code completion results, at
683  /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
685  Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
686  const CodeCompleteOptions &Opts, raw_ostream &OS);
687 
688  /// \brief Create the Sema object to be used for parsing.
689  void createSema(TranslationUnitKind TUKind,
690  CodeCompleteConsumer *CompletionConsumer);
691 
692  /// Create the frontend timer and replace any existing one with it.
693  void createFrontendTimer();
694 
695  /// Create the default output file (from the invocation's options) and add it
696  /// to the list of tracked output files.
697  ///
698  /// The files created by this function always use temporary files to write to
699  /// their result (that is, the data is written to a temporary file which will
700  /// atomically replace the target output on success).
701  ///
702  /// \return - Null on error.
703  std::unique_ptr<raw_pwrite_stream>
704  createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "",
705  StringRef Extension = "");
706 
707  /// Create a new output file and add it to the list of tracked output files,
708  /// optionally deriving the output path name.
709  ///
710  /// \return - Null on error.
711  std::unique_ptr<raw_pwrite_stream>
712  createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal,
713  StringRef BaseInput, StringRef Extension, bool UseTemporary,
714  bool CreateMissingDirectories = false);
715 
716  /// Create a new output file, optionally deriving the output path name.
717  ///
718  /// If \p OutputPath is empty, then createOutputFile will derive an output
719  /// path location as \p BaseInput, with any suffix removed, and \p Extension
720  /// appended. If \p OutputPath is not stdout and \p UseTemporary
721  /// is true, createOutputFile will create a new temporary file that must be
722  /// renamed to \p OutputPath in the end.
723  ///
724  /// \param OutputPath - If given, the path to the output file.
725  /// \param Error [out] - On failure, the error.
726  /// \param BaseInput - If \p OutputPath is empty, the input path name to use
727  /// for deriving the output path.
728  /// \param Extension - The extension to use for derived output names.
729  /// \param Binary - The mode to open the file in.
730  /// \param RemoveFileOnSignal - Whether the file should be registered with
731  /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
732  /// multithreaded use, as the underlying signal mechanism is not reentrant
733  /// \param UseTemporary - Create a new temporary file that must be renamed to
734  /// OutputPath in the end.
735  /// \param CreateMissingDirectories - When \p UseTemporary is true, create
736  /// missing directories in the output path.
737  /// \param ResultPathName [out] - If given, the result path name will be
738  /// stored here on success.
739  /// \param TempPathName [out] - If given, the temporary file path name
740  /// will be stored here on success.
741  std::unique_ptr<raw_pwrite_stream>
742  createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary,
743  bool RemoveFileOnSignal, StringRef BaseInput,
744  StringRef Extension, bool UseTemporary,
745  bool CreateMissingDirectories, std::string *ResultPathName,
746  std::string *TempPathName);
747 
748  std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
749 
750  /// }
751  /// @name Initialization Utility Methods
752  /// {
753 
754  /// InitializeSourceManager - Initialize the source manager to set InputFile
755  /// as the main file.
756  ///
757  /// \return True on success.
759 
760  /// InitializeSourceManager - Initialize the source manager to set InputFile
761  /// as the main file.
762  ///
763  /// \return True on success.
765  DiagnosticsEngine &Diags,
766  FileManager &FileMgr,
767  SourceManager &SourceMgr,
768  HeaderSearch *HS,
769  DependencyOutputOptions &DepOpts,
770  const FrontendOptions &Opts);
771 
772  /// }
773 
774  // Create module manager.
775  void createModuleManager();
776 
777  bool loadModuleFile(StringRef FileName);
778 
781  bool IsInclusionDirective) override;
782 
783  void loadModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName,
784  StringRef Source) override;
785 
787  SourceLocation ImportLoc) override;
788 
791  }
792 
794 
795  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
796 
797  void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
798  DependencyCollectors.push_back(std::move(Listener));
799  }
800 
802 
803  MemoryBufferCache &getPCMCache() const { return *PCMCache; }
804 };
805 
806 } // end namespace clang
807 
808 #endif
LangOptions & getLangOpts()
ASTContext & getASTContext() const
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
void createFrontendTimer()
Create the frontend timer and replace any existing one with it.
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:34
void setCodeCompletionConsumer(CodeCompleteConsumer *Value)
setCodeCompletionConsumer - Replace the current code completion consumer; the compiler instance takes...
vfs::FileSystem & getVirtualFileSystem() const
void createDiagnostics(DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)
Create the diagnostics engine using the invocation's diagnostic options and replace any existing one ...
Defines the SourceManager interface.
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()
bool hasCodeCompletionConsumer() const
bool InitializeSourceManager(const FrontendInputFile &Input)
InitializeSourceManager - Initialize the source manager to set InputFile as the main file...
void setAuxTarget(TargetInfo *Value)
Replace the current AuxTarget.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
void setModuleManager(IntrusiveRefCntPtr< ASTReader > Reader)
TargetInfo & getTarget() const
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
SourceManager & getSourceManager() const
Return the current source manager.
Options for controlling the target.
Definition: TargetOptions.h:26
Manage memory buffers across multiple users.
const DependencyOutputOptions & getDependencyOutputOpts() const
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1395
DependencyOutputOptions & getDependencyOutputOpts()
const HeaderSearchOptions & getHeaderSearchOpts() const
void setExternalSemaSource(IntrusiveRefCntPtr< ExternalSemaSource > ESS)
The virtual file system interface.
void loadModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName, StringRef Source) override
Attempt to load the given module from the specified source buffer.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
void createFileManager()
Create the file manager and replace any existing one with it.
void createSourceManager(FileManager &FileMgr)
Create the source manager and replace any existing one with it.
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
CodeGenOptions & getCodeGenOpts()
std::shared_ptr< Preprocessor > getPreprocessorPtr()
const PreprocessorOptions & getPreprocessorOpts() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
ASTConsumer & getASTConsumer() const
Describes a module or submodule.
Definition: Module.h:57
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) override
Make the given module visible.
void setBuildGlobalModuleIndex(bool Build)
Set the flag indicating whether we should (re)build the global module index.
This abstract interface provides operations for creating containers for serialized ASTs (precompiled ...
FrontendOptions & getFrontendOpts()
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
DiagnosticConsumer & getDiagnosticClient() const
PreprocessorOutputOptions & getPreprocessorOutputOpts()
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
Defines the Diagnostic-related interfaces.
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value...
IntrusiveRefCntPtr< ASTReader > getModuleManager() const
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
HeaderSearchOptions & getHeaderSearchOpts()
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Builds a depdenency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
Definition: Utils.h:111
AnalyzerOptionsRef getAnalyzerOpts()
void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
Create an external AST source to read a PCH file and attach it to the AST context.
bool hasVirtualFileSystem() const
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:137
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:269
void setVirtualFileSystem(IntrusiveRefCntPtr< vfs::FileSystem > FS)
Replace the current virtual file system.
Describes the result of attempting to load a module.
Definition: ModuleLoader.h:33
StringRef Filename
Definition: Format.cpp:1301
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
Exposes information about the current target.
Definition: TargetInfo.h:54
void addDependencyCollector(std::shared_ptr< DependencyCollector > Listener)
bool hadModuleLoaderFatalFailure() const
std::string getSpecificModuleCachePath()
void createASTContext()
Create the AST context.
const FrontendOptions & getFrontendOpts() const
void setSema(Sema *S)
Replace the current Sema; the compiler instance takes ownership of S.
MemoryBufferCache & getPCMCache() const
An input file for the front end.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
void addOutputFile(OutputFile &&OutFile)
addOutputFile - Add an output file onto the list of tracked output files.
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...
bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
Check global module index for missing imports.
std::unique_ptr< Sema > takeSema()
bool hasSourceManager() const
FileSystemOptions & getFileSystemOpts()
StringRef FileName
Definition: Format.cpp:1465
bool ExecuteAction(FrontendAction &Act)
ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object...
const TargetOptions & getTargetOpts() const
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
AnnotatedLine & Line
Options for controlling the compiler diagnostics engine.
std::unique_ptr< raw_pwrite_stream > createNullOutputFile()
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
void createPreprocessor(TranslationUnitKind TUKind)
Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...
A global index for a set of module files, providing information about the identifiers within those mo...
TargetInfo * getAuxTarget() const
Abstract interface for a consumer of code-completion information.
Options controlling the behavior of code completion.
bool hasFrontendTimer() const
void setPreprocessor(std::shared_ptr< Preprocessor > Value)
Replace the current preprocessor.
StringRef Name
Definition: USRFinder.cpp:123
const LangOptions & getLangOpts() const
const DiagnosticOptions & getDiagnosticOpts() const
FileManager & getFileManager() const
Return the current file manager to the caller.
bool loadModuleFile(StringRef FileName)
std::shared_ptr< HeaderSearchOptions > getHeaderSearchOptsPtr() const
Helper class for holding the data necessary to invoke the compiler.
FrontendOptions - Options for controlling the behavior of the frontend.
Abstract interface for a module loader.
Definition: ModuleLoader.h:69
void clearOutputFiles(bool EraseFiles)
clearOutputFiles - Clear the output file list.
void BuryPointer(const void *Ptr)
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CodeCompleteConsumer & getCodeCompletionConsumer() const
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
void setTarget(TargetInfo *Value)
Replace the current Target.
Keeps track of options that affect how file operations are performed.
const PCHContainerWriter & getPCHContainerWriter() const
Return the appropriate PCHContainerWriter depending on the current CodeGenOptions.
void setInvocation(std::shared_ptr< CompilerInvocation > Value)
setInvocation - Replace the current invocation.
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
llvm::Timer & getFrontendTimer() const
std::shared_ptr< ModuleDependencyCollector > getModuleDepCollector() const
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:237
const FileSystemOptions & getFileSystemOpts() const
const StringRef Input
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:244
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
const CodeGenOptions & getCodeGenOpts() const
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override
Attempt to load the given module.
void setModuleDepCollector(std::shared_ptr< ModuleDependencyCollector > Collector)
GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc) override
Load, create, or return global module.
TargetOptions & getTargetOpts()
This class handles loading and caching of source files into memory.
void setDiagnostics(DiagnosticsEngine *Value)
setDiagnostics - Replace the current diagnostics engine.
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