13#ifndef LLVM_CLANG_FRONTEND_PRECOMPILEDPREAMBLE_H
14#define LLVM_CLANG_FRONTEND_PRECOMPILEDPREAMBLE_H
18#include "llvm/ADT/IntrusiveRefCntPtr.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/MD5.h"
23#include <system_error>
35class CompilerInstance;
36class CompilerInvocation;
39class PCHContainerOperations;
43 const llvm::MemoryBufferRef &Buffer,
46class PreambleCallbacks;
53 struct PreambleFileHash;
84 static llvm::ErrorOr<PrecompiledPreamble>
89 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
90 bool StoreInMemory, StringRef StoragePath,
107 return {PreambleBytes.data(), PreambleBytes.size()};
113 const llvm::MemoryBufferRef &MainFileBuffer,
126 llvm::MemoryBuffer *MainFileBuffer)
const;
133 llvm::MemoryBuffer *MainFileBuffer)
const;
137 std::vector<char> PreambleBytes,
138 bool PreambleEndsAtStartOfLine,
139 llvm::StringMap<PreambleFileHash> FilesInPreamble,
140 llvm::StringSet<> MissingFiles);
143 struct PreambleFileHash {
154 llvm::MD5::MD5Result MD5 = {};
156 static PreambleFileHash createForFile(off_t Size, time_t ModTime);
157 static PreambleFileHash
158 createForMemoryBuffer(
const llvm::MemoryBufferRef &Buffer);
160 friend bool operator==(
const PreambleFileHash &LHS,
161 const PreambleFileHash &RHS) {
162 return LHS.Size == RHS.Size && LHS.ModTime == RHS.ModTime &&
165 friend bool operator!=(
const PreambleFileHash &LHS,
166 const PreambleFileHash &RHS) {
167 return !(LHS == RHS);
173 void configurePreamble(PreambleBounds Bounds, CompilerInvocation &CI,
174 IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
175 llvm::MemoryBuffer *MainFileBuffer)
const;
181 setupPreambleStorage(
const PCHStorage &Storage,
182 PreprocessorOptions &PreprocessorOpts,
183 IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS);
186 std::unique_ptr<PCHStorage> Storage;
192 llvm::StringMap<PreambleFileHash> FilesInPreamble;
201 llvm::StringSet<> MissingFiles;
205 std::vector<char> PreambleBytes;
207 bool PreambleEndsAtStartOfLine;
252 const char *
name()
const noexcept override;
253 std::string
message(
int condition)
const override;
260struct std::is_error_code_enum<
clang::BuildPreambleError> : std::true_type {};
Defines the clang::Preprocessor interface.
Writes an AST file containing the contents of a translation unit.
std::string message(int condition) const override
const char * name() const noexcept override
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Decl - This represents one declaration (or definition), e.g.
Concrete class used by the front-end to report problems and issues.
A set of callbacks to gather useful information while building a preamble.
virtual void AfterPCHEmitted(ASTWriter &Writer)
Called after PCH has been emitted.
virtual void BeforeExecute(CompilerInstance &CI)
Called before FrontendAction::Execute.
virtual CommentHandler * getCommentHandler()
The returned CommentHandler will be added to the preprocessor if not null.
virtual ~PreambleCallbacks()=default
virtual void HandleTopLevelDecl(DeclGroupRef DG)
Called for each TopLevelDecl.
virtual std::unique_ptr< PPCallbacks > createPPCallbacks()
Creates wrapper class for PPCallbacks so we can also process information about includes that are insi...
virtual void AfterExecute(CompilerInstance &CI)
Called after FrontendAction::Execute(), but before FrontendAction::EndSourceFile().
virtual bool shouldSkipFunctionBody(Decl *D)
Determines which function bodies are parsed, by default skips everything.
A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subse...
void OverridePreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Configure CI to use this preamble.
llvm::StringRef getContents() const
Returned string is not null-terminated.
PrecompiledPreamble & operator=(PrecompiledPreamble &&)
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, StringRef StoragePath, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
bool CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBufferRef &MainFileBuffer, PreambleBounds Bounds, llvm::vfs::FileSystem &VFS) const
Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file...
void AddImplicitPreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Changes options inside CI to use PCH from this preamble.
std::size_t getSize() const
Returns the size, in bytes, that preamble takes on disk or in memory.
PreambleBounds getBounds() const
PreambleBounds used to build the preamble.
PrecompiledPreamble(PrecompiledPreamble &&)
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool operator!=(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
The JSON file list parser is used to communicate input to InstallAPI.
std::error_code make_error_code(BuildPreambleError Error)
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, const llvm::MemoryBufferRef &Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
@ CouldntCreateTargetInfo
Diagnostic wrappers for TextAPI types for error reporting.
Describes the bounds (start, size) of the preamble and a flag required by PreprocessorOptions::Precom...