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 std::map<std::string, std::string> BuiltModules;
134 bool DeleteBuiltModules =
true;
146 bool BuildGlobalModuleIndex =
false;
149 bool HaveFullGlobalModuleIndex =
false;
152 bool ModuleBuildFailed =
false;
155 std::unique_ptr<raw_ostream> OwnedVerboseOutputStream;
158 raw_ostream *VerboseOutputStream = &llvm::errs();
167 std::string TempFilename;
169 OutputFile(std::string filename, std::string tempFilename)
170 :
Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
177 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
180 std::list<OutputFile> OutputFiles;
183 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
189 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
190 std::make_shared<PCHContainerOperations>(),
233 assert(Invocation &&
"Compiler instance has no invocation!");
238 void setInvocation(std::shared_ptr<CompilerInvocation>
Value);
241 bool shouldBuildGlobalModuleIndex()
const;
246 BuildGlobalModuleIndex = Build;
254 return Invocation->getAnalyzerOpts();
258 return Invocation->getCodeGenOpts();
261 return Invocation->getCodeGenOpts();
265 return Invocation->getDependencyOutputOpts();
268 return Invocation->getDependencyOutputOpts();
272 return Invocation->getDiagnosticOpts();
275 return Invocation->getDiagnosticOpts();
279 return Invocation->getFileSystemOpts();
282 return Invocation->getFileSystemOpts();
286 return Invocation->getFrontendOpts();
289 return Invocation->getFrontendOpts();
293 return Invocation->getHeaderSearchOpts();
296 return Invocation->getHeaderSearchOpts();
299 return Invocation->getHeaderSearchOptsPtr();
303 return *Invocation->getLangOpts();
306 return *Invocation->getLangOpts();
310 return Invocation->getPreprocessorOpts();
313 return Invocation->getPreprocessorOpts();
317 return Invocation->getPreprocessorOutputOpts();
320 return Invocation->getPreprocessorOutputOpts();
324 return Invocation->getTargetOpts();
327 return Invocation->getTargetOpts();
338 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
346 assert(Diagnostics && Diagnostics->getClient() &&
347 "Compiler instance has no diagnostic client!");
348 return *Diagnostics->getClient();
356 void setVerboseOutputStream(raw_ostream &Value);
359 void setVerboseOutputStream(std::unique_ptr<raw_ostream> Value);
363 return *VerboseOutputStream;
373 assert(Target &&
"Compiler instance has no target!");
394 return getFileManager().getVirtualFileSystem();
405 assert(FileMgr &&
"Compiler instance has no file manager!");
410 llvm::BuryPointer(FileMgr.get());
411 FileMgr.resetWithoutRelease();
425 assert(SourceMgr &&
"Compiler instance has no source manager!");
430 llvm::BuryPointer(SourceMgr.get());
431 SourceMgr.resetWithoutRelease();
445 assert(PP &&
"Compiler instance has no preprocessor!");
452 llvm::BuryPointer(
new std::shared_ptr<Preprocessor>(PP));
456 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
465 assert(Context &&
"Compiler instance has no AST context!");
470 llvm::BuryPointer(Context.get());
471 Context.resetWithoutRelease();
479 void setSema(
Sema *S);
488 assert(Consumer &&
"Compiler instance has no AST consumer!");
498 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
503 bool hasSema()
const {
return (
bool)TheSema; }
506 assert(TheSema &&
"Compiler instance has no Sema object!");
510 std::unique_ptr<Sema> takeSema();
511 void resetAndLeakSema();
520 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector()
const;
521 void setModuleDepCollector(
522 std::shared_ptr<ModuleDependencyCollector> Collector);
525 return ThePCHContainerOperations;
531 assert(Invocation &&
"cannot determine module format without invocation");
532 StringRef Format = getHeaderSearchOpts().ModuleFormat;
533 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
536 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
537 llvm::report_fatal_error(
"unknown module format");
545 assert(Invocation &&
"cannot determine module format without invocation");
546 StringRef Format = getHeaderSearchOpts().ModuleFormat;
547 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
550 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
551 llvm::report_fatal_error(
"unknown module format");
563 assert(CompletionConsumer &&
564 "Compiler instance has no code completion consumer!");
565 return *CompletionConsumer;
579 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
580 return *FrontendTimer;
590 void addOutputFile(OutputFile &&OutFile);
596 void clearOutputFiles(
bool EraseFiles);
615 bool ShouldOwnClient =
true);
638 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,
674 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 OutputStream = std::move(OutStream);
781 return std::move(OutputStream);
787 bool loadModuleFile(StringRef FileName);
804 bool IsInclusionDirective);
809 bool IsInclusionDirective)
override;
811 void createModuleFromSource(
SourceLocation ImportLoc, StringRef ModuleName,
812 StringRef Source)
override;
818 return ModuleLoader::HadFatalFailure;
823 bool lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc)
override;
826 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
static ASTReader * createASTReader(CompilerInstance &CI, StringRef pchFile, SmallVectorImpl< std::unique_ptr< llvm::MemoryBuffer >> &MemBufs, SmallVectorImpl< std::string > &bufNames, ASTDeserializationListener *deserialListener=nullptr)
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 ...
raw_ostream & getVerboseOutputStream()
Get the current stream for verbose output.
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.