10 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
11 #define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_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"
40 class CodeCompleteConsumer;
41 class DiagnosticsEngine;
42 class DiagnosticConsumer;
43 class ExternalASTSource;
97 std::unique_ptr<ASTConsumer> Consumer;
100 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
103 std::unique_ptr<Sema> TheSema;
106 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
109 std::unique_ptr<llvm::Timer> FrontendTimer;
115 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
118 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
121 std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
123 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
127 llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
130 llvm::StringMap<std::string> ModuleFileOverrides;
134 llvm::StringSet<> ExplicitlyLoadedModuleFiles;
146 bool BuildGlobalModuleIndex;
149 bool HaveFullGlobalModuleIndex;
152 bool ModuleBuildFailed;
160 std::string Filename;
161 std::string TempFilename;
162 std::unique_ptr<raw_ostream> OS;
164 OutputFile(std::string filename, std::string tempFilename,
165 std::unique_ptr<raw_ostream> OS)
166 : Filename(std::move(filename)), TempFilename(std::move(tempFilename)),
168 OutputFile(OutputFile &&O)
169 : Filename(std::move(O.Filename)),
170 TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {}
176 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
179 std::list<OutputFile> OutputFiles;
185 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
186 std::make_shared<PCHContainerOperations>(),
187 bool BuildingModule =
false);
232 assert(Invocation &&
"Compiler instance has no invocation!");
245 BuildGlobalModuleIndex = Build;
253 return Invocation->getAnalyzerOpts();
257 return Invocation->getCodeGenOpts();
260 return Invocation->getCodeGenOpts();
264 return Invocation->getDependencyOutputOpts();
267 return Invocation->getDependencyOutputOpts();
271 return Invocation->getDiagnosticOpts();
274 return Invocation->getDiagnosticOpts();
278 return Invocation->getFileSystemOpts();
281 return Invocation->getFileSystemOpts();
285 return Invocation->getFrontendOpts();
288 return Invocation->getFrontendOpts();
292 return Invocation->getHeaderSearchOpts();
295 return Invocation->getHeaderSearchOpts();
299 return *Invocation->getLangOpts();
302 return *Invocation->getLangOpts();
306 return Invocation->getPreprocessorOpts();
309 return Invocation->getPreprocessorOpts();
313 return Invocation->getPreprocessorOutputOpts();
316 return Invocation->getPreprocessorOutputOpts();
320 return Invocation->getTargetOpts();
323 return Invocation->getTargetOpts();
334 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
342 assert(Diagnostics && Diagnostics->getClient() &&
343 "Compiler instance has no diagnostic client!");
344 return *Diagnostics->getClient();
354 assert(Target &&
"Compiler instance has no target!");
369 "Compiler instance has no virtual file system");
370 return *VirtualFileSystem;
378 VirtualFileSystem = FS;
389 assert(FileMgr &&
"Compiler instance has no file manager!");
395 FileMgr.resetWithoutRelease();
409 assert(SourceMgr &&
"Compiler instance has no source manager!");
415 SourceMgr.resetWithoutRelease();
429 assert(PP &&
"Compiler instance has no preprocessor!");
435 PP.resetWithoutRelease();
448 assert(Context &&
"Compiler instance has no AST context!");
454 Context.resetWithoutRelease();
471 assert(Consumer &&
"Compiler instance has no AST consumer!");
486 bool hasSema()
const {
return (
bool)TheSema; }
489 assert(TheSema &&
"Compiler instance has no Sema object!");
505 std::shared_ptr<ModuleDependencyCollector> Collector);
508 return ThePCHContainerOperations;
514 assert(Invocation &&
"cannot determine module format without invocation");
516 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
519 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
520 llvm::report_fatal_error(
"unknown module format");
528 assert(Invocation &&
"cannot determine module format without invocation");
530 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
533 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
534 llvm::report_fatal_error(
"unknown module format");
546 assert(CompletionConsumer &&
547 "Compiler instance has no code completion consumer!");
548 return *CompletionConsumer;
562 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
563 return *FrontendTimer;
598 bool ShouldOwnClient =
true);
621 bool ShouldOwnClient =
true,
642 bool AllowPCHWithCompilerErrors,
643 void *DeserializationListener,
644 bool OwnDeserializationListener);
650 StringRef Path, StringRef Sysroot,
bool DisablePCHValidation,
653 void *DeserializationListener,
bool OwnDeserializationListener,
654 bool Preamble,
bool UseGlobalModuleIndex);
683 StringRef BaseInput =
"",
684 StringRef Extension =
"");
691 bool RemoveFileOnSignal,
692 StringRef BaseInput, StringRef Extension,
694 bool CreateMissingDirectories =
false);
721 std::unique_ptr<raw_pwrite_stream>
723 bool RemoveFileOnSignal, StringRef BaseInput,
724 StringRef Extension,
bool UseTemporary,
725 bool CreateMissingDirectories, std::string *ResultPathName,
726 std::string *TempPathName);
759 bool IsInclusionDirective)
override;
773 DependencyCollectors.push_back(std::move(Listener));
LangOptions & getLangOpts()
void resetAndLeakFileManager()
bool hasFileManager() const
ASTContext & getASTContext() const
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
void createCodeCompletionConsumer()
bool hasASTConsumer() const
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...
void setCodeCompletionConsumer(CodeCompleteConsumer *Value)
vfs::FileSystem & getVirtualFileSystem() const
void createDiagnostics(DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)
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)
bool hasInvocation() const
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.
const DependencyOutputOptions & getDependencyOutputOpts() const
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
DependencyOutputOptions & getDependencyOutputOpts()
const HeaderSearchOptions & getHeaderSearchOpts() const
The virtual file system interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
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...
ASTConsumer & getASTConsumer() const
Describes a module or submodule.
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.
FrontendOptions & getFrontendOpts()
Visibility
Describes the different kinds of visibility that a declaration may have.
DiagnosticConsumer & getDiagnosticClient() const
PreprocessorOutputOptions & getPreprocessorOutputOpts()
Concrete class used by the front-end to report problems and issues.
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
IntrusiveRefCntPtr< ASTReader > getModuleManager() const
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
HeaderSearchOptions & getHeaderSearchOpts()
Preprocessor & getPreprocessor() const
Return the current preprocessor.
AnalyzerOptionsRef getAnalyzerOpts()
void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
bool hasVirtualFileSystem() const
Sema - This implements semantic analysis and AST building for C.
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.
void resetAndLeakPreprocessor()
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.
std::string getSpecificModuleCachePath()
bool hasDiagnostics() const
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.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
void addOutputFile(OutputFile &&OutFile)
bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
std::unique_ptr< Sema > takeSema()
Options controlling the behavior of code completion.
bool hasSourceManager() const
FileSystemOptions & getFileSystemOpts()
bool ExecuteAction(FrontendAction &Act)
const TargetOptions & getTargetOpts() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const PCHContainerReader & getPCHContainerReader() const
void resetAndLeakSourceManager()
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
Options for controlling the compiler diagnostics engine.
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
void createPreprocessor(TranslationUnitKind TUKind)
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.
bool hasFrontendTimer() const
llvm::raw_null_ostream * createNullOutputFile()
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.
Defines the Diagnostic-related interfaces.
void clearOutputFiles(bool EraseFiles)
void BuryPointer(const void *Ptr)
CodeCompleteConsumer & getCodeCompletionConsumer() const
bool hasASTContext() const
void setTarget(TargetInfo *Value)
Replace the current diagnostics engine.
Keeps track of options that affect how file operations are performed.
const PCHContainerWriter & getPCHContainerWriter() const
raw_pwrite_stream * createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
~CompilerInstance() override
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
void resetAndLeakASTContext()
llvm::Timer & getFrontendTimer() const
std::shared_ptr< ModuleDependencyCollector > getModuleDepCollector() const
TranslationUnitKind
Describes the kind of translation unit being processed.
const FileSystemOptions & getFileSystemOpts() const
NameVisibilityKind
Describes the visibility of the various names within a particular module.
const CodeGenOptions & getCodeGenOpts() const
bool hasPreprocessor() const
std::unique_ptr< ASTConsumer > takeASTConsumer()
ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override
Attempt to load the given module.
void createModuleManager()
}
void setModuleDepCollector(std::shared_ptr< ModuleDependencyCollector > Collector)
GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc) override
Load, create, or return global module. This function returns an existing global module index...
raw_pwrite_stream * createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, StringRef BaseInput, StringRef Extension, bool UseTemporary, bool CreateMissingDirectories=false)
TargetOptions & getTargetOpts()
This class handles loading and caching of source files into memory.
void setDiagnostics(DiagnosticsEngine *Value)
setDiagnostics - Replace the current diagnostics engine.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.