clang API Documentation

CompilerInstance.h
Go to the documentation of this file.
00001 //===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
00011 #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
00012 
00013 #include "clang/Basic/Diagnostic.h"
00014 #include "clang/Basic/SourceManager.h"
00015 #include "clang/Frontend/CompilerInvocation.h"
00016 #include "clang/Frontend/Utils.h"
00017 #include "clang/AST/ASTConsumer.h"
00018 #include "clang/Lex/ModuleLoader.h"
00019 #include "llvm/ADT/ArrayRef.h"
00020 #include "llvm/ADT/DenseMap.h"
00021 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00022 #include "llvm/ADT/StringRef.h"
00023 #include <cassert>
00024 #include <list>
00025 #include <memory>
00026 #include <string>
00027 #include <utility>
00028 
00029 namespace llvm {
00030 class raw_fd_ostream;
00031 class Timer;
00032 }
00033 
00034 namespace clang {
00035 class ASTContext;
00036 class ASTConsumer;
00037 class ASTReader;
00038 class CodeCompleteConsumer;
00039 class DiagnosticsEngine;
00040 class DiagnosticConsumer;
00041 class ExternalASTSource;
00042 class FileEntry;
00043 class FileManager;
00044 class FrontendAction;
00045 class Module;
00046 class Preprocessor;
00047 class Sema;
00048 class SourceManager;
00049 class TargetInfo;
00050 
00051 /// CompilerInstance - Helper class for managing a single instance of the Clang
00052 /// compiler.
00053 ///
00054 /// The CompilerInstance serves two purposes:
00055 ///  (1) It manages the various objects which are necessary to run the compiler,
00056 ///      for example the preprocessor, the target information, and the AST
00057 ///      context.
00058 ///  (2) It provides utility routines for constructing and manipulating the
00059 ///      common Clang objects.
00060 ///
00061 /// The compiler instance generally owns the instance of all the objects that it
00062 /// manages. However, clients can still share objects by manually setting the
00063 /// object and retaking ownership prior to destroying the CompilerInstance.
00064 ///
00065 /// The compiler instance is intended to simplify clients, but not to lock them
00066 /// in to the compiler instance for everything. When possible, utility functions
00067 /// come in two forms; a short form that reuses the CompilerInstance objects,
00068 /// and a long form that takes explicit instances of any required objects.
00069 class CompilerInstance : public ModuleLoader {
00070   /// The options used in this compiler instance.
00071   IntrusiveRefCntPtr<CompilerInvocation> Invocation;
00072 
00073   /// The diagnostics engine instance.
00074   IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
00075 
00076   /// The target being compiled for.
00077   IntrusiveRefCntPtr<TargetInfo> Target;
00078 
00079   /// The virtual file system.
00080   IntrusiveRefCntPtr<vfs::FileSystem> VirtualFileSystem;
00081 
00082   /// The file manager.
00083   IntrusiveRefCntPtr<FileManager> FileMgr;
00084 
00085   /// The source manager.
00086   IntrusiveRefCntPtr<SourceManager> SourceMgr;
00087 
00088   /// The preprocessor.
00089   IntrusiveRefCntPtr<Preprocessor> PP;
00090 
00091   /// The AST context.
00092   IntrusiveRefCntPtr<ASTContext> Context;
00093 
00094   /// The AST consumer.
00095   std::unique_ptr<ASTConsumer> Consumer;
00096 
00097   /// The code completion consumer.
00098   std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
00099 
00100   /// \brief The semantic analysis object.
00101   std::unique_ptr<Sema> TheSema;
00102 
00103   /// \brief The frontend timer
00104   std::unique_ptr<llvm::Timer> FrontendTimer;
00105 
00106   /// \brief The ASTReader, if one exists.
00107   IntrusiveRefCntPtr<ASTReader> ModuleManager;
00108 
00109   /// \brief The module dependency collector for crashdumps
00110   std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
00111 
00112   /// \brief The dependency file generator.
00113   std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
00114 
00115   std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
00116 
00117   /// \brief The set of top-level modules that has already been loaded,
00118   /// along with the module map
00119   llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
00120 
00121   /// \brief Module names that have an override for the target file.
00122   llvm::StringMap<std::string> ModuleFileOverrides;
00123 
00124   /// \brief The location of the module-import keyword for the last module
00125   /// import. 
00126   SourceLocation LastModuleImportLoc;
00127   
00128   /// \brief The result of the last module import.
00129   ///
00130   ModuleLoadResult LastModuleImportResult;
00131 
00132   /// \brief Whether we should (re)build the global module index once we
00133   /// have finished with this translation unit.
00134   bool BuildGlobalModuleIndex;
00135 
00136   /// \brief We have a full global module index, with all modules.
00137   bool HaveFullGlobalModuleIndex;
00138 
00139   /// \brief One or more modules failed to build.
00140   bool ModuleBuildFailed;
00141 
00142   /// \brief Holds information about the output file.
00143   ///
00144   /// If TempFilename is not empty we must rename it to Filename at the end.
00145   /// TempFilename may be empty and Filename non-empty if creating the temporary
00146   /// failed.
00147   struct OutputFile {
00148     std::string Filename;
00149     std::string TempFilename;
00150     raw_ostream *OS;
00151 
00152     OutputFile(const std::string &filename, const std::string &tempFilename,
00153                raw_ostream *os)
00154       : Filename(filename), TempFilename(tempFilename), OS(os) { }
00155   };
00156 
00157   /// The list of active output files.
00158   std::list<OutputFile> OutputFiles;
00159 
00160   CompilerInstance(const CompilerInstance &) LLVM_DELETED_FUNCTION;
00161   void operator=(const CompilerInstance &) LLVM_DELETED_FUNCTION;
00162 public:
00163   explicit CompilerInstance(bool BuildingModule = false);
00164   ~CompilerInstance();
00165 
00166   /// @name High-Level Operations
00167   /// {
00168 
00169   /// ExecuteAction - Execute the provided action against the compiler's
00170   /// CompilerInvocation object.
00171   ///
00172   /// This function makes the following assumptions:
00173   ///
00174   ///  - The invocation options should be initialized. This function does not
00175   ///    handle the '-help' or '-version' options, clients should handle those
00176   ///    directly.
00177   ///
00178   ///  - The diagnostics engine should have already been created by the client.
00179   ///
00180   ///  - No other CompilerInstance state should have been initialized (this is
00181   ///    an unchecked error).
00182   ///
00183   ///  - Clients should have initialized any LLVM target features that may be
00184   ///    required.
00185   ///
00186   ///  - Clients should eventually call llvm_shutdown() upon the completion of
00187   ///    this routine to ensure that any managed objects are properly destroyed.
00188   ///
00189   /// Note that this routine may write output to 'stderr'.
00190   ///
00191   /// \param Act - The action to execute.
00192   /// \return - True on success.
00193   //
00194   // FIXME: This function should take the stream to write any debugging /
00195   // verbose output to as an argument.
00196   //
00197   // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
00198   // of the context or else not CompilerInstance specific.
00199   bool ExecuteAction(FrontendAction &Act);
00200 
00201   /// }
00202   /// @name Compiler Invocation and Options
00203   /// {
00204 
00205   bool hasInvocation() const { return Invocation != nullptr; }
00206 
00207   CompilerInvocation &getInvocation() {
00208     assert(Invocation && "Compiler instance has no invocation!");
00209     return *Invocation;
00210   }
00211 
00212   /// setInvocation - Replace the current invocation.
00213   void setInvocation(CompilerInvocation *Value);
00214 
00215   /// \brief Indicates whether we should (re)build the global module index.
00216   bool shouldBuildGlobalModuleIndex() const;
00217   
00218   /// \brief Set the flag indicating whether we should (re)build the global
00219   /// module index.
00220   void setBuildGlobalModuleIndex(bool Build) {
00221     BuildGlobalModuleIndex = Build;
00222   }
00223 
00224   /// }
00225   /// @name Forwarding Methods
00226   /// {
00227 
00228   AnalyzerOptionsRef getAnalyzerOpts() {
00229     return Invocation->getAnalyzerOpts();
00230   }
00231 
00232   CodeGenOptions &getCodeGenOpts() {
00233     return Invocation->getCodeGenOpts();
00234   }
00235   const CodeGenOptions &getCodeGenOpts() const {
00236     return Invocation->getCodeGenOpts();
00237   }
00238 
00239   DependencyOutputOptions &getDependencyOutputOpts() {
00240     return Invocation->getDependencyOutputOpts();
00241   }
00242   const DependencyOutputOptions &getDependencyOutputOpts() const {
00243     return Invocation->getDependencyOutputOpts();
00244   }
00245 
00246   DiagnosticOptions &getDiagnosticOpts() {
00247     return Invocation->getDiagnosticOpts();
00248   }
00249   const DiagnosticOptions &getDiagnosticOpts() const {
00250     return Invocation->getDiagnosticOpts();
00251   }
00252 
00253   const FileSystemOptions &getFileSystemOpts() const {
00254     return Invocation->getFileSystemOpts();
00255   }
00256 
00257   FrontendOptions &getFrontendOpts() {
00258     return Invocation->getFrontendOpts();
00259   }
00260   const FrontendOptions &getFrontendOpts() const {
00261     return Invocation->getFrontendOpts();
00262   }
00263 
00264   HeaderSearchOptions &getHeaderSearchOpts() {
00265     return Invocation->getHeaderSearchOpts();
00266   }
00267   const HeaderSearchOptions &getHeaderSearchOpts() const {
00268     return Invocation->getHeaderSearchOpts();
00269   }
00270 
00271   LangOptions &getLangOpts() {
00272     return *Invocation->getLangOpts();
00273   }
00274   const LangOptions &getLangOpts() const {
00275     return *Invocation->getLangOpts();
00276   }
00277 
00278   PreprocessorOptions &getPreprocessorOpts() {
00279     return Invocation->getPreprocessorOpts();
00280   }
00281   const PreprocessorOptions &getPreprocessorOpts() const {
00282     return Invocation->getPreprocessorOpts();
00283   }
00284 
00285   PreprocessorOutputOptions &getPreprocessorOutputOpts() {
00286     return Invocation->getPreprocessorOutputOpts();
00287   }
00288   const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
00289     return Invocation->getPreprocessorOutputOpts();
00290   }
00291 
00292   TargetOptions &getTargetOpts() {
00293     return Invocation->getTargetOpts();
00294   }
00295   const TargetOptions &getTargetOpts() const {
00296     return Invocation->getTargetOpts();
00297   }
00298 
00299   /// }
00300   /// @name Diagnostics Engine
00301   /// {
00302 
00303   bool hasDiagnostics() const { return Diagnostics != nullptr; }
00304 
00305   /// Get the current diagnostics engine.
00306   DiagnosticsEngine &getDiagnostics() const {
00307     assert(Diagnostics && "Compiler instance has no diagnostics!");
00308     return *Diagnostics;
00309   }
00310 
00311   /// setDiagnostics - Replace the current diagnostics engine.
00312   void setDiagnostics(DiagnosticsEngine *Value);
00313 
00314   DiagnosticConsumer &getDiagnosticClient() const {
00315     assert(Diagnostics && Diagnostics->getClient() && 
00316            "Compiler instance has no diagnostic client!");
00317     return *Diagnostics->getClient();
00318   }
00319 
00320   /// }
00321   /// @name Target Info
00322   /// {
00323 
00324   bool hasTarget() const { return Target != nullptr; }
00325 
00326   TargetInfo &getTarget() const {
00327     assert(Target && "Compiler instance has no target!");
00328     return *Target;
00329   }
00330 
00331   /// Replace the current diagnostics engine.
00332   void setTarget(TargetInfo *Value);
00333 
00334   /// }
00335   /// @name Virtual File System
00336   /// {
00337 
00338   bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; }
00339 
00340   vfs::FileSystem &getVirtualFileSystem() const {
00341     assert(hasVirtualFileSystem() &&
00342            "Compiler instance has no virtual file system");
00343     return *VirtualFileSystem;
00344   }
00345 
00346   /// \brief Replace the current virtual file system.
00347   ///
00348   /// \note Most clients should use setFileManager, which will implicitly reset
00349   /// the virtual file system to the one contained in the file manager.
00350   void setVirtualFileSystem(IntrusiveRefCntPtr<vfs::FileSystem> FS) {
00351     VirtualFileSystem = FS;
00352   }
00353 
00354   /// }
00355   /// @name File Manager
00356   /// {
00357 
00358   bool hasFileManager() const { return FileMgr != nullptr; }
00359 
00360   /// Return the current file manager to the caller.
00361   FileManager &getFileManager() const {
00362     assert(FileMgr && "Compiler instance has no file manager!");
00363     return *FileMgr;
00364   }
00365   
00366   void resetAndLeakFileManager() {
00367     BuryPointer(FileMgr.get());
00368     FileMgr.resetWithoutRelease();
00369   }
00370 
00371   /// \brief Replace the current file manager and virtual file system.
00372   void setFileManager(FileManager *Value);
00373 
00374   /// }
00375   /// @name Source Manager
00376   /// {
00377 
00378   bool hasSourceManager() const { return SourceMgr != nullptr; }
00379 
00380   /// Return the current source manager.
00381   SourceManager &getSourceManager() const {
00382     assert(SourceMgr && "Compiler instance has no source manager!");
00383     return *SourceMgr;
00384   }
00385   
00386   void resetAndLeakSourceManager() {
00387     BuryPointer(SourceMgr.get());
00388     SourceMgr.resetWithoutRelease();
00389   }
00390 
00391   /// setSourceManager - Replace the current source manager.
00392   void setSourceManager(SourceManager *Value);
00393 
00394   /// }
00395   /// @name Preprocessor
00396   /// {
00397 
00398   bool hasPreprocessor() const { return PP != nullptr; }
00399 
00400   /// Return the current preprocessor.
00401   Preprocessor &getPreprocessor() const {
00402     assert(PP && "Compiler instance has no preprocessor!");
00403     return *PP;
00404   }
00405 
00406   void resetAndLeakPreprocessor() {
00407     BuryPointer(PP.get());
00408     PP.resetWithoutRelease();
00409   }
00410 
00411   /// Replace the current preprocessor.
00412   void setPreprocessor(Preprocessor *Value);
00413 
00414   /// }
00415   /// @name ASTContext
00416   /// {
00417 
00418   bool hasASTContext() const { return Context != nullptr; }
00419 
00420   ASTContext &getASTContext() const {
00421     assert(Context && "Compiler instance has no AST context!");
00422     return *Context;
00423   }
00424   
00425   void resetAndLeakASTContext() {
00426     BuryPointer(Context.get());
00427     Context.resetWithoutRelease();
00428   }
00429 
00430   /// setASTContext - Replace the current AST context.
00431   void setASTContext(ASTContext *Value);
00432 
00433   /// \brief Replace the current Sema; the compiler instance takes ownership
00434   /// of S.
00435   void setSema(Sema *S);
00436   
00437   /// }
00438   /// @name ASTConsumer
00439   /// {
00440 
00441   bool hasASTConsumer() const { return (bool)Consumer; }
00442 
00443   ASTConsumer &getASTConsumer() const {
00444     assert(Consumer && "Compiler instance has no AST consumer!");
00445     return *Consumer;
00446   }
00447 
00448   /// takeASTConsumer - Remove the current AST consumer and give ownership to
00449   /// the caller.
00450   std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
00451 
00452   /// setASTConsumer - Replace the current AST consumer; the compiler instance
00453   /// takes ownership of \p Value.
00454   void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
00455 
00456   /// }
00457   /// @name Semantic analysis
00458   /// {
00459   bool hasSema() const { return (bool)TheSema; }
00460 
00461   Sema &getSema() const { 
00462     assert(TheSema && "Compiler instance has no Sema object!");
00463     return *TheSema;
00464   }
00465 
00466   std::unique_ptr<Sema> takeSema();
00467   void resetAndLeakSema();
00468 
00469   /// }
00470   /// @name Module Management
00471   /// {
00472 
00473   IntrusiveRefCntPtr<ASTReader> getModuleManager() const;
00474   void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader);
00475 
00476   std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
00477   void setModuleDepCollector(
00478       std::shared_ptr<ModuleDependencyCollector> Collector);
00479 
00480   /// }
00481   /// @name Code Completion
00482   /// {
00483 
00484   bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
00485 
00486   CodeCompleteConsumer &getCodeCompletionConsumer() const {
00487     assert(CompletionConsumer &&
00488            "Compiler instance has no code completion consumer!");
00489     return *CompletionConsumer;
00490   }
00491 
00492   /// setCodeCompletionConsumer - Replace the current code completion consumer;
00493   /// the compiler instance takes ownership of \p Value.
00494   void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
00495 
00496   /// }
00497   /// @name Frontend timer
00498   /// {
00499 
00500   bool hasFrontendTimer() const { return (bool)FrontendTimer; }
00501 
00502   llvm::Timer &getFrontendTimer() const {
00503     assert(FrontendTimer && "Compiler instance has no frontend timer!");
00504     return *FrontendTimer;
00505   }
00506 
00507   /// }
00508   /// @name Output Files
00509   /// {
00510 
00511   /// addOutputFile - Add an output file onto the list of tracked output files.
00512   ///
00513   /// \param OutFile - The output file info.
00514   void addOutputFile(const OutputFile &OutFile);
00515 
00516   /// clearOutputFiles - Clear the output file list, destroying the contained
00517   /// output streams.
00518   ///
00519   /// \param EraseFiles - If true, attempt to erase the files from disk.
00520   void clearOutputFiles(bool EraseFiles);
00521 
00522   /// }
00523   /// @name Construction Utility Methods
00524   /// {
00525 
00526   /// Create the diagnostics engine using the invocation's diagnostic options
00527   /// and replace any existing one with it.
00528   ///
00529   /// Note that this routine also replaces the diagnostic client,
00530   /// allocating one if one is not provided.
00531   ///
00532   /// \param Client If non-NULL, a diagnostic client that will be
00533   /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
00534   /// unit.
00535   ///
00536   /// \param ShouldOwnClient If Client is non-NULL, specifies whether 
00537   /// the diagnostic object should take ownership of the client.
00538   void createDiagnostics(DiagnosticConsumer *Client = nullptr,
00539                          bool ShouldOwnClient = true);
00540 
00541   /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
00542   ///
00543   /// If no diagnostic client is provided, this creates a
00544   /// DiagnosticConsumer that is owned by the returned diagnostic
00545   /// object, if using directly the caller is responsible for
00546   /// releasing the returned DiagnosticsEngine's client eventually.
00547   ///
00548   /// \param Opts - The diagnostic options; note that the created text
00549   /// diagnostic object contains a reference to these options.
00550   ///
00551   /// \param Client If non-NULL, a diagnostic client that will be
00552   /// attached to (and, then, owned by) the returned DiagnosticsEngine
00553   /// object.
00554   ///
00555   /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
00556   /// used by some diagnostics printers (for logging purposes only).
00557   ///
00558   /// \return The new object on success, or null on failure.
00559   static IntrusiveRefCntPtr<DiagnosticsEngine>
00560   createDiagnostics(DiagnosticOptions *Opts,
00561                     DiagnosticConsumer *Client = nullptr,
00562                     bool ShouldOwnClient = true,
00563                     const CodeGenOptions *CodeGenOpts = nullptr);
00564 
00565   /// Create the file manager and replace any existing one with it.
00566   void createFileManager();
00567 
00568   /// Create the source manager and replace any existing one with it.
00569   void createSourceManager(FileManager &FileMgr);
00570 
00571   /// Create the preprocessor, using the invocation, file, and source managers,
00572   /// and replace any existing one with it.
00573   void createPreprocessor(TranslationUnitKind TUKind);
00574 
00575   /// Create the AST context.
00576   void createASTContext();
00577 
00578   /// Create an external AST source to read a PCH file and attach it to the AST
00579   /// context.
00580   void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation,
00581                                   bool AllowPCHWithCompilerErrors,
00582                                   void *DeserializationListener,
00583                                   bool OwnDeserializationListener);
00584 
00585   /// Create an external AST source to read a PCH file.
00586   ///
00587   /// \return - The new object on success, or null on failure.
00588   static ExternalASTSource *createPCHExternalASTSource(
00589       StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
00590       bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
00591       void *DeserializationListener, bool OwnDeserializationListener,
00592       bool Preamble, bool UseGlobalModuleIndex);
00593 
00594   /// Create a code completion consumer using the invocation; note that this
00595   /// will cause the source manager to truncate the input source file at the
00596   /// completion point.
00597   void createCodeCompletionConsumer();
00598 
00599   /// Create a code completion consumer to print code completion results, at
00600   /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
00601   static CodeCompleteConsumer *
00602   createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
00603                                unsigned Line, unsigned Column,
00604                                const CodeCompleteOptions &Opts,
00605                                raw_ostream &OS);
00606 
00607   /// \brief Create the Sema object to be used for parsing.
00608   void createSema(TranslationUnitKind TUKind,
00609                   CodeCompleteConsumer *CompletionConsumer);
00610   
00611   /// Create the frontend timer and replace any existing one with it.
00612   void createFrontendTimer();
00613 
00614   /// Create the default output file (from the invocation's options) and add it
00615   /// to the list of tracked output files.
00616   ///
00617   /// The files created by this function always use temporary files to write to
00618   /// their result (that is, the data is written to a temporary file which will
00619   /// atomically replace the target output on success).
00620   ///
00621   /// \return - Null on error.
00622   llvm::raw_fd_ostream *
00623   createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "",
00624                           StringRef Extension = "");
00625 
00626   /// Create a new output file and add it to the list of tracked output files,
00627   /// optionally deriving the output path name.
00628   ///
00629   /// \return - Null on error.
00630   llvm::raw_fd_ostream *
00631   createOutputFile(StringRef OutputPath,
00632                    bool Binary, bool RemoveFileOnSignal,
00633                    StringRef BaseInput,
00634                    StringRef Extension,
00635                    bool UseTemporary,
00636                    bool CreateMissingDirectories = false);
00637 
00638   /// Create a new output file, optionally deriving the output path name.
00639   ///
00640   /// If \p OutputPath is empty, then createOutputFile will derive an output
00641   /// path location as \p BaseInput, with any suffix removed, and \p Extension
00642   /// appended. If \p OutputPath is not stdout and \p UseTemporary
00643   /// is true, createOutputFile will create a new temporary file that must be
00644   /// renamed to \p OutputPath in the end.
00645   ///
00646   /// \param OutputPath - If given, the path to the output file.
00647   /// \param Error [out] - On failure, the error.
00648   /// \param BaseInput - If \p OutputPath is empty, the input path name to use
00649   /// for deriving the output path.
00650   /// \param Extension - The extension to use for derived output names.
00651   /// \param Binary - The mode to open the file in.
00652   /// \param RemoveFileOnSignal - Whether the file should be registered with
00653   /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
00654   /// multithreaded use, as the underlying signal mechanism is not reentrant
00655   /// \param UseTemporary - Create a new temporary file that must be renamed to
00656   /// OutputPath in the end.
00657   /// \param CreateMissingDirectories - When \p UseTemporary is true, create
00658   /// missing directories in the output path.
00659   /// \param ResultPathName [out] - If given, the result path name will be
00660   /// stored here on success.
00661   /// \param TempPathName [out] - If given, the temporary file path name
00662   /// will be stored here on success.
00663   static llvm::raw_fd_ostream *
00664   createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary,
00665                    bool RemoveFileOnSignal, StringRef BaseInput,
00666                    StringRef Extension, bool UseTemporary,
00667                    bool CreateMissingDirectories, std::string *ResultPathName,
00668                    std::string *TempPathName);
00669 
00670   llvm::raw_null_ostream *createNullOutputFile();
00671 
00672   /// }
00673   /// @name Initialization Utility Methods
00674   /// {
00675 
00676   /// InitializeSourceManager - Initialize the source manager to set InputFile
00677   /// as the main file.
00678   ///
00679   /// \return True on success.
00680   bool InitializeSourceManager(const FrontendInputFile &Input);
00681 
00682   /// InitializeSourceManager - Initialize the source manager to set InputFile
00683   /// as the main file.
00684   ///
00685   /// \return True on success.
00686   static bool InitializeSourceManager(const FrontendInputFile &Input,
00687                 DiagnosticsEngine &Diags,
00688                 FileManager &FileMgr,
00689                 SourceManager &SourceMgr,
00690                 const FrontendOptions &Opts);
00691 
00692   /// }
00693 
00694   // Create module manager.
00695   void createModuleManager();
00696 
00697   bool loadModuleFile(StringRef FileName);
00698 
00699   ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
00700                               Module::NameVisibilityKind Visibility,
00701                               bool IsInclusionDirective) override;
00702 
00703   void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility,
00704                          SourceLocation ImportLoc, bool Complain) override;
00705 
00706   bool hadModuleLoaderFatalFailure() const {
00707     return ModuleLoader::HadFatalFailure;
00708   }
00709 
00710   GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override;
00711 
00712   bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
00713 
00714   void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
00715     DependencyCollectors.push_back(std::move(Listener));
00716   }
00717 };
00718 
00719 } // end namespace clang
00720 
00721 #endif