clang  10.0.0svn
CompilerInstance.h
Go to the documentation of this file.
1 //===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
10 #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
11 
12 #include "clang/AST/ASTConsumer.h"
13 #include "clang/Basic/Diagnostic.h"
17 #include "clang/Frontend/Utils.h"
19 #include "clang/Lex/ModuleLoader.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/BuryPointer.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 InMemoryModuleCache;
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.
73  /// The options used in this compiler instance.
74  std::shared_ptr<CompilerInvocation> Invocation;
75 
76  /// The diagnostics engine instance.
78 
79  /// The target being compiled for.
81 
82  /// Auxiliary Target info.
84 
85  /// The file manager.
87 
88  /// The source manager.
90 
91  /// The cache of PCM files.
93 
94  /// The preprocessor.
95  std::shared_ptr<Preprocessor> PP;
96 
97  /// The AST context.
99 
100  /// An optional sema source that will be attached to sema.
102 
103  /// The AST consumer.
104  std::unique_ptr<ASTConsumer> Consumer;
105 
106  /// The code completion consumer.
107  std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
108 
109  /// The semantic analysis object.
110  std::unique_ptr<Sema> TheSema;
111 
112  /// The frontend timer group.
113  std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
114 
115  /// The frontend timer.
116  std::unique_ptr<llvm::Timer> FrontendTimer;
117 
118  /// The ASTReader, if one exists.
119  IntrusiveRefCntPtr<ASTReader> ModuleManager;
120 
121  /// The module dependency collector for crashdumps
122  std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
123 
124  /// The module provider.
125  std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
126 
127  std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
128 
129  /// The set of top-level modules that has already been loaded,
130  /// along with the module map
131  llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
132 
133  /// The set of top-level modules that has already been built on the
134  /// fly as part of this overall compilation action.
135  std::map<std::string, std::string> BuiltModules;
136 
137  /// Should we delete the BuiltModules when we're done?
138  bool DeleteBuiltModules = true;
139 
140  /// The location of the module-import keyword for the last module
141  /// import.
142  SourceLocation LastModuleImportLoc;
143 
144  /// The result of the last module import.
145  ///
146  ModuleLoadResult LastModuleImportResult;
147 
148  /// Whether we should (re)build the global module index once we
149  /// have finished with this translation unit.
150  bool BuildGlobalModuleIndex = false;
151 
152  /// We have a full global module index, with all modules.
153  bool HaveFullGlobalModuleIndex = false;
154 
155  /// One or more modules failed to build.
156  bool ModuleBuildFailed = false;
157 
158  /// The stream for verbose output if owned, otherwise nullptr.
159  std::unique_ptr<raw_ostream> OwnedVerboseOutputStream;
160 
161  /// The stream for verbose output.
162  raw_ostream *VerboseOutputStream = &llvm::errs();
163 
164  /// Holds information about the output file.
165  ///
166  /// If TempFilename is not empty we must rename it to Filename at the end.
167  /// TempFilename may be empty and Filename non-empty if creating the temporary
168  /// failed.
169  struct OutputFile {
170  std::string Filename;
171  std::string TempFilename;
172 
173  OutputFile(std::string filename, std::string tempFilename)
174  : Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
175  }
176  };
177 
178  /// If the output doesn't support seeking (terminal, pipe). we switch
179  /// the stream to a buffer_ostream. These are the buffer and the original
180  /// stream.
181  std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
182 
183  /// The list of active output files.
184  std::list<OutputFile> OutputFiles;
185 
186  /// Force an output buffer.
187  std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
188 
189  CompilerInstance(const CompilerInstance &) = delete;
190  void operator=(const CompilerInstance &) = delete;
191 public:
192  explicit CompilerInstance(
193  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
194  std::make_shared<PCHContainerOperations>(),
195  InMemoryModuleCache *SharedModuleCache = nullptr);
196  ~CompilerInstance() override;
197 
198  /// @name High-Level Operations
199  /// {
200 
201  /// ExecuteAction - Execute the provided action against the compiler's
202  /// CompilerInvocation object.
203  ///
204  /// This function makes the following assumptions:
205  ///
206  /// - The invocation options should be initialized. This function does not
207  /// handle the '-help' or '-version' options, clients should handle those
208  /// directly.
209  ///
210  /// - The diagnostics engine should have already been created by the client.
211  ///
212  /// - No other CompilerInstance state should have been initialized (this is
213  /// an unchecked error).
214  ///
215  /// - Clients should have initialized any LLVM target features that may be
216  /// required.
217  ///
218  /// - Clients should eventually call llvm_shutdown() upon the completion of
219  /// this routine to ensure that any managed objects are properly destroyed.
220  ///
221  /// Note that this routine may write output to 'stderr'.
222  ///
223  /// \param Act - The action to execute.
224  /// \return - True on success.
225  //
226  // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
227  // of the context or else not CompilerInstance specific.
228  bool ExecuteAction(FrontendAction &Act);
229 
230  /// }
231  /// @name Compiler Invocation and Options
232  /// {
233 
234  bool hasInvocation() const { return Invocation != nullptr; }
235 
237  assert(Invocation && "Compiler instance has no invocation!");
238  return *Invocation;
239  }
240 
241  /// setInvocation - Replace the current invocation.
242  void setInvocation(std::shared_ptr<CompilerInvocation> Value);
243 
244  /// Indicates whether we should (re)build the global module index.
245  bool shouldBuildGlobalModuleIndex() const;
246 
247  /// Set the flag indicating whether we should (re)build the global
248  /// module index.
249  void setBuildGlobalModuleIndex(bool Build) {
250  BuildGlobalModuleIndex = Build;
251  }
252 
253  /// }
254  /// @name Forwarding Methods
255  /// {
256 
258  return Invocation->getAnalyzerOpts();
259  }
260 
262  return Invocation->getCodeGenOpts();
263  }
265  return Invocation->getCodeGenOpts();
266  }
267 
269  return Invocation->getDependencyOutputOpts();
270  }
272  return Invocation->getDependencyOutputOpts();
273  }
274 
276  return Invocation->getDiagnosticOpts();
277  }
279  return Invocation->getDiagnosticOpts();
280  }
281 
283  return Invocation->getFileSystemOpts();
284  }
286  return Invocation->getFileSystemOpts();
287  }
288 
290  return Invocation->getFrontendOpts();
291  }
293  return Invocation->getFrontendOpts();
294  }
295 
297  return Invocation->getHeaderSearchOpts();
298  }
300  return Invocation->getHeaderSearchOpts();
301  }
302  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
303  return Invocation->getHeaderSearchOptsPtr();
304  }
305 
307  return *Invocation->getLangOpts();
308  }
309  const LangOptions &getLangOpts() const {
310  return *Invocation->getLangOpts();
311  }
312 
314  return Invocation->getPreprocessorOpts();
315  }
317  return Invocation->getPreprocessorOpts();
318  }
319 
321  return Invocation->getPreprocessorOutputOpts();
322  }
324  return Invocation->getPreprocessorOutputOpts();
325  }
326 
328  return Invocation->getTargetOpts();
329  }
330  const TargetOptions &getTargetOpts() const {
331  return Invocation->getTargetOpts();
332  }
333 
334  /// }
335  /// @name Diagnostics Engine
336  /// {
337 
338  bool hasDiagnostics() const { return Diagnostics != nullptr; }
339 
340  /// Get the current diagnostics engine.
342  assert(Diagnostics && "Compiler instance has no diagnostics!");
343  return *Diagnostics;
344  }
345 
346  /// setDiagnostics - Replace the current diagnostics engine.
347  void setDiagnostics(DiagnosticsEngine *Value);
348 
350  assert(Diagnostics && Diagnostics->getClient() &&
351  "Compiler instance has no diagnostic client!");
352  return *Diagnostics->getClient();
353  }
354 
355  /// }
356  /// @name VerboseOutputStream
357  /// }
358 
359  /// Replace the current stream for verbose output.
360  void setVerboseOutputStream(raw_ostream &Value);
361 
362  /// Replace the current stream for verbose output.
363  void setVerboseOutputStream(std::unique_ptr<raw_ostream> Value);
364 
365  /// Get the current stream for verbose output.
366  raw_ostream &getVerboseOutputStream() {
367  return *VerboseOutputStream;
368  }
369 
370  /// }
371  /// @name Target Info
372  /// {
373 
374  bool hasTarget() const { return Target != nullptr; }
375 
377  assert(Target && "Compiler instance has no target!");
378  return *Target;
379  }
380 
381  /// Replace the current Target.
382  void setTarget(TargetInfo *Value);
383 
384  /// }
385  /// @name AuxTarget Info
386  /// {
387 
388  TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
389 
390  /// Replace the current AuxTarget.
391  void setAuxTarget(TargetInfo *Value);
392 
393  /// }
394  /// @name Virtual File System
395  /// {
396 
397  llvm::vfs::FileSystem &getVirtualFileSystem() const {
398  return getFileManager().getVirtualFileSystem();
399  }
400 
401  /// }
402  /// @name File Manager
403  /// {
404 
405  bool hasFileManager() const { return FileMgr != nullptr; }
406 
407  /// Return the current file manager to the caller.
409  assert(FileMgr && "Compiler instance has no file manager!");
410  return *FileMgr;
411  }
412 
414  llvm::BuryPointer(FileMgr.get());
415  FileMgr.resetWithoutRelease();
416  }
417 
418  /// Replace the current file manager and virtual file system.
419  void setFileManager(FileManager *Value);
420 
421  /// }
422  /// @name Source Manager
423  /// {
424 
425  bool hasSourceManager() const { return SourceMgr != nullptr; }
426 
427  /// Return the current source manager.
429  assert(SourceMgr && "Compiler instance has no source manager!");
430  return *SourceMgr;
431  }
432 
434  llvm::BuryPointer(SourceMgr.get());
435  SourceMgr.resetWithoutRelease();
436  }
437 
438  /// setSourceManager - Replace the current source manager.
439  void setSourceManager(SourceManager *Value);
440 
441  /// }
442  /// @name Preprocessor
443  /// {
444 
445  bool hasPreprocessor() const { return PP != nullptr; }
446 
447  /// Return the current preprocessor.
449  assert(PP && "Compiler instance has no preprocessor!");
450  return *PP;
451  }
452 
453  std::shared_ptr<Preprocessor> getPreprocessorPtr() { return PP; }
454 
456  llvm::BuryPointer(new std::shared_ptr<Preprocessor>(PP));
457  }
458 
459  /// Replace the current preprocessor.
460  void setPreprocessor(std::shared_ptr<Preprocessor> Value);
461 
462  /// }
463  /// @name ASTContext
464  /// {
465 
466  bool hasASTContext() const { return Context != nullptr; }
467 
469  assert(Context && "Compiler instance has no AST context!");
470  return *Context;
471  }
472 
474  llvm::BuryPointer(Context.get());
475  Context.resetWithoutRelease();
476  }
477 
478  /// setASTContext - Replace the current AST context.
479  void setASTContext(ASTContext *Value);
480 
481  /// Replace the current Sema; the compiler instance takes ownership
482  /// of S.
483  void setSema(Sema *S);
484 
485  /// }
486  /// @name ASTConsumer
487  /// {
488 
489  bool hasASTConsumer() const { return (bool)Consumer; }
490 
492  assert(Consumer && "Compiler instance has no AST consumer!");
493  return *Consumer;
494  }
495 
496  /// takeASTConsumer - Remove the current AST consumer and give ownership to
497  /// the caller.
498  std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
499 
500  /// setASTConsumer - Replace the current AST consumer; the compiler instance
501  /// takes ownership of \p Value.
502  void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
503 
504  /// }
505  /// @name Semantic analysis
506  /// {
507  bool hasSema() const { return (bool)TheSema; }
508 
509  Sema &getSema() const {
510  assert(TheSema && "Compiler instance has no Sema object!");
511  return *TheSema;
512  }
513 
514  std::unique_ptr<Sema> takeSema();
515  void resetAndLeakSema();
516 
517  /// }
518  /// @name Module Management
519  /// {
520 
521  IntrusiveRefCntPtr<ASTReader> getModuleManager() const;
522  void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader);
523 
524  std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
525  void setModuleDepCollector(
526  std::shared_ptr<ModuleDependencyCollector> Collector);
527 
528  std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
529  return ThePCHContainerOperations;
530  }
531 
532  /// Return the appropriate PCHContainerWriter depending on the
533  /// current CodeGenOptions.
535  assert(Invocation && "cannot determine module format without invocation");
536  StringRef Format = getHeaderSearchOpts().ModuleFormat;
537  auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
538  if (!Writer) {
539  if (Diagnostics)
540  Diagnostics->Report(diag::err_module_format_unhandled) << Format;
541  llvm::report_fatal_error("unknown module format");
542  }
543  return *Writer;
544  }
545 
546  /// Return the appropriate PCHContainerReader depending on the
547  /// current CodeGenOptions.
549  assert(Invocation && "cannot determine module format without invocation");
550  StringRef Format = getHeaderSearchOpts().ModuleFormat;
551  auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
552  if (!Reader) {
553  if (Diagnostics)
554  Diagnostics->Report(diag::err_module_format_unhandled) << Format;
555  llvm::report_fatal_error("unknown module format");
556  }
557  return *Reader;
558  }
559 
560  /// }
561  /// @name Code Completion
562  /// {
563 
564  bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
565 
567  assert(CompletionConsumer &&
568  "Compiler instance has no code completion consumer!");
569  return *CompletionConsumer;
570  }
571 
572  /// setCodeCompletionConsumer - Replace the current code completion consumer;
573  /// the compiler instance takes ownership of \p Value.
574  void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
575 
576  /// }
577  /// @name Frontend timer
578  /// {
579 
580  bool hasFrontendTimer() const { return (bool)FrontendTimer; }
581 
582  llvm::Timer &getFrontendTimer() const {
583  assert(FrontendTimer && "Compiler instance has no frontend timer!");
584  return *FrontendTimer;
585  }
586 
587  /// }
588  /// @name Output Files
589  /// {
590 
591  /// addOutputFile - Add an output file onto the list of tracked output files.
592  ///
593  /// \param OutFile - The output file info.
594  void addOutputFile(OutputFile &&OutFile);
595 
596  /// clearOutputFiles - Clear the output file list. The underlying output
597  /// streams must have been closed beforehand.
598  ///
599  /// \param EraseFiles - If true, attempt to erase the files from disk.
600  void clearOutputFiles(bool EraseFiles);
601 
602  /// }
603  /// @name Construction Utility Methods
604  /// {
605 
606  /// Create the diagnostics engine using the invocation's diagnostic options
607  /// and replace any existing one with it.
608  ///
609  /// Note that this routine also replaces the diagnostic client,
610  /// allocating one if one is not provided.
611  ///
612  /// \param Client If non-NULL, a diagnostic client that will be
613  /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
614  /// unit.
615  ///
616  /// \param ShouldOwnClient If Client is non-NULL, specifies whether
617  /// the diagnostic object should take ownership of the client.
618  void createDiagnostics(DiagnosticConsumer *Client = nullptr,
619  bool ShouldOwnClient = true);
620 
621  /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
622  ///
623  /// If no diagnostic client is provided, this creates a
624  /// DiagnosticConsumer that is owned by the returned diagnostic
625  /// object, if using directly the caller is responsible for
626  /// releasing the returned DiagnosticsEngine's client eventually.
627  ///
628  /// \param Opts - The diagnostic options; note that the created text
629  /// diagnostic object contains a reference to these options.
630  ///
631  /// \param Client If non-NULL, a diagnostic client that will be
632  /// attached to (and, then, owned by) the returned DiagnosticsEngine
633  /// object.
634  ///
635  /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
636  /// used by some diagnostics printers (for logging purposes only).
637  ///
638  /// \return The new object on success, or null on failure.
640  createDiagnostics(DiagnosticOptions *Opts,
641  DiagnosticConsumer *Client = nullptr,
642  bool ShouldOwnClient = true,
643  const CodeGenOptions *CodeGenOpts = nullptr);
644 
645  /// Create the file manager and replace any existing one with it.
646  ///
647  /// \return The new file manager on success, or null on failure.
648  FileManager *
649  createFileManager(IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
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,
676  InMemoryModuleCache &ModuleCache, ASTContext &Context,
677  const PCHContainerReader &PCHContainerRdr,
678  ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
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,
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 
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  InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
818 };
819 
820 } // end namespace clang
821 
822 #endif
LangOptions & getLangOpts()
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:171
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
const TargetOptions & getTargetOpts() const
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
Defines the SourceManager interface.
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
Abstract base class for actions which can be performed by the frontend.
DiagnosticOptions & getDiagnosticOpts()
std::shared_ptr< HeaderSearchOptions > getHeaderSearchOptsPtr() const
const HeaderSearchOptions & getHeaderSearchOpts() const
InMemoryModuleCache & getModuleCache() const
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
ASTContext & getASTContext() const
const FrontendOptions & getFrontendOpts() const
Options for controlling the target.
Definition: TargetOptions.h:26
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1489
DependencyOutputOptions & getDependencyOutputOpts()
const FileSystemOptions & getFileSystemOpts() const
const DependencyOutputOptions & getDependencyOutputOpts() const
void setOutputStream(std::unique_ptr< llvm::raw_pwrite_stream > OutStream)
}
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
raw_ostream & getVerboseOutputStream()
Get the current stream for verbose output.
CodeGenOptions & getCodeGenOpts()
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
std::shared_ptr< Preprocessor > getPreprocessorPtr()
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
Describes a module or submodule.
Definition: Module.h:64
const PCHContainerWriter & getPCHContainerWriter() const
Return the appropriate PCHContainerWriter depending on the current CodeGenOptions.
void setBuildGlobalModuleIndex(bool Build)
Set the flag indicating whether we should (re)build the global module index.
This abstract interface provides operations for creating containers for serialized ASTs (precompiled ...
FrontendOptions & getFrontendOpts()
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:33
PreprocessorOutputOptions & getPreprocessorOutputOpts()
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
ASTConsumer & getASTConsumer() const
llvm::Error Error
Defines the Diagnostic-related interfaces.
HeaderSearchOptions & getHeaderSearchOpts()
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
AnalyzerOptionsRef getAnalyzerOpts()
CodeCompleteConsumer & getCodeCompletionConsumer() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:158
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:331
Describes the result of attempting to load a module.
Definition: ModuleLoader.h:35
StringRef Filename
Definition: Format.cpp:1807
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
Exposes information about the current target.
Definition: TargetInfo.h:163
void addDependencyCollector(std::shared_ptr< DependencyCollector > Listener)
const AnnotatedLine * Line
TargetInfo * getAuxTarget() const
const CodeGenOptions & getCodeGenOpts() const
An input file for the front end.
In-memory cache for modules.
FileSystemOptions & getFileSystemOpts()
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
Options for controlling the compiler diagnostics engine.
const DiagnosticOptions & getDiagnosticOpts() const
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
const PreprocessorOptions & getPreprocessorOpts() const
A global index for a set of module files, providing information about the identifiers within those mo...
Abstract interface for a consumer of code-completion information.
Options controlling the behavior of code completion.
Dataflow Directional Tag Classes.
FileManager & getFileManager() const
Return the current file manager to the caller.
llvm::Timer & getFrontendTimer() const
Helper class for holding the data necessary to invoke the compiler.
SourceManager & getSourceManager() const
Return the current source manager.
FrontendOptions - Options for controlling the behavior of the frontend.
Abstract interface for a module loader.
Definition: ModuleLoader.h:73
TargetInfo & getTarget() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
const LangOptions & getLangOpts() const
Keeps track of options that affect how file operations are performed.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
bool hasCodeCompletionConsumer() const
DiagnosticConsumer & getDiagnosticClient() const
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:378
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
bool hadModuleLoaderFatalFailure() const
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:273
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
TargetOptions & getTargetOpts()
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125