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;
187 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
193 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
194 std::make_shared<PCHContainerOperations>(),
240 assert(Invocation &&
"Compiler instance has no invocation!");
245 void setInvocation(std::shared_ptr<CompilerInvocation>
Value);
248 bool shouldBuildGlobalModuleIndex()
const;
253 BuildGlobalModuleIndex = Build;
261 return Invocation->getAnalyzerOpts();
265 return Invocation->getCodeGenOpts();
268 return Invocation->getCodeGenOpts();
272 return Invocation->getDependencyOutputOpts();
275 return Invocation->getDependencyOutputOpts();
279 return Invocation->getDiagnosticOpts();
282 return Invocation->getDiagnosticOpts();
286 return Invocation->getFileSystemOpts();
289 return Invocation->getFileSystemOpts();
293 return Invocation->getFrontendOpts();
296 return Invocation->getFrontendOpts();
300 return Invocation->getHeaderSearchOpts();
303 return Invocation->getHeaderSearchOpts();
306 return Invocation->getHeaderSearchOptsPtr();
310 return *Invocation->getLangOpts();
313 return *Invocation->getLangOpts();
317 return Invocation->getPreprocessorOpts();
320 return Invocation->getPreprocessorOpts();
324 return Invocation->getPreprocessorOutputOpts();
327 return Invocation->getPreprocessorOutputOpts();
331 return Invocation->getTargetOpts();
334 return Invocation->getTargetOpts();
345 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
353 assert(Diagnostics && Diagnostics->getClient() &&
354 "Compiler instance has no diagnostic client!");
355 return *Diagnostics->getClient();
365 assert(Target &&
"Compiler instance has no target!");
388 assert(hasVirtualFileSystem() &&
389 "Compiler instance has no virtual file system");
390 return *VirtualFileSystem;
398 VirtualFileSystem = std::move(FS);
409 assert(FileMgr &&
"Compiler instance has no file manager!");
415 FileMgr.resetWithoutRelease();
429 assert(SourceMgr &&
"Compiler instance has no source manager!");
435 SourceMgr.resetWithoutRelease();
449 assert(PP &&
"Compiler instance has no preprocessor!");
456 BuryPointer(
new std::shared_ptr<Preprocessor>(PP));
460 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
469 assert(Context &&
"Compiler instance has no AST context!");
475 Context.resetWithoutRelease();
483 void setSema(
Sema *S);
492 assert(Consumer &&
"Compiler instance has no AST consumer!");
502 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
507 bool hasSema()
const {
return (
bool)TheSema; }
510 assert(TheSema &&
"Compiler instance has no Sema object!");
514 std::unique_ptr<Sema> takeSema();
515 void resetAndLeakSema();
524 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector()
const;
525 void setModuleDepCollector(
526 std::shared_ptr<ModuleDependencyCollector> Collector);
529 return ThePCHContainerOperations;
535 assert(Invocation &&
"cannot determine module format without invocation");
536 StringRef Format = getHeaderSearchOpts().ModuleFormat;
537 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
540 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
541 llvm::report_fatal_error(
"unknown module format");
549 assert(Invocation &&
"cannot determine module format without invocation");
550 StringRef Format = getHeaderSearchOpts().ModuleFormat;
551 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
554 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
555 llvm::report_fatal_error(
"unknown module format");
567 assert(CompletionConsumer &&
568 "Compiler instance has no code completion consumer!");
569 return *CompletionConsumer;
583 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
584 return *FrontendTimer;
594 void addOutputFile(OutputFile &&OutFile);
600 void clearOutputFiles(
bool EraseFiles);
619 bool ShouldOwnClient =
true);
642 bool ShouldOwnClient =
true,
657 std::string getSpecificModuleCachePath();
660 void createASTContext();
664 void createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
665 bool AllowPCHWithCompilerErrors,
666 void *DeserializationListener,
667 bool OwnDeserializationListener);
673 StringRef Path, StringRef Sysroot,
bool DisablePCHValidation,
676 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
678 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
679 void *DeserializationListener,
bool OwnDeserializationListener,
680 bool Preamble,
bool UseGlobalModuleIndex);
685 void createCodeCompletionConsumer();
698 void createFrontendTimer();
708 std::unique_ptr<raw_pwrite_stream>
709 createDefaultOutputFile(
bool Binary =
true, StringRef BaseInput =
"",
710 StringRef Extension =
"");
716 std::unique_ptr<raw_pwrite_stream>
717 createOutputFile(StringRef OutputPath,
bool Binary,
bool RemoveFileOnSignal,
718 StringRef BaseInput, StringRef Extension,
bool UseTemporary,
719 bool CreateMissingDirectories =
false);
746 std::unique_ptr<raw_pwrite_stream>
747 createOutputFile(StringRef OutputPath, std::error_code &Error,
bool Binary,
748 bool RemoveFileOnSignal, StringRef BaseInput,
749 StringRef Extension,
bool UseTemporary,
750 bool CreateMissingDirectories, std::string *ResultPathName,
751 std::string *TempPathName);
753 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
780 OutputStream = std::move(OutStream);
784 return std::move(OutputStream);
788 void createModuleManager();
790 bool loadModuleFile(StringRef FileName);
794 bool IsInclusionDirective)
override;
796 void loadModuleFromSource(
SourceLocation ImportLoc, StringRef ModuleName,
797 StringRef Source)
override;
803 return ModuleLoader::HadFatalFailure;
808 bool lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc)
override;
811 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
void setOutputStream(std::unique_ptr< llvm::raw_pwrite_stream > OutStream)
}
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()
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
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.