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