9 #ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_ 10 #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" 24 #include "llvm/Support/BuryPointer.h" 40 class CodeCompleteConsumer;
41 class DiagnosticsEngine;
42 class DiagnosticConsumer;
43 class ExternalASTSource;
47 class InMemoryModuleCache;
74 std::shared_ptr<CompilerInvocation> Invocation;
95 std::shared_ptr<Preprocessor> PP;
104 std::unique_ptr<ASTConsumer> Consumer;
107 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
110 std::unique_ptr<Sema> TheSema;
113 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
116 std::unique_ptr<llvm::Timer> FrontendTimer;
122 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
125 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
127 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
131 llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
135 std::map<std::string, std::string> BuiltModules;
138 bool DeleteBuiltModules =
true;
150 bool BuildGlobalModuleIndex =
false;
153 bool HaveFullGlobalModuleIndex =
false;
156 bool ModuleBuildFailed =
false;
165 std::string TempFilename;
167 OutputFile(std::string filename, std::string tempFilename)
168 :
Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
175 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
178 std::list<OutputFile> OutputFiles;
181 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
187 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
188 std::make_shared<PCHContainerOperations>(),
234 assert(Invocation &&
"Compiler instance has no invocation!");
239 void setInvocation(std::shared_ptr<CompilerInvocation>
Value);
242 bool shouldBuildGlobalModuleIndex()
const;
247 BuildGlobalModuleIndex = Build;
255 return Invocation->getAnalyzerOpts();
259 return Invocation->getCodeGenOpts();
262 return Invocation->getCodeGenOpts();
266 return Invocation->getDependencyOutputOpts();
269 return Invocation->getDependencyOutputOpts();
273 return Invocation->getDiagnosticOpts();
276 return Invocation->getDiagnosticOpts();
280 return Invocation->getFileSystemOpts();
283 return Invocation->getFileSystemOpts();
287 return Invocation->getFrontendOpts();
290 return Invocation->getFrontendOpts();
294 return Invocation->getHeaderSearchOpts();
297 return Invocation->getHeaderSearchOpts();
300 return Invocation->getHeaderSearchOptsPtr();
304 return *Invocation->getLangOpts();
307 return *Invocation->getLangOpts();
311 return Invocation->getPreprocessorOpts();
314 return Invocation->getPreprocessorOpts();
318 return Invocation->getPreprocessorOutputOpts();
321 return Invocation->getPreprocessorOutputOpts();
325 return Invocation->getTargetOpts();
328 return Invocation->getTargetOpts();
339 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
347 assert(Diagnostics && Diagnostics->getClient() &&
348 "Compiler instance has no diagnostic client!");
349 return *Diagnostics->getClient();
359 assert(Target &&
"Compiler instance has no target!");
380 return getFileManager().getVirtualFileSystem();
391 assert(FileMgr &&
"Compiler instance has no file manager!");
396 llvm::BuryPointer(FileMgr.get());
397 FileMgr.resetWithoutRelease();
411 assert(SourceMgr &&
"Compiler instance has no source manager!");
416 llvm::BuryPointer(SourceMgr.get());
417 SourceMgr.resetWithoutRelease();
431 assert(PP &&
"Compiler instance has no preprocessor!");
438 llvm::BuryPointer(
new std::shared_ptr<Preprocessor>(PP));
442 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
451 assert(Context &&
"Compiler instance has no AST context!");
456 llvm::BuryPointer(Context.get());
457 Context.resetWithoutRelease();
465 void setSema(
Sema *S);
474 assert(Consumer &&
"Compiler instance has no AST consumer!");
484 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
489 bool hasSema()
const {
return (
bool)TheSema; }
492 assert(TheSema &&
"Compiler instance has no Sema object!");
496 std::unique_ptr<Sema> takeSema();
497 void resetAndLeakSema();
506 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector()
const;
507 void setModuleDepCollector(
508 std::shared_ptr<ModuleDependencyCollector> Collector);
511 return ThePCHContainerOperations;
517 assert(Invocation &&
"cannot determine module format without invocation");
518 StringRef Format = getHeaderSearchOpts().ModuleFormat;
519 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
522 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
523 llvm::report_fatal_error(
"unknown module format");
531 assert(Invocation &&
"cannot determine module format without invocation");
532 StringRef Format = getHeaderSearchOpts().ModuleFormat;
533 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
536 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
537 llvm::report_fatal_error(
"unknown module format");
549 assert(CompletionConsumer &&
550 "Compiler instance has no code completion consumer!");
551 return *CompletionConsumer;
565 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
566 return *FrontendTimer;
576 void addOutputFile(OutputFile &&OutFile);
582 void clearOutputFiles(
bool EraseFiles);
601 bool ShouldOwnClient =
true);
624 bool ShouldOwnClient =
true,
640 std::string getSpecificModuleCachePath();
643 void createASTContext();
647 void createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
648 bool AllowPCHWithCompilerErrors,
649 void *DeserializationListener,
650 bool OwnDeserializationListener);
656 StringRef Path, StringRef Sysroot,
bool DisablePCHValidation,
660 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
661 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
662 void *DeserializationListener,
bool OwnDeserializationListener,
663 bool Preamble,
bool UseGlobalModuleIndex);
668 void createCodeCompletionConsumer();
681 void createFrontendTimer();
691 std::unique_ptr<raw_pwrite_stream>
692 createDefaultOutputFile(
bool Binary =
true, StringRef BaseInput =
"",
693 StringRef Extension =
"");
699 std::unique_ptr<raw_pwrite_stream>
700 createOutputFile(StringRef OutputPath,
bool Binary,
bool RemoveFileOnSignal,
701 StringRef BaseInput, StringRef Extension,
bool UseTemporary,
702 bool CreateMissingDirectories =
false);
729 std::unique_ptr<raw_pwrite_stream>
730 createOutputFile(StringRef OutputPath, std::error_code &Error,
bool Binary,
731 bool RemoveFileOnSignal, StringRef BaseInput,
732 StringRef Extension,
bool UseTemporary,
733 bool CreateMissingDirectories, std::string *ResultPathName,
734 std::string *TempPathName);
736 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
763 OutputStream = std::move(OutStream);
767 return std::move(OutputStream);
771 void createModuleManager();
773 bool loadModuleFile(StringRef FileName);
777 bool IsInclusionDirective)
override;
779 void loadModuleFromSource(
SourceLocation ImportLoc, StringRef ModuleName,
780 StringRef Source)
override;
786 return ModuleLoader::HadFatalFailure;
791 bool lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc)
override;
794 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
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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
InMemoryModuleCache & getModuleCache() 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.
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)
}
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.
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...
AnalyzerOptionsRef getAnalyzerOpts()
CodeCompleteConsumer & getCodeCompletionConsumer() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
Sema - This implements semantic analysis and AST building for C.
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
In-memory cache for modules.
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 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
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.
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.