clang 20.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::SrcMgr::ContentCache Class Reference

One instance of this struct is kept for every file loaded or used. More...

#include "clang/Basic/SourceManager.h"

Public Member Functions

 ContentCache ()
 
 ContentCache (FileEntryRef Ent)
 
 ContentCache (FileEntryRef Ent, FileEntryRef contentEnt)
 
 ContentCache (const ContentCache &RHS)
 The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCache.
 
ContentCacheoperator= (const ContentCache &RHS)=delete
 
std::optional< llvm::MemoryBufferRef > getBufferOrNone (DiagnosticsEngine &Diag, FileManager &FM, SourceLocation Loc=SourceLocation()) const
 Returns the memory buffer for the associated content.
 
unsigned getSize () const
 Returns the size of the content encapsulated by this ContentCache.
 
unsigned getSizeBytesMapped () const
 Returns the number of bytes actually mapped for this ContentCache.
 
llvm::MemoryBuffer::BufferKind getMemoryBufferKind () const
 Returns the kind of memory used to back the memory buffer for this content cache.
 
std::optional< llvm::MemoryBufferRef > getBufferIfLoaded () const
 Return the buffer, only if it has been loaded.
 
std::optional< StringRef > getBufferDataIfLoaded () const
 Return a StringRef to the source buffer data, only if it has already been loaded.
 
void setBuffer (std::unique_ptr< llvm::MemoryBuffer > B)
 Set the buffer.
 
void setUnownedBuffer (std::optional< llvm::MemoryBufferRef > B)
 Set the buffer to one that's not owned (or to nullptr).
 

Static Public Member Functions

static const char * getInvalidBOM (StringRef BufStr)
 

Public Attributes

OptionalFileEntryRef OrigEntry
 Reference to the file entry representing this ContentCache.
 
OptionalFileEntryRef ContentsEntry
 References the file which the contents were actually loaded from.
 
StringRef Filename
 The filename that is used to access OrigEntry.
 
LineOffsetMapping SourceLineCache
 A bump pointer allocated array of offsets for each source line.
 
unsigned BufferOverridden: 1
 Indicates whether the buffer itself was provided to override the actual file contents.
 
unsigned IsFileVolatile: 1
 True if this content cache was initially created for a source file considered to be volatile (likely to change between stat and open).
 
unsigned IsTransient: 1
 True if this file may be transient, that is, if it might not exist at some later point in time when this content entry is used, after serialization and deserialization.
 
unsigned IsBufferInvalid: 1
 

Detailed Description

One instance of this struct is kept for every file loaded or used.

This object owns the MemoryBuffer object.

Definition at line 131 of file SourceManager.h.

Constructor & Destructor Documentation

◆ ContentCache() [1/4]

clang::SrcMgr::ContentCache::ContentCache ( )
inline

Definition at line 187 of file SourceManager.h.

◆ ContentCache() [2/4]

clang::SrcMgr::ContentCache::ContentCache ( FileEntryRef  Ent)
inline

Definition at line 192 of file SourceManager.h.

◆ ContentCache() [3/4]

clang::SrcMgr::ContentCache::ContentCache ( FileEntryRef  Ent,
FileEntryRef  contentEnt 
)
inline

Definition at line 194 of file SourceManager.h.

◆ ContentCache() [4/4]

clang::SrcMgr::ContentCache::ContentCache ( const ContentCache RHS)
inline

The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCache.

Ownership of allocated memory is not transferred, so this is a logical error.

Definition at line 201 of file SourceManager.h.

References ContentsEntry, OrigEntry, and SourceLineCache.

Member Function Documentation

◆ getBufferDataIfLoaded()

std::optional< StringRef > clang::SrcMgr::ContentCache::getBufferDataIfLoaded ( ) const
inline

Return a StringRef to the source buffer data, only if it has already been loaded.

Definition at line 251 of file SourceManager.h.

Referenced by clang::SourceManager::getBufferDataIfLoaded().

◆ getBufferIfLoaded()

std::optional< llvm::MemoryBufferRef > clang::SrcMgr::ContentCache::getBufferIfLoaded ( ) const
inline

Return the buffer, only if it has been loaded.

Definition at line 243 of file SourceManager.h.

Referenced by clang::ASTReader::ReadSLocEntry().

◆ getBufferOrNone()

std::optional< llvm::MemoryBufferRef > ContentCache::getBufferOrNone ( DiagnosticsEngine Diag,
FileManager FM,
SourceLocation  Loc = SourceLocation() 
) const

Returns the memory buffer for the associated content.

Parameters
DiagObject through which diagnostics will be emitted if the buffer cannot be retrieved.
LocIf specified, is the location that invalid file diagnostics will be emitted at.

Definition at line 110 of file SourceManager.cpp.

References ContentsEntry, Diag(), clang::FileManager::getBufferForFile(), getInvalidBOM(), clang::FileEntryRef::getName(), clang::FileEntryRef::getSize(), IsBufferInvalid, IsFileVolatile, clang::FileEntryRef::isNamedPipe(), and Loc.

Referenced by clang::SourceManager::createFileID(), clang::SourceManager::getBufferDataOrNone(), clang::SourceManager::getCharacterData(), clang::SourceManager::getLineNumber(), clang::SourceManager::getMemoryBufferForFileOrNone(), and clang::SourceManager::translateLineCol().

◆ getInvalidBOM()

const char * ContentCache::getInvalidBOM ( StringRef  BufStr)
static

Definition at line 86 of file SourceManager.cpp.

Referenced by getBufferOrNone().

◆ getMemoryBufferKind()

llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind ( ) const

Returns the kind of memory used to back the memory buffer for this content cache.

This is used for performance analysis.

Definition at line 69 of file SourceManager.cpp.

◆ getSize()

unsigned ContentCache::getSize ( ) const

Returns the size of the content encapsulated by this ContentCache.

getSize - Returns the size of the content encapsulated by this ContentCache.

This can be the size of the source file or the size of an arbitrary scratch buffer. If the ContentCache encapsulates a source file this size is retrieved from the file's FileEntry.

This can be the size of the source file or the size of an arbitrary scratch buffer. If the ContentCache encapsulates a source file, that file is not lazily brought in from disk to satisfy this query.

Definition at line 81 of file SourceManager.cpp.

References ContentsEntry, and clang::FileEntryRef::getSize().

◆ getSizeBytesMapped()

unsigned ContentCache::getSizeBytesMapped ( ) const

Returns the number of bytes actually mapped for this ContentCache.

getSizeBytesMapped - Returns the number of bytes actually mapped for this ContentCache.

This can be 0 if the MemBuffer was not actually expanded.

Definition at line 63 of file SourceManager.cpp.

◆ operator=()

ContentCache & clang::SrcMgr::ContentCache::operator= ( const ContentCache RHS)
delete

◆ setBuffer()

void clang::SrcMgr::ContentCache::setBuffer ( std::unique_ptr< llvm::MemoryBuffer >  B)
inline

Set the buffer.

Definition at line 258 of file SourceManager.h.

References IsBufferInvalid.

Referenced by clang::SourceManager::overrideFileContents(), and setUnownedBuffer().

◆ setUnownedBuffer()

void clang::SrcMgr::ContentCache::setUnownedBuffer ( std::optional< llvm::MemoryBufferRef >  B)
inline

Set the buffer to one that's not owned (or to nullptr).

Precondition
Buffer cannot already be set.

Definition at line 266 of file SourceManager.h.

References setBuffer().

Member Data Documentation

◆ BufferOverridden

unsigned clang::SrcMgr::ContentCache::BufferOverridden

Indicates whether the buffer itself was provided to override the actual file contents.

When true, the original entry may be a virtual file that does not exist.

Definition at line 171 of file SourceManager.h.

Referenced by clang::SourceManager::overrideFileContents(), and clang::ASTReader::ReadSLocEntry().

◆ ContentsEntry

OptionalFileEntryRef clang::SrcMgr::ContentCache::ContentsEntry

References the file which the contents were actually loaded from.

Can be different from 'Entry' if we overridden the contents of one file with the contents of another file.

Definition at line 152 of file SourceManager.h.

Referenced by ContentCache(), clang::SourceManager::createFileID(), getBufferOrNone(), getSize(), and clang::ASTReader::ReadSLocEntry().

◆ Filename

StringRef clang::SrcMgr::ContentCache::Filename

The filename that is used to access OrigEntry.

FIXME: Remove this once OrigEntry is a FileEntryRef with a stable name.

Definition at line 157 of file SourceManager.h.

Referenced by clang::SrcMgr::FileInfo::get(), and clang::SrcMgr::FileInfo::getName().

◆ IsBufferInvalid

unsigned clang::SrcMgr::ContentCache::IsBufferInvalid
mutable

Definition at line 185 of file SourceManager.h.

Referenced by getBufferOrNone(), and setBuffer().

◆ IsFileVolatile

unsigned clang::SrcMgr::ContentCache::IsFileVolatile

True if this content cache was initially created for a source file considered to be volatile (likely to change between stat and open).

Definition at line 176 of file SourceManager.h.

Referenced by getBufferOrNone().

◆ IsTransient

unsigned clang::SrcMgr::ContentCache::IsTransient

True if this file may be transient, that is, if it might not exist at some later point in time when this content entry is used, after serialization and deserialization.

Definition at line 182 of file SourceManager.h.

Referenced by clang::SourceManager::setFileIsTransient().

◆ OrigEntry

OptionalFileEntryRef clang::SrcMgr::ContentCache::OrigEntry

Reference to the file entry representing this ContentCache.

This reference does not own the FileEntry object.

It is possible for this to be NULL if the ContentCache encapsulates an imaginary text buffer.

FIXME: Make non-optional using a virtual file as needed, remove Filename and use OrigEntry.getNameAsRequested() instead.

Definition at line 146 of file SourceManager.h.

Referenced by ContentCache(), clang::SourceManager::getFileEntryForSLocEntry(), clang::SourceManager::getNonBuiltinFilenameForID(), clang::SourceManager::initializeForReplay(), clang::ASTReader::ReadSLocEntry(), and clang::SourceManager::translateFile().

◆ SourceLineCache

LineOffsetMapping clang::SrcMgr::ContentCache::SourceLineCache
mutable

A bump pointer allocated array of offsets for each source line.

This is lazily computed. The lines are owned by the SourceManager BumpPointerAllocator object.

Definition at line 163 of file SourceManager.h.

Referenced by ContentCache(), clang::SourceManager::getColumnNumber(), clang::SourceManager::getLineNumber(), clang::ScratchBuffer::getToken(), clang::Rewriter::IncreaseIndentation(), clang::Rewriter::InsertText(), and clang::SourceManager::translateLineCol().


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