#include "clang/Frontend/CompilerInstance.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Stack.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Frontend/LogDiagnosticPrinter.h"
#include "clang/Frontend/SARIFDiagnosticPrinter.h"
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/Utils.h"
#include "clang/Frontend/VerifyDiagnosticConsumer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/GlobalModuleIndex.h"
#include "clang/Serialization/InMemoryModuleCache.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LockFileManager.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include <optional>
#include <time.h>
#include <utility>
usingnamespaceclang;
CompilerInstance::CompilerInstance(
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
InMemoryModuleCache *SharedModuleCache)
: … { … }
CompilerInstance::~CompilerInstance() { … }
void CompilerInstance::setInvocation(
std::shared_ptr<CompilerInvocation> Value) { … }
bool CompilerInstance::shouldBuildGlobalModuleIndex() const { … }
void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) { … }
void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) { … }
void CompilerInstance::setVerboseOutputStream(std::unique_ptr<raw_ostream> Value) { … }
void CompilerInstance::setTarget(TargetInfo *Value) { … }
void CompilerInstance::setAuxTarget(TargetInfo *Value) { … }
bool CompilerInstance::createTarget() { … }
llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const { … }
void CompilerInstance::setFileManager(FileManager *Value) { … }
void CompilerInstance::setSourceManager(SourceManager *Value) { … }
void CompilerInstance::setPreprocessor(std::shared_ptr<Preprocessor> Value) { … }
void CompilerInstance::setASTContext(ASTContext *Value) { … }
void CompilerInstance::setSema(Sema *S) { … }
void CompilerInstance::setASTConsumer(std::unique_ptr<ASTConsumer> Value) { … }
void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { … }
std::unique_ptr<Sema> CompilerInstance::takeSema() { … }
IntrusiveRefCntPtr<ASTReader> CompilerInstance::getASTReader() const { … }
void CompilerInstance::setASTReader(IntrusiveRefCntPtr<ASTReader> Reader) { … }
std::shared_ptr<ModuleDependencyCollector>
CompilerInstance::getModuleDepCollector() const { … }
void CompilerInstance::setModuleDepCollector(
std::shared_ptr<ModuleDependencyCollector> Collector) { … }
static void collectHeaderMaps(const HeaderSearch &HS,
std::shared_ptr<ModuleDependencyCollector> MDC) { … }
static void collectIncludePCH(CompilerInstance &CI,
std::shared_ptr<ModuleDependencyCollector> MDC) { … }
static void collectVFSEntries(CompilerInstance &CI,
std::shared_ptr<ModuleDependencyCollector> MDC) { … }
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
const CodeGenOptions *CodeGenOpts,
DiagnosticsEngine &Diags) { … }
static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
DiagnosticsEngine &Diags,
StringRef OutputFile) { … }
void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client,
bool ShouldOwnClient) { … }
IntrusiveRefCntPtr<DiagnosticsEngine>
CompilerInstance::createDiagnostics(DiagnosticOptions *Opts,
DiagnosticConsumer *Client,
bool ShouldOwnClient,
const CodeGenOptions *CodeGenOpts) { … }
FileManager *CompilerInstance::createFileManager(
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { … }
void CompilerInstance::createSourceManager(FileManager &FileMgr) { … }
static void InitializeFileRemapping(DiagnosticsEngine &Diags,
SourceManager &SourceMgr,
FileManager &FileMgr,
const PreprocessorOptions &InitOpts) { … }
void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { … }
std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) { … }
void CompilerInstance::createASTContext() { … }
namespace {
struct ReadModuleNames : ASTReaderListener { … };
}
void CompilerInstance::createPCHExternalASTSource(
StringRef Path, DisableValidationForModuleKind DisableValidation,
bool AllowPCHWithCompilerErrors, void *DeserializationListener,
bool OwnDeserializationListener) { … }
IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
StringRef Path, StringRef Sysroot,
DisableValidationForModuleKind DisableValidation,
bool AllowPCHWithCompilerErrors, Preprocessor &PP,
InMemoryModuleCache &ModuleCache, ASTContext &Context,
const PCHContainerReader &PCHContainerRdr,
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
void *DeserializationListener, bool OwnDeserializationListener,
bool Preamble, bool UseGlobalModuleIndex) { … }
static bool EnableCodeCompletion(Preprocessor &PP,
StringRef Filename,
unsigned Line,
unsigned Column) { … }
void CompilerInstance::createCodeCompletionConsumer() { … }
void CompilerInstance::createFrontendTimer() { … }
CodeCompleteConsumer *
CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
StringRef Filename,
unsigned Line,
unsigned Column,
const CodeCompleteOptions &Opts,
raw_ostream &OS) { … }
void CompilerInstance::createSema(TranslationUnitKind TUKind,
CodeCompleteConsumer *CompletionConsumer) { … }
void CompilerInstance::clearOutputFiles(bool EraseFiles) { … }
std::unique_ptr<raw_pwrite_stream> CompilerInstance::createDefaultOutputFile(
bool Binary, StringRef InFile, StringRef Extension, bool RemoveFileOnSignal,
bool CreateMissingDirectories, bool ForceUseTemporary) { … }
std::unique_ptr<raw_pwrite_stream> CompilerInstance::createNullOutputFile() { … }
std::unique_ptr<raw_pwrite_stream>
CompilerInstance::createOutputFile(StringRef OutputPath, bool Binary,
bool RemoveFileOnSignal, bool UseTemporary,
bool CreateMissingDirectories) { … }
Expected<std::unique_ptr<llvm::raw_pwrite_stream>>
CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary,
bool RemoveFileOnSignal,
bool UseTemporary,
bool CreateMissingDirectories) { … }
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){ … }
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr) { … }
bool CompilerInstance::ExecuteAction(FrontendAction &Act) { … }
void CompilerInstance::printDiagnosticStats() { … }
void CompilerInstance::LoadRequestedPlugins() { … }
static Language getLanguageFromOptions(const LangOptions &LangOpts) { … }
static bool
compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
StringRef ModuleName, FrontendInputFile Input,
StringRef OriginalModuleMapFile, StringRef ModuleFileName,
llvm::function_ref<void(CompilerInstance &)> PreBuildStep =
[](CompilerInstance &) { … }
static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
FileManager &FileMgr) { … }
static bool compileModule(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc, Module *Module,
StringRef ModuleFileName) { … }
static bool readASTAfterCompileModule(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc,
SourceLocation ModuleNameLoc,
Module *Module, StringRef ModuleFileName,
bool *OutOfDate) { … }
static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc,
SourceLocation ModuleNameLoc,
Module *Module,
StringRef ModuleFileName) { … }
static bool compileModuleAndReadASTBehindLock(
CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName) { … }
static bool compileModuleAndReadAST(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc,
SourceLocation ModuleNameLoc,
Module *Module, StringRef ModuleFileName) { … }
static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro,
Module *Mod, SourceLocation ImportLoc) { … }
static void checkConfigMacros(Preprocessor &PP, Module *M,
SourceLocation ImportLoc) { … }
static void writeTimestampFile(StringRef TimestampFile) { … }
static void pruneModuleCache(const HeaderSearchOptions &HSOpts) { … }
void CompilerInstance::createASTReader() { … }
bool CompilerInstance::loadModuleFile(
StringRef FileName, serialization::ModuleFile *&LoadedModuleFile) { … }
namespace {
enum ModuleSource { … };
}
static ModuleSource selectModuleSource(
Module *M, StringRef ModuleName, std::string &ModuleFilename,
const std::map<std::string, std::string, std::less<>> &BuiltModules,
HeaderSearch &HS) { … }
ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
StringRef ModuleName, SourceLocation ImportLoc,
SourceLocation ModuleNameLoc, bool IsInclusionDirective) { … }
ModuleLoadResult
CompilerInstance::loadModule(SourceLocation ImportLoc,
ModuleIdPath Path,
Module::NameVisibilityKind Visibility,
bool IsInclusionDirective) { … }
void CompilerInstance::createModuleFromSource(SourceLocation ImportLoc,
StringRef ModuleName,
StringRef Source) { … }
void CompilerInstance::makeModuleVisible(Module *Mod,
Module::NameVisibilityKind Visibility,
SourceLocation ImportLoc) { … }
GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
SourceLocation TriggerLoc) { … }
bool
CompilerInstance::lookupMissingImports(StringRef Name,
SourceLocation TriggerLoc) { … }
void CompilerInstance::resetAndLeakSema() { … }
void CompilerInstance::setExternalSemaSource(
IntrusiveRefCntPtr<ExternalSemaSource> ESS) { … }