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;
100 std::unique_ptr<ASTConsumer> Consumer;
103 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
106 std::unique_ptr<Sema> TheSema;
109 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
112 std::unique_ptr<llvm::Timer> FrontendTimer;
118 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
121 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
124 std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
126 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
130 llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
142 bool BuildGlobalModuleIndex;
145 bool HaveFullGlobalModuleIndex;
148 bool ModuleBuildFailed;
157 std::string TempFilename;
159 OutputFile(std::string filename, std::string tempFilename)
160 :
Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
167 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
170 std::list<OutputFile> OutputFiles;
176 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
177 std::make_shared<PCHContainerOperations>(),
178 bool BuildingModule =
false);
223 assert(Invocation &&
"Compiler instance has no invocation!");
236 BuildGlobalModuleIndex = Build;
244 return Invocation->getAnalyzerOpts();
248 return Invocation->getCodeGenOpts();
251 return Invocation->getCodeGenOpts();
255 return Invocation->getDependencyOutputOpts();
258 return Invocation->getDependencyOutputOpts();
262 return Invocation->getDiagnosticOpts();
265 return Invocation->getDiagnosticOpts();
269 return Invocation->getFileSystemOpts();
272 return Invocation->getFileSystemOpts();
276 return Invocation->getFrontendOpts();
279 return Invocation->getFrontendOpts();
283 return Invocation->getHeaderSearchOpts();
286 return Invocation->getHeaderSearchOpts();
290 return *Invocation->getLangOpts();
293 return *Invocation->getLangOpts();
297 return Invocation->getPreprocessorOpts();
300 return Invocation->getPreprocessorOpts();
304 return Invocation->getPreprocessorOutputOpts();
307 return Invocation->getPreprocessorOutputOpts();
311 return Invocation->getTargetOpts();
314 return Invocation->getTargetOpts();
325 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
333 assert(Diagnostics && Diagnostics->getClient() &&
334 "Compiler instance has no diagnostic client!");
335 return *Diagnostics->getClient();
345 assert(Target &&
"Compiler instance has no target!");
369 "Compiler instance has no virtual file system");
370 return *VirtualFileSystem;
378 VirtualFileSystem = std::move(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,
654 void *DeserializationListener,
bool OwnDeserializationListener,
655 bool Preamble,
bool UseGlobalModuleIndex);
683 std::unique_ptr<raw_pwrite_stream>
685 StringRef Extension =
"");
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);
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);
761 bool IsInclusionDirective)
override;
775 DependencyCollectors.push_back(std::move(Listener));
LangOptions & getLangOpts()
void resetAndLeakFileManager()
bool hasFileManager() const
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 ...
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...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
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.
bool hasInvocation() const
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.
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.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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.
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.
DiagnosticConsumer & getDiagnosticClient() const
PreprocessorOutputOptions & getPreprocessorOutputOpts()
Concrete class used by the front-end to report problems and issues.
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
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()
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.
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)
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()
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.
void resetAndLeakSourceManager()
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
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.
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
bool hasASTContext() 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.
~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()
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 createModuleManager()
}
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.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.