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