18#include "llvm/Support/CrashRecoveryContext.h"
59 const char **ArgBegin,
const char **ArgEnd,
60 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
61 std::shared_ptr<DiagnosticOptions> DiagOpts,
63 bool StorePreamblesInMemory, StringRef PreambleStoragePath,
66 bool RemappedFilesKeepOriginalName,
unsigned PrecompilePreambleAfterNParses,
68 bool IncludeBriefCommentsInCodeCompletion,
bool AllowPCHWithCompilerErrors,
70 bool UserFilesAreVolatile,
bool ForSerialization,
71 bool RetainExcludedConditionalBlocks, std::optional<StringRef> ModuleFormat,
72 std::unique_ptr<ASTUnit> *ErrAST,
74 assert(Diags.get() &&
"no DiagnosticsEngine was provided");
80 VFS = llvm::vfs::createPhysicalFileSystem();
84 std::shared_ptr<CompilerInvocation> CI;
88 &StoredDiagnostics,
nullptr);
100 for (
const auto &RemappedFile : RemappedFiles) {
101 CI->getPreprocessorOpts().addRemappedFile(RemappedFile.first,
102 RemappedFile.second);
111 CI->getHeaderSearchOpts().ResourceDir = std::string(ResourceFilesPath);
113 CI->getFrontendOpts().SkipFunctionBodies =
117 CI->getHeaderSearchOpts().ModuleFormat = std::string(*ModuleFormat);
120 std::unique_ptr<ASTUnit> AST;
122 AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
123 AST->StoredDiagnostics.swap(StoredDiagnostics);
124 ASTUnit::ConfigureDiags(Diags, *AST, CaptureDiagnostics);
125 AST->DiagOpts = DiagOpts;
126 AST->Diagnostics = Diags;
127 AST->FileSystemOpts = CI->getFileSystemOpts();
128 AST->CodeGenOpts = std::make_unique<CodeGenOptions>(CI->getCodeGenOpts());
131 llvm::makeIntrusiveRefCnt<FileManager>(AST->FileSystemOpts, VFS);
132 AST->StorePreamblesInMemory = StorePreamblesInMemory;
133 AST->PreambleStoragePath = PreambleStoragePath;
135 AST->OnlyLocalDecls = OnlyLocalDecls;
136 AST->CaptureDiagnostics = CaptureDiagnostics;
137 AST->TUKind = TUKind;
138 AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
139 AST->IncludeBriefCommentsInCodeCompletion =
140 IncludeBriefCommentsInCodeCompletion;
141 AST->UserFilesAreVolatile = UserFilesAreVolatile;
142 AST->Invocation = CI;
143 AST->SkipFunctionBodies = SkipFunctionBodies;
144 if (ForSerialization)
145 AST->WriterData.reset(
146 new ASTUnit::ASTWriterData(*AST->ModCache, *AST->CodeGenOpts));
152 llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit> ASTUnitCleanup(AST.get());
154 if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
155 PrecompilePreambleAfterNParses, VFS)) {
159 AST->StoredDiagnostics.swap(AST->FailedParseDiagnostics);
Utility class for loading a ASTContext from an AST file.
RAII object that optionally captures and filters diagnostics, if there is no diagnostic client to cap...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
bool RetainExcludedConditionalBlocks
When enabled, excluded conditional blocks retain in the main file.
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
The JSON file list parser is used to communicate input to InstallAPI.
std::unique_ptr< ASTUnit > CreateASTUnitFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool StorePreamblesInMemory=false, StringRef PreambleStoragePath=StringRef(), bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, ArrayRef< ASTUnit::RemappedFile > RemappedFiles={}, bool RemappedFilesKeepOriginalName=true, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, SkipFunctionBodiesScope SkipFunctionBodies=SkipFunctionBodiesScope::None, bool SingleFileParse=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, bool RetainExcludedConditionalBlocks=false, std::optional< StringRef > ModuleFormat=std::nullopt, std::unique_ptr< ASTUnit > *ErrAST=nullptr, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file...
SkipFunctionBodiesScope
Enumerates the available scopes for skipping function bodies.
std::unique_ptr< CompilerInvocation > createInvocation(ArrayRef< const char * > Args, CreateInvocationOptions Opts={})
Interpret clang arguments in preparation to parse a file.
CaptureDiagsKind
Enumerates the available kinds for capturing diagnostics.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
IntrusiveRefCntPtr< ModuleCache > createCrossProcessModuleCache()
Creates new ModuleCache backed by a file system directory that may be operated on by multiple process...
TranslationUnitKind
Describes the kind of translation unit being processed.
Optional inputs to createInvocation.
IntrusiveRefCntPtr< DiagnosticsEngine > Diags
Receives diagnostics encountered while parsing command-line flags.
bool ProbePrecompiled
Allow the driver to probe the filesystem for PCH files.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS
Used e.g.