clang  14.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"

Collaboration diagram for clang::SrcMgr::ContentCache:
Collaboration graph
[legend]

Public Member Functions

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

Static Public Member Functions

static const char * getInvalidBOM (StringRef BufStr)
 

Public Attributes

const FileEntryOrigEntry
 Reference to the file entry representing this ContentCache. More...
 
const FileEntryContentsEntry
 References the file which the contents were actually loaded from. More...
 
StringRef Filename
 The filename that is used to access OrigEntry. More...
 
LineOffsetMapping SourceLineCache
 A bump pointer allocated array of offsets for each source line. More...
 
unsigned BufferOverridden: 1
 Indicates whether the buffer itself was provided to override the actual file contents. More...
 
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). More...
 
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. More...
 
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 128 of file SourceManager.h.

Constructor & Destructor Documentation

◆ ContentCache() [1/3]

clang::SrcMgr::ContentCache::ContentCache ( const FileEntry Ent = nullptr)
inline

Definition at line 179 of file SourceManager.h.

◆ ContentCache() [2/3]

clang::SrcMgr::ContentCache::ContentCache ( const FileEntry Ent,
const FileEntry contentEnt 
)
inline

Definition at line 181 of file SourceManager.h.

◆ ContentCache() [3/3]

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 188 of file SourceManager.h.

References ContentsEntry, OrigEntry, and SourceLineCache.

Member Function Documentation

◆ getBufferDataIfLoaded()

llvm::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 238 of file SourceManager.h.

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

◆ getBufferIfLoaded()

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

Return the buffer, only if it has been loaded.

Definition at line 230 of file SourceManager.h.

◆ getBufferOrNone()

llvm::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 104 of file SourceManager.cpp.

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

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 80 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 61 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 75 of file SourceManager.cpp.

References ContentsEntry, and clang::FileEntry::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 55 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 245 of file SourceManager.h.

References IsBufferInvalid.

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

◆ setUnownedBuffer()

void clang::SrcMgr::ContentCache::setUnownedBuffer ( llvm::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 253 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 166 of file SourceManager.h.

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

◆ ContentsEntry

const FileEntry* 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 148 of file SourceManager.h.

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

◆ 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 153 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 177 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 170 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 175 of file SourceManager.h.

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

◆ OrigEntry

const FileEntry* 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: Turn this into a FileEntryRef and remove Filename.

Definition at line 142 of file SourceManager.h.

Referenced by ContentCache(), clang::SourceManager::getFileEntryForSLocEntry(), clang::SourceManager::getNonBuiltinFilenameForID(), clang::SourceManager::initializeForReplay(), 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 159 of file SourceManager.h.

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


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