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