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