]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Frontend/CompilerInstance.h
Vendor import of clang trunk r290819:
[FreeBSD/FreeBSD.git] / 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   IntrusiveRefCntPtr<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   IntrusiveRefCntPtr<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(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
292   LangOptions &getLangOpts() {
293     return *Invocation->getLangOpts();
294   }
295   const LangOptions &getLangOpts() const {
296     return *Invocation->getLangOpts();
297   }
298
299   PreprocessorOptions &getPreprocessorOpts() {
300     return Invocation->getPreprocessorOpts();
301   }
302   const PreprocessorOptions &getPreprocessorOpts() const {
303     return Invocation->getPreprocessorOpts();
304   }
305
306   PreprocessorOutputOptions &getPreprocessorOutputOpts() {
307     return Invocation->getPreprocessorOutputOpts();
308   }
309   const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
310     return Invocation->getPreprocessorOutputOpts();
311   }
312
313   TargetOptions &getTargetOpts() {
314     return Invocation->getTargetOpts();
315   }
316   const TargetOptions &getTargetOpts() const {
317     return Invocation->getTargetOpts();
318   }
319
320   /// }
321   /// @name Diagnostics Engine
322   /// {
323
324   bool hasDiagnostics() const { return Diagnostics != nullptr; }
325
326   /// Get the current diagnostics engine.
327   DiagnosticsEngine &getDiagnostics() const {
328     assert(Diagnostics && "Compiler instance has no diagnostics!");
329     return *Diagnostics;
330   }
331
332   /// setDiagnostics - Replace the current diagnostics engine.
333   void setDiagnostics(DiagnosticsEngine *Value);
334
335   DiagnosticConsumer &getDiagnosticClient() const {
336     assert(Diagnostics && Diagnostics->getClient() && 
337            "Compiler instance has no diagnostic client!");
338     return *Diagnostics->getClient();
339   }
340
341   /// }
342   /// @name Target Info
343   /// {
344
345   bool hasTarget() const { return Target != nullptr; }
346
347   TargetInfo &getTarget() const {
348     assert(Target && "Compiler instance has no target!");
349     return *Target;
350   }
351
352   /// Replace the current Target.
353   void setTarget(TargetInfo *Value);
354
355   /// }
356   /// @name AuxTarget Info
357   /// {
358
359   TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
360
361   /// Replace the current AuxTarget.
362   void setAuxTarget(TargetInfo *Value);
363
364   /// }
365   /// @name Virtual File System
366   /// {
367
368   bool hasVirtualFileSystem() const { return VirtualFileSystem != nullptr; }
369
370   vfs::FileSystem &getVirtualFileSystem() const {
371     assert(hasVirtualFileSystem() &&
372            "Compiler instance has no virtual file system");
373     return *VirtualFileSystem;
374   }
375
376   /// \brief Replace the current virtual file system.
377   ///
378   /// \note Most clients should use setFileManager, which will implicitly reset
379   /// the virtual file system to the one contained in the file manager.
380   void setVirtualFileSystem(IntrusiveRefCntPtr<vfs::FileSystem> FS) {
381     VirtualFileSystem = std::move(FS);
382   }
383
384   /// }
385   /// @name File Manager
386   /// {
387
388   bool hasFileManager() const { return FileMgr != nullptr; }
389
390   /// Return the current file manager to the caller.
391   FileManager &getFileManager() const {
392     assert(FileMgr && "Compiler instance has no file manager!");
393     return *FileMgr;
394   }
395   
396   void resetAndLeakFileManager() {
397     BuryPointer(FileMgr.get());
398     FileMgr.resetWithoutRelease();
399   }
400
401   /// \brief Replace the current file manager and virtual file system.
402   void setFileManager(FileManager *Value);
403
404   /// }
405   /// @name Source Manager
406   /// {
407
408   bool hasSourceManager() const { return SourceMgr != nullptr; }
409
410   /// Return the current source manager.
411   SourceManager &getSourceManager() const {
412     assert(SourceMgr && "Compiler instance has no source manager!");
413     return *SourceMgr;
414   }
415   
416   void resetAndLeakSourceManager() {
417     BuryPointer(SourceMgr.get());
418     SourceMgr.resetWithoutRelease();
419   }
420
421   /// setSourceManager - Replace the current source manager.
422   void setSourceManager(SourceManager *Value);
423
424   /// }
425   /// @name Preprocessor
426   /// {
427
428   bool hasPreprocessor() const { return PP != nullptr; }
429
430   /// Return the current preprocessor.
431   Preprocessor &getPreprocessor() const {
432     assert(PP && "Compiler instance has no preprocessor!");
433     return *PP;
434   }
435
436   void resetAndLeakPreprocessor() {
437     BuryPointer(PP.get());
438     PP.resetWithoutRelease();
439   }
440
441   /// Replace the current preprocessor.
442   void setPreprocessor(Preprocessor *Value);
443
444   /// }
445   /// @name ASTContext
446   /// {
447
448   bool hasASTContext() const { return Context != nullptr; }
449
450   ASTContext &getASTContext() const {
451     assert(Context && "Compiler instance has no AST context!");
452     return *Context;
453   }
454   
455   void resetAndLeakASTContext() {
456     BuryPointer(Context.get());
457     Context.resetWithoutRelease();
458   }
459
460   /// setASTContext - Replace the current AST context.
461   void setASTContext(ASTContext *Value);
462
463   /// \brief Replace the current Sema; the compiler instance takes ownership
464   /// of S.
465   void setSema(Sema *S);
466   
467   /// }
468   /// @name ASTConsumer
469   /// {
470
471   bool hasASTConsumer() const { return (bool)Consumer; }
472
473   ASTConsumer &getASTConsumer() const {
474     assert(Consumer && "Compiler instance has no AST consumer!");
475     return *Consumer;
476   }
477
478   /// takeASTConsumer - Remove the current AST consumer and give ownership to
479   /// the caller.
480   std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
481
482   /// setASTConsumer - Replace the current AST consumer; the compiler instance
483   /// takes ownership of \p Value.
484   void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
485
486   /// }
487   /// @name Semantic analysis
488   /// {
489   bool hasSema() const { return (bool)TheSema; }
490
491   Sema &getSema() const { 
492     assert(TheSema && "Compiler instance has no Sema object!");
493     return *TheSema;
494   }
495
496   std::unique_ptr<Sema> takeSema();
497   void resetAndLeakSema();
498
499   /// }
500   /// @name Module Management
501   /// {
502
503   IntrusiveRefCntPtr<ASTReader> getModuleManager() const;
504   void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader);
505
506   std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
507   void setModuleDepCollector(
508       std::shared_ptr<ModuleDependencyCollector> Collector);
509
510   std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
511     return ThePCHContainerOperations;
512   }
513
514   /// Return the appropriate PCHContainerWriter depending on the
515   /// current CodeGenOptions.
516   const PCHContainerWriter &getPCHContainerWriter() const {
517     assert(Invocation && "cannot determine module format without invocation");
518     StringRef Format = getHeaderSearchOpts().ModuleFormat;
519     auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
520     if (!Writer) {
521       if (Diagnostics)
522         Diagnostics->Report(diag::err_module_format_unhandled) << Format;
523       llvm::report_fatal_error("unknown module format");
524     }
525     return *Writer;
526   }
527
528   /// Return the appropriate PCHContainerReader depending on the
529   /// current CodeGenOptions.
530   const PCHContainerReader &getPCHContainerReader() const {
531     assert(Invocation && "cannot determine module format without invocation");
532     StringRef Format = getHeaderSearchOpts().ModuleFormat;
533     auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
534     if (!Reader) {
535       if (Diagnostics)
536         Diagnostics->Report(diag::err_module_format_unhandled) << Format;
537       llvm::report_fatal_error("unknown module format");
538     }
539     return *Reader;
540   }
541
542   /// }
543   /// @name Code Completion
544   /// {
545
546   bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
547
548   CodeCompleteConsumer &getCodeCompletionConsumer() const {
549     assert(CompletionConsumer &&
550            "Compiler instance has no code completion consumer!");
551     return *CompletionConsumer;
552   }
553
554   /// setCodeCompletionConsumer - Replace the current code completion consumer;
555   /// the compiler instance takes ownership of \p Value.
556   void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
557
558   /// }
559   /// @name Frontend timer
560   /// {
561
562   bool hasFrontendTimer() const { return (bool)FrontendTimer; }
563
564   llvm::Timer &getFrontendTimer() const {
565     assert(FrontendTimer && "Compiler instance has no frontend timer!");
566     return *FrontendTimer;
567   }
568
569   /// }
570   /// @name Output Files
571   /// {
572
573   /// addOutputFile - Add an output file onto the list of tracked output files.
574   ///
575   /// \param OutFile - The output file info.
576   void addOutputFile(OutputFile &&OutFile);
577
578   /// clearOutputFiles - Clear the output file list. The underlying output
579   /// streams must have been closed beforehand.
580   ///
581   /// \param EraseFiles - If true, attempt to erase the files from disk.
582   void clearOutputFiles(bool EraseFiles);
583
584   /// }
585   /// @name Construction Utility Methods
586   /// {
587
588   /// Create the diagnostics engine using the invocation's diagnostic options
589   /// and replace any existing one with it.
590   ///
591   /// Note that this routine also replaces the diagnostic client,
592   /// allocating one if one is not provided.
593   ///
594   /// \param Client If non-NULL, a diagnostic client that will be
595   /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
596   /// unit.
597   ///
598   /// \param ShouldOwnClient If Client is non-NULL, specifies whether 
599   /// the diagnostic object should take ownership of the client.
600   void createDiagnostics(DiagnosticConsumer *Client = nullptr,
601                          bool ShouldOwnClient = true);
602
603   /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
604   ///
605   /// If no diagnostic client is provided, this creates a
606   /// DiagnosticConsumer that is owned by the returned diagnostic
607   /// object, if using directly the caller is responsible for
608   /// releasing the returned DiagnosticsEngine's client eventually.
609   ///
610   /// \param Opts - The diagnostic options; note that the created text
611   /// diagnostic object contains a reference to these options.
612   ///
613   /// \param Client If non-NULL, a diagnostic client that will be
614   /// attached to (and, then, owned by) the returned DiagnosticsEngine
615   /// object.
616   ///
617   /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
618   /// used by some diagnostics printers (for logging purposes only).
619   ///
620   /// \return The new object on success, or null on failure.
621   static IntrusiveRefCntPtr<DiagnosticsEngine>
622   createDiagnostics(DiagnosticOptions *Opts,
623                     DiagnosticConsumer *Client = nullptr,
624                     bool ShouldOwnClient = true,
625                     const CodeGenOptions *CodeGenOpts = nullptr);
626
627   /// Create the file manager and replace any existing one with it.
628   void createFileManager();
629
630   /// Create the source manager and replace any existing one with it.
631   void createSourceManager(FileManager &FileMgr);
632
633   /// Create the preprocessor, using the invocation, file, and source managers,
634   /// and replace any existing one with it.
635   void createPreprocessor(TranslationUnitKind TUKind);
636
637   std::string getSpecificModuleCachePath();
638
639   /// Create the AST context.
640   void createASTContext();
641
642   /// Create an external AST source to read a PCH file and attach it to the AST
643   /// context.
644   void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation,
645                                   bool AllowPCHWithCompilerErrors,
646                                   void *DeserializationListener,
647                                   bool OwnDeserializationListener);
648
649   /// Create an external AST source to read a PCH file.
650   ///
651   /// \return - The new object on success, or null on failure.
652   static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource(
653       StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
654       bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
655       const PCHContainerReader &PCHContainerRdr,
656       ArrayRef<IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
657       void *DeserializationListener, bool OwnDeserializationListener,
658       bool Preamble, bool UseGlobalModuleIndex);
659
660   /// Create a code completion consumer using the invocation; note that this
661   /// will cause the source manager to truncate the input source file at the
662   /// completion point.
663   void createCodeCompletionConsumer();
664
665   /// Create a code completion consumer to print code completion results, at
666   /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
667   static CodeCompleteConsumer *createCodeCompletionConsumer(
668       Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
669       const CodeCompleteOptions &Opts, raw_ostream &OS);
670
671   /// \brief Create the Sema object to be used for parsing.
672   void createSema(TranslationUnitKind TUKind,
673                   CodeCompleteConsumer *CompletionConsumer);
674   
675   /// Create the frontend timer and replace any existing one with it.
676   void createFrontendTimer();
677
678   /// Create the default output file (from the invocation's options) and add it
679   /// to the list of tracked output files.
680   ///
681   /// The files created by this function always use temporary files to write to
682   /// their result (that is, the data is written to a temporary file which will
683   /// atomically replace the target output on success).
684   ///
685   /// \return - Null on error.
686   std::unique_ptr<raw_pwrite_stream>
687   createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "",
688                           StringRef Extension = "");
689
690   /// Create a new output file and add it to the list of tracked output files,
691   /// optionally deriving the output path name.
692   ///
693   /// \return - Null on error.
694   std::unique_ptr<raw_pwrite_stream>
695   createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal,
696                    StringRef BaseInput, StringRef Extension, bool UseTemporary,
697                    bool CreateMissingDirectories = false);
698
699   /// Create a new output file, optionally deriving the output path name.
700   ///
701   /// If \p OutputPath is empty, then createOutputFile will derive an output
702   /// path location as \p BaseInput, with any suffix removed, and \p Extension
703   /// appended. If \p OutputPath is not stdout and \p UseTemporary
704   /// is true, createOutputFile will create a new temporary file that must be
705   /// renamed to \p OutputPath in the end.
706   ///
707   /// \param OutputPath - If given, the path to the output file.
708   /// \param Error [out] - On failure, the error.
709   /// \param BaseInput - If \p OutputPath is empty, the input path name to use
710   /// for deriving the output path.
711   /// \param Extension - The extension to use for derived output names.
712   /// \param Binary - The mode to open the file in.
713   /// \param RemoveFileOnSignal - Whether the file should be registered with
714   /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
715   /// multithreaded use, as the underlying signal mechanism is not reentrant
716   /// \param UseTemporary - Create a new temporary file that must be renamed to
717   /// OutputPath in the end.
718   /// \param CreateMissingDirectories - When \p UseTemporary is true, create
719   /// missing directories in the output path.
720   /// \param ResultPathName [out] - If given, the result path name will be
721   /// stored here on success.
722   /// \param TempPathName [out] - If given, the temporary file path name
723   /// will be stored here on success.
724   std::unique_ptr<raw_pwrite_stream>
725   createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary,
726                    bool RemoveFileOnSignal, StringRef BaseInput,
727                    StringRef Extension, bool UseTemporary,
728                    bool CreateMissingDirectories, std::string *ResultPathName,
729                    std::string *TempPathName);
730
731   std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
732
733   /// }
734   /// @name Initialization Utility Methods
735   /// {
736
737   /// InitializeSourceManager - Initialize the source manager to set InputFile
738   /// as the main file.
739   ///
740   /// \return True on success.
741   bool InitializeSourceManager(const FrontendInputFile &Input);
742
743   /// InitializeSourceManager - Initialize the source manager to set InputFile
744   /// as the main file.
745   ///
746   /// \return True on success.
747   static bool InitializeSourceManager(const FrontendInputFile &Input,
748                                       DiagnosticsEngine &Diags,
749                                       FileManager &FileMgr,
750                                       SourceManager &SourceMgr,
751                                       HeaderSearch *HS,
752                                       DependencyOutputOptions &DepOpts,
753                                       const FrontendOptions &Opts);
754
755   /// }
756
757   // Create module manager.
758   void createModuleManager();
759
760   bool loadModuleFile(StringRef FileName);
761
762   ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
763                               Module::NameVisibilityKind Visibility,
764                               bool IsInclusionDirective) override;
765
766   void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility,
767                          SourceLocation ImportLoc) override;
768
769   bool hadModuleLoaderFatalFailure() const {
770     return ModuleLoader::HadFatalFailure;
771   }
772
773   GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override;
774
775   bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
776
777   void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
778     DependencyCollectors.push_back(std::move(Listener));
779   }
780
781   void setExternalSemaSource(IntrusiveRefCntPtr<ExternalSemaSource> ESS);
782 };
783
784 } // end namespace clang
785
786 #endif