22#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREAMBLE_H
23#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREAMBLE_H
32#include "clang-include-cleaner/Record.h"
34#include "clang/Basic/SourceManager.h"
35#include "clang/Basic/TargetOptions.h"
36#include "clang/Frontend/CompilerInvocation.h"
37#include "clang/Frontend/PrecompiledPreamble.h"
38#include "clang/Lex/Lexer.h"
39#include "clang/Tooling/CompilationDatabase.h"
40#include "llvm/ADT/ArrayRef.h"
41#include "llvm/ADT/StringRef.h"
62 : Invocation(
Clang.getInvocationPtr()),
63 Diagnostics(
Clang.getDiagnosticsPtr()), Target(
Clang.getTargetPtr()),
64 AuxTarget(
Clang.getAuxTarget()), FileMgr(
Clang.getFileManagerPtr()),
65 SourceMgr(
Clang.getSourceManagerPtr()), PP(
Clang.getPreprocessorPtr()),
77 void setStatCache(std::shared_ptr<PreambleFileStatusCache> StatCache) {
78 this->StatCache = StatCache;
82 std::shared_ptr<CompilerInvocation> Invocation;
83 IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
84 IntrusiveRefCntPtr<TargetInfo> Target;
85 IntrusiveRefCntPtr<TargetInfo> AuxTarget;
86 IntrusiveRefCntPtr<FileManager> FileMgr;
87 IntrusiveRefCntPtr<SourceManager> SourceMgr;
88 std::shared_ptr<Preprocessor> PP;
89 IntrusiveRefCntPtr<ASTContext>
Context;
90 std::shared_ptr<PreambleFileStatusCache> StatCache;
113 std::shared_ptr<const include_cleaner::PragmaIncludes>
Pragmas;
132 std::shared_ptr<const include_cleaner::PragmaIncludes>)>;
156std::shared_ptr<const PreambleData>
168 const CompilerInvocation &
CI);
192 static OptionalFileEntryRef
getPatchEntry(llvm::StringRef MainFilePath,
193 const SourceManager &SM);
198 void apply(CompilerInvocation &
CI)
const;
212 llvm::StringRef
text()
const {
return PatchContents; }
217 static constexpr llvm::StringLiteral
HeaderName =
"__preamble_patch__.h";
219 llvm::ArrayRef<PragmaMark>
marks()
const;
229 std::string PatchContents;
230 std::string PatchFileName;
233 std::vector<Inclusion> PreambleIncludes;
235 std::vector<Diag> PatchedDiags;
236 PreambleBounds ModifiedBounds = {0,
false};
238 std::vector<PragmaMark> PatchedMarks;
std::unique_ptr< CompilerInvocation > CI
A context is an immutable container for per-request data that must be propagated through layers that ...
Stores information required to parse a TU using a (possibly stale) Baseline preamble.
static OptionalFileEntryRef getPatchEntry(llvm::StringRef MainFilePath, const SourceManager &SM)
Returns the FileEntry for the preamble patch of MainFilePath in SM, if any.
const MainFileMacros & mainFileMacros() const
llvm::ArrayRef< PragmaMark > marks() const
void apply(CompilerInvocation &CI) const
Adjusts CI (which compiles the modified inputs) to be used with the baseline preamble.
static PreamblePatch unmodified(const PreambleData &Preamble)
Preamble is used verbatim.
llvm::ArrayRef< Diag > patchedDiags() const
Returns diag locations for Modified contents.
llvm::StringRef text() const
Returns textual patch contents.
static PreamblePatch createMacroPatch(llvm::StringRef FileName, const ParseInputs &Modified, const PreambleData &Baseline)
static PreamblePatch createFullPatch(llvm::StringRef FileName, const ParseInputs &Modified, const PreambleData &Baseline)
Builds a patch that contains new PP directives introduced to the preamble section of Modified compare...
static constexpr llvm::StringLiteral HeaderName
std::vector< Inclusion > preambleIncludes() const
Returns #include directives from the Modified preamble that were resolved using the Baseline preamble...
PreambleBounds modifiedBounds() const
Returns preamble bounds for the Modified.
std::function< void(CapturedASTCtx ASTCtx, std::shared_ptr< const include_cleaner::PragmaIncludes >)> PreambleParsedCallback
bool isPreambleCompatible(const PreambleData &Preamble, const ParseInputs &Inputs, PathRef FileName, const CompilerInvocation &CI)
Returns true if Preamble is reusable for Inputs.
std::shared_ptr< const PreambleData > buildPreamble(PathRef FileName, CompilerInvocation CI, const ParseInputs &Inputs, bool StoreInMemory, PreambleParsedCallback PreambleCallback, PreambleBuildStats *Stats)
Build a preamble for the new inputs unless an old one can be reused.
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
The captured AST context.
CapturedASTCtx & operator=(CapturedASTCtx &&)=default
CapturedASTCtx & operator=(const CapturedASTCtx &)=delete
CapturedASTCtx(const CapturedASTCtx &)=delete
void setStatCache(std::shared_ptr< PreambleFileStatusCache > StatCache)
CapturedASTCtx(CompilerInstance &Clang)
CapturedASTCtx(CapturedASTCtx &&)=default
CompilerInvocation & getCompilerInvocation()
Preprocessor & getPreprocessor()
FileManager & getFileManager()
ASTContext & getASTContext()
Timings and statistics from the premble build.
double FileSystemTime
Time spent in filesystem operations during the build, in seconds.
size_t BuildSize
Estimate of the memory used while building the preamble.
double TotalBuildTime
Total wall time it took to build preamble, in seconds.
size_t SerializedSize
The serialized size of the preamble.
The parsed preamble and associated data.
std::vector< Diag > Diags
std::vector< PragmaMark > Marks
PrecompiledPreamble Preamble
std::unique_ptr< PrerequisiteModules > RequiredModules
std::shared_ptr< const include_cleaner::PragmaIncludes > Pragmas
PreambleData(PrecompiledPreamble Preamble)
bool MainIsIncludeGuarded
std::shared_ptr< PreambleFileStatusCache > StatCache
std::shared_ptr< TargetOptions > TargetOpts
tooling::CompileCommand CompileCommand
IncludeStructure Includes