10 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 11 #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_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" 40 class CodeCompleteConsumer;
41 class DiagnosticsEngine;
42 class DiagnosticConsumer;
43 class ExternalASTSource;
47 class MemoryBufferCache;
74 std::shared_ptr<CompilerInvocation> Invocation;
98 std::shared_ptr<Preprocessor> PP;
107 std::unique_ptr<ASTConsumer> Consumer;
110 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
113 std::unique_ptr<Sema> TheSema;
116 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
119 std::unique_ptr<llvm::Timer> FrontendTimer;
125 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
128 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
131 std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
133 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
137 llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
141 std::map<std::string, std::string> BuiltModules;
144 bool DeleteBuiltModules =
true;
156 bool BuildGlobalModuleIndex =
false;
159 bool HaveFullGlobalModuleIndex =
false;
162 bool ModuleBuildFailed =
false;
171 std::string TempFilename;
173 OutputFile(std::string filename, std::string tempFilename)
174 :
Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
181 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
184 std::list<OutputFile> OutputFiles;
190 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
191 std::make_shared<PCHContainerOperations>(),
237 assert(Invocation &&
"Compiler instance has no invocation!");
242 void setInvocation(std::shared_ptr<CompilerInvocation>
Value);
245 bool shouldBuildGlobalModuleIndex()
const;
250 BuildGlobalModuleIndex = Build;
258 return Invocation->getAnalyzerOpts();
262 return Invocation->getCodeGenOpts();
265 return Invocation->getCodeGenOpts();
269 return Invocation->getDependencyOutputOpts();
272 return Invocation->getDependencyOutputOpts();
276 return Invocation->getDiagnosticOpts();
279 return Invocation->getDiagnosticOpts();
283 return Invocation->getFileSystemOpts();
286 return Invocation->getFileSystemOpts();
290 return Invocation->getFrontendOpts();
293 return Invocation->getFrontendOpts();
297 return Invocation->getHeaderSearchOpts();
300 return Invocation->getHeaderSearchOpts();
303 return Invocation->getHeaderSearchOptsPtr();
307 return *Invocation->getLangOpts();
310 return *Invocation->getLangOpts();
314 return Invocation->getPreprocessorOpts();
317 return Invocation->getPreprocessorOpts();
321 return Invocation->getPreprocessorOutputOpts();
324 return Invocation->getPreprocessorOutputOpts();
328 return Invocation->getTargetOpts();
331 return Invocation->getTargetOpts();
342 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
350 assert(Diagnostics && Diagnostics->getClient() &&
351 "Compiler instance has no diagnostic client!");
352 return *Diagnostics->getClient();
362 assert(Target &&
"Compiler instance has no target!");
385 assert(hasVirtualFileSystem() &&
386 "Compiler instance has no virtual file system");
387 return *VirtualFileSystem;
395 VirtualFileSystem = std::move(FS);
406 assert(FileMgr &&
"Compiler instance has no file manager!");
412 FileMgr.resetWithoutRelease();
426 assert(SourceMgr &&
"Compiler instance has no source manager!");
432 SourceMgr.resetWithoutRelease();
446 assert(PP &&
"Compiler instance has no preprocessor!");
453 BuryPointer(
new std::shared_ptr<Preprocessor>(PP));
457 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
466 assert(Context &&
"Compiler instance has no AST context!");
472 Context.resetWithoutRelease();
480 void setSema(
Sema *S);
489 assert(Consumer &&
"Compiler instance has no AST consumer!");
499 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
504 bool hasSema()
const {
return (
bool)TheSema; }
507 assert(TheSema &&
"Compiler instance has no Sema object!");
511 std::unique_ptr<Sema> takeSema();
512 void resetAndLeakSema();
521 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector()
const;
522 void setModuleDepCollector(
523 std::shared_ptr<ModuleDependencyCollector> Collector);
526 return ThePCHContainerOperations;
532 assert(Invocation &&
"cannot determine module format without invocation");
533 StringRef Format = getHeaderSearchOpts().ModuleFormat;
534 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
537 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
538 llvm::report_fatal_error(
"unknown module format");
546 assert(Invocation &&
"cannot determine module format without invocation");
547 StringRef Format = getHeaderSearchOpts().ModuleFormat;
548 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
551 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
552 llvm::report_fatal_error(
"unknown module format");
564 assert(CompletionConsumer &&
565 "Compiler instance has no code completion consumer!");
566 return *CompletionConsumer;
580 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
581 return *FrontendTimer;
591 void addOutputFile(OutputFile &&OutFile);
597 void clearOutputFiles(
bool EraseFiles);
616 bool ShouldOwnClient =
true);
639 bool ShouldOwnClient =
true,
654 std::string getSpecificModuleCachePath();
657 void createASTContext();
661 void createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
662 bool AllowPCHWithCompilerErrors,
663 void *DeserializationListener,
664 bool OwnDeserializationListener);
670 StringRef Path, StringRef Sysroot,
bool DisablePCHValidation,
673 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
675 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
676 void *DeserializationListener,
bool OwnDeserializationListener,
677 bool Preamble,
bool UseGlobalModuleIndex);
682 void createCodeCompletionConsumer();
695 void createFrontendTimer();
705 std::unique_ptr<raw_pwrite_stream>
706 createDefaultOutputFile(
bool Binary =
true, StringRef BaseInput =
"",
707 StringRef Extension =
"");
713 std::unique_ptr<raw_pwrite_stream>
714 createOutputFile(StringRef OutputPath,
bool Binary,
bool RemoveFileOnSignal,
715 StringRef BaseInput, StringRef Extension,
bool UseTemporary,
716 bool CreateMissingDirectories =
false);
743 std::unique_ptr<raw_pwrite_stream>
744 createOutputFile(StringRef OutputPath, std::error_code &Error,
bool Binary,
745 bool RemoveFileOnSignal, StringRef BaseInput,
746 StringRef Extension,
bool UseTemporary,
747 bool CreateMissingDirectories, std::string *ResultPathName,
748 std::string *TempPathName);
750 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
777 void createModuleManager();
779 bool loadModuleFile(StringRef FileName);
783 bool IsInclusionDirective)
override;
785 void loadModuleFromSource(
SourceLocation ImportLoc, StringRef ModuleName,
786 StringRef Source)
override;
792 return ModuleLoader::HadFatalFailure;
797 bool lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc)
override;
800 DependencyCollectors.push_back(std::move(Listener));
LangOptions & getLangOpts()
void resetAndLeakFileManager()
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
Implements support for file system lookup, file system caching, and directory search management...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
const TargetOptions & getTargetOpts() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
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
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.
Manage memory buffers across multiple users.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
DependencyOutputOptions & getDependencyOutputOpts()
const FileSystemOptions & getFileSystemOpts() const
const DependencyOutputOptions & getDependencyOutputOpts() const
The virtual file system interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
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...
Describes a module or submodule.
MemoryBufferCache & getPCMCache() const
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.
PreprocessorOutputOptions & getPreprocessorOutputOpts()
bool hasFrontendTimer() const
Concrete class used by the front-end to report problems and issues.
ASTConsumer & getASTConsumer() const
Defines the Diagnostic-related interfaces.
bool hasASTConsumer() const
HeaderSearchOptions & getHeaderSearchOpts()
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
Builds a depdenency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
AnalyzerOptionsRef getAnalyzerOpts()
CodeCompleteConsumer & getCodeCompletionConsumer() const
Sema - This implements semantic analysis and AST building for C.
void setVirtualFileSystem(IntrusiveRefCntPtr< vfs::FileSystem > FS)
Replace the current virtual file system.
Describes the result of attempting to load a module.
void resetAndLeakPreprocessor()
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
Exposes information about the current target.
void addDependencyCollector(std::shared_ptr< DependencyCollector > Listener)
const AnnotatedLine * Line
bool hasFileManager() const
TargetInfo * getAuxTarget() const
const CodeGenOptions & getCodeGenOpts() const
FileSystemOptions & getFileSystemOpts()
bool hasPreprocessor() const
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
void resetAndLeakSourceManager()
Options for controlling the compiler diagnostics engine.
bool hasVirtualFileSystem() const
bool hasSourceManager() const
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
bool hasInvocation() const
vfs::FileSystem & getVirtualFileSystem() 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.
void BuryPointer(const void *Ptr)
bool hasDiagnostics() const
TargetInfo & getTarget() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
const LangOptions & getLangOpts() const
bool hasASTContext() 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
void resetAndLeakASTContext()
TranslationUnitKind
Describes the kind of translation unit being processed.
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.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
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.