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" 25 #include "llvm/Support/BuryPointer.h" 41 class CodeCompleteConsumer;
42 class DiagnosticsEngine;
43 class DiagnosticConsumer;
44 class ExternalASTSource;
48 class MemoryBufferCache;
75 std::shared_ptr<CompilerInvocation> Invocation;
99 std::shared_ptr<Preprocessor> PP;
108 std::unique_ptr<ASTConsumer> Consumer;
111 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
114 std::unique_ptr<Sema> TheSema;
117 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
120 std::unique_ptr<llvm::Timer> FrontendTimer;
126 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
129 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
132 std::unique_ptr<DependencyFileGenerator> TheDependencyFileGenerator;
134 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
138 llvm::DenseMap<const IdentifierInfo *, Module *> KnownModules;
142 std::map<std::string, std::string> BuiltModules;
145 bool DeleteBuiltModules =
true;
157 bool BuildGlobalModuleIndex =
false;
160 bool HaveFullGlobalModuleIndex =
false;
163 bool ModuleBuildFailed =
false;
172 std::string TempFilename;
174 OutputFile(std::string filename, std::string tempFilename)
175 :
Filename(std::move(filename)), TempFilename(std::move(tempFilename)) {
182 std::unique_ptr<llvm::raw_fd_ostream> NonSeekStream;
185 std::list<OutputFile> OutputFiles;
188 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
194 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
195 std::make_shared<PCHContainerOperations>(),
241 assert(Invocation &&
"Compiler instance has no invocation!");
246 void setInvocation(std::shared_ptr<CompilerInvocation>
Value);
249 bool shouldBuildGlobalModuleIndex()
const;
254 BuildGlobalModuleIndex = Build;
262 return Invocation->getAnalyzerOpts();
266 return Invocation->getCodeGenOpts();
269 return Invocation->getCodeGenOpts();
273 return Invocation->getDependencyOutputOpts();
276 return Invocation->getDependencyOutputOpts();
280 return Invocation->getDiagnosticOpts();
283 return Invocation->getDiagnosticOpts();
287 return Invocation->getFileSystemOpts();
290 return Invocation->getFileSystemOpts();
294 return Invocation->getFrontendOpts();
297 return Invocation->getFrontendOpts();
301 return Invocation->getHeaderSearchOpts();
304 return Invocation->getHeaderSearchOpts();
307 return Invocation->getHeaderSearchOptsPtr();
311 return *Invocation->getLangOpts();
314 return *Invocation->getLangOpts();
318 return Invocation->getPreprocessorOpts();
321 return Invocation->getPreprocessorOpts();
325 return Invocation->getPreprocessorOutputOpts();
328 return Invocation->getPreprocessorOutputOpts();
332 return Invocation->getTargetOpts();
335 return Invocation->getTargetOpts();
346 assert(Diagnostics &&
"Compiler instance has no diagnostics!");
354 assert(Diagnostics && Diagnostics->getClient() &&
355 "Compiler instance has no diagnostic client!");
356 return *Diagnostics->getClient();
366 assert(Target &&
"Compiler instance has no target!");
389 assert(hasVirtualFileSystem() &&
390 "Compiler instance has no virtual file system");
391 return *VirtualFileSystem;
399 VirtualFileSystem = std::move(FS);
410 assert(FileMgr &&
"Compiler instance has no file manager!");
415 llvm::BuryPointer(FileMgr.get());
416 FileMgr.resetWithoutRelease();
430 assert(SourceMgr &&
"Compiler instance has no source manager!");
435 llvm::BuryPointer(SourceMgr.get());
436 SourceMgr.resetWithoutRelease();
450 assert(PP &&
"Compiler instance has no preprocessor!");
457 llvm::BuryPointer(
new std::shared_ptr<Preprocessor>(PP));
461 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
470 assert(Context &&
"Compiler instance has no AST context!");
475 llvm::BuryPointer(Context.get());
476 Context.resetWithoutRelease();
484 void setSema(
Sema *S);
493 assert(Consumer &&
"Compiler instance has no AST consumer!");
503 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
508 bool hasSema()
const {
return (
bool)TheSema; }
511 assert(TheSema &&
"Compiler instance has no Sema object!");
515 std::unique_ptr<Sema> takeSema();
516 void resetAndLeakSema();
525 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector()
const;
526 void setModuleDepCollector(
527 std::shared_ptr<ModuleDependencyCollector> Collector);
530 return ThePCHContainerOperations;
536 assert(Invocation &&
"cannot determine module format without invocation");
537 StringRef Format = getHeaderSearchOpts().ModuleFormat;
538 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
541 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
542 llvm::report_fatal_error(
"unknown module format");
550 assert(Invocation &&
"cannot determine module format without invocation");
551 StringRef Format = getHeaderSearchOpts().ModuleFormat;
552 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
555 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
556 llvm::report_fatal_error(
"unknown module format");
568 assert(CompletionConsumer &&
569 "Compiler instance has no code completion consumer!");
570 return *CompletionConsumer;
584 assert(FrontendTimer &&
"Compiler instance has no frontend timer!");
585 return *FrontendTimer;
595 void addOutputFile(OutputFile &&OutFile);
601 void clearOutputFiles(
bool EraseFiles);
620 bool ShouldOwnClient =
true);
643 bool ShouldOwnClient =
true,
658 std::string getSpecificModuleCachePath();
661 void createASTContext();
665 void createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
666 bool AllowPCHWithCompilerErrors,
667 void *DeserializationListener,
668 bool OwnDeserializationListener);
674 StringRef Path, StringRef Sysroot,
bool DisablePCHValidation,
677 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
679 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
680 void *DeserializationListener,
bool OwnDeserializationListener,
681 bool Preamble,
bool UseGlobalModuleIndex);
686 void createCodeCompletionConsumer();
699 void createFrontendTimer();
709 std::unique_ptr<raw_pwrite_stream>
710 createDefaultOutputFile(
bool Binary =
true, StringRef BaseInput =
"",
711 StringRef Extension =
"");
717 std::unique_ptr<raw_pwrite_stream>
718 createOutputFile(StringRef OutputPath,
bool Binary,
bool RemoveFileOnSignal,
719 StringRef BaseInput, StringRef Extension,
bool UseTemporary,
720 bool CreateMissingDirectories =
false);
747 std::unique_ptr<raw_pwrite_stream>
748 createOutputFile(StringRef OutputPath, std::error_code &Error,
bool Binary,
749 bool RemoveFileOnSignal, StringRef BaseInput,
750 StringRef Extension,
bool UseTemporary,
751 bool CreateMissingDirectories, std::string *ResultPathName,
752 std::string *TempPathName);
754 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
781 OutputStream = std::move(OutStream);
785 return std::move(OutputStream);
789 void createModuleManager();
791 bool loadModuleFile(StringRef FileName);
795 bool IsInclusionDirective)
override;
797 void loadModuleFromSource(
SourceLocation ImportLoc, StringRef ModuleName,
798 StringRef Source)
override;
804 return ModuleLoader::HadFatalFailure;
809 bool lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc)
override;
812 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)
}
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
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
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
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
void setVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Replace the current virtual file system.
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.