clang  8.0.0svn
Classes | Public Member Functions | Static Public Member Functions | List of all members
clang::PrecompiledPreamble Class Reference

A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subsequent runs. More...

#include "clang/Frontend/PrecompiledPreamble.h"

Public Member Functions

 PrecompiledPreamble (PrecompiledPreamble &&)=default
 
PrecompiledPreambleoperator= (PrecompiledPreamble &&)=default
 
PreambleBounds getBounds () const
 PreambleBounds used to build the preamble. More...
 
std::size_t getSize () const
 Returns the size, in bytes, that preamble takes on disk or in memory. More...
 
bool CanReuse (const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, vfs::FileSystem *VFS) const
 Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file. More...
 
void AddImplicitPreamble (CompilerInvocation &CI, IntrusiveRefCntPtr< vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
 Changes options inside CI to use PCH from this preamble. More...
 
void OverridePreamble (CompilerInvocation &CI, IntrusiveRefCntPtr< vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
 Configure CI to use this preamble. More...
 

Static Public Member Functions

static llvm::ErrorOr< PrecompiledPreambleBuild (const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, PreambleCallbacks &Callbacks)
 Try to build PrecompiledPreamble for Invocation. More...
 

Detailed Description

A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subsequent runs.

Use BuildPreamble to create PCH and CanReusePreamble + AddImplicitPreamble to make use of it.

Definition at line 51 of file PrecompiledPreamble.h.

Constructor & Destructor Documentation

◆ PrecompiledPreamble()

clang::PrecompiledPreamble::PrecompiledPreamble ( PrecompiledPreamble &&  )
default

Referenced by OverridePreamble().

Member Function Documentation

◆ AddImplicitPreamble()

void PrecompiledPreamble::AddImplicitPreamble ( CompilerInvocation CI,
IntrusiveRefCntPtr< vfs::FileSystem > &  VFS,
llvm::MemoryBuffer *  MainFileBuffer 
) const

Changes options inside CI to use PCH from this preamble.

Also remaps main file to MainFileBuffer and updates VFS to ensure the preamble is accessible. Requires that CanReuse() is true. For in-memory preambles, PrecompiledPreamble instance continues to own the MemoryBuffer with the Preamble after this method returns. The caller is responsible for making sure the PrecompiledPreamble instance outlives the compiler run and the AST that will be using the PCH.

Definition at line 487 of file PrecompiledPreamble.cpp.

◆ Build()

llvm::ErrorOr< PrecompiledPreamble > PrecompiledPreamble::Build ( const CompilerInvocation Invocation,
const llvm::MemoryBuffer *  MainFileBuffer,
PreambleBounds  Bounds,
DiagnosticsEngine Diagnostics,
IntrusiveRefCntPtr< vfs::FileSystem VFS,
std::shared_ptr< PCHContainerOperations PCHContainerOps,
bool  StoreInMemory,
PreambleCallbacks Callbacks 
)
static

Try to build PrecompiledPreamble for Invocation.

See BuildPreambleError for possible error codes.

Parameters
InvocationOriginal CompilerInvocation with options to compile the file.
MainFileBufferBuffer with the contents of the main file.
BoundsBounds of the preamble, result of calling ComputePreambleBounds.
DiagnosticsDiagnostics engine to be used while building the preamble.
VFSAn instance of vfs::FileSystem to be used for file accesses.
PCHContainerOpsAn instance of PCHContainerOperations.
StoreInMemoryStore PCH in memory. If false, PCH will be stored in a temporary file.
CallbacksA set of callbacks to be executed when building the preamble.

Definition at line 232 of file PrecompiledPreamble.cpp.

References clang::PreprocessorOptions::addRemappedFile(), clang::PreambleCallbacks::AfterExecute(), clang::PreambleCallbacks::BeforeExecute(), clang::BeginSourceFileFailed, clang::CouldntCreateTargetInfo, clang::CouldntCreateTempFile, clang::CouldntEmitPCH, clang::PreambleCallbacks::createPPCallbacks(), clang::TargetInfo::CreateTargetInfo(), clang::createVFSFromCompilerInvocation(), Filename, clang::frontend::GeneratePCH, clang::PreprocessorOptions::GeneratePreamble, clang::SourceManager::getFileEntryForID(), clang::SourceManager::getMainFileID(), clang::FileEntry::getModificationTime(), clang::FileEntry::getName(), clang::FileEntry::getSize(), clang::InputKind::LLVM_IR, clang::PreambleBounds::PreambleEndsAtStartOfLine, clang::PreprocessorOptions::PrecompiledPreambleBytes, clang::ProcessWarningOptions(), clang::DiagnosticsEngine::Reset(), clang::PreprocessorOptions::RetainRemappedFileBuffers, clang::PreambleBounds::Size, and clang::InputKind::Source.

Referenced by makeStandaloneDiagnostic().

◆ CanReuse()

bool PrecompiledPreamble::CanReuse ( const CompilerInvocation Invocation,
const llvm::MemoryBuffer *  MainFileBuffer,
PreambleBounds  Bounds,
vfs::FileSystem VFS 
) const

Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file.

Definition at line 410 of file PrecompiledPreamble.cpp.

References clang::PreambleBounds::PreambleEndsAtStartOfLine, and clang::PreambleBounds::Size.

◆ getBounds()

PreambleBounds PrecompiledPreamble::getBounds ( ) const

PreambleBounds used to build the preamble.

Definition at line 385 of file PrecompiledPreamble.cpp.

◆ getSize()

std::size_t PrecompiledPreamble::getSize ( ) const

Returns the size, in bytes, that preamble takes on disk or in memory.

For on-disk preambles returns 0 if filesystem operations fail. Intended to be used for logging and debugging purposes only.

Definition at line 389 of file PrecompiledPreamble.cpp.

References max(), and clang::Result.

◆ operator=()

PrecompiledPreamble& clang::PrecompiledPreamble::operator= ( PrecompiledPreamble &&  )
default

◆ OverridePreamble()

void PrecompiledPreamble::OverridePreamble ( CompilerInvocation CI,
IntrusiveRefCntPtr< vfs::FileSystem > &  VFS,
llvm::MemoryBuffer *  MainFileBuffer 
) const

Configure CI to use this preamble.

Like AddImplicitPreamble, but doesn't assume CanReuse() is true. If this preamble does not match the file, it may parse differently.

Definition at line 494 of file PrecompiledPreamble.cpp.

References clang::ComputePreambleBounds(), getKind(), clang::CompilerInvocationBase::getLangOpts(), clang::None, PrecompiledPreamble(), and clang::Result.


The documentation for this class was generated from the following files: