clang  6.0.0svn
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
 
 ~ContentCache ()
 
llvm::MemoryBuffer * getBuffer (DiagnosticsEngine &Diag, const SourceManager &SM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) 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::MemoryBuffer * getRawBuffer () const
 Get the underlying buffer, returning NULL if the buffer is not yet available. More...
 
void replaceBuffer (llvm::MemoryBuffer *B, bool DoNotFree=false)
 Replace the existing buffer (which will be deleted) with the given buffer. More...
 
bool isBufferInvalid () const
 Determine whether the buffer itself is invalid. More...
 
bool shouldFreeBuffer () const
 Determine whether the buffer should be freed. More...
 

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...
 
unsigned * SourceLineCache = nullptr
 A bump pointer allocated array of offsets for each source line. More...
 
unsigned NumLines = 0
 The number of lines in this ContentCache. More...
 
unsigned BufferOverridden: 1
 Indicates whether the buffer itself was provided to override the actual file contents. More...
 
unsigned IsSystemFile: 1
 True if this content cache was initially created for a source file considered as a system one. 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...
 

Detailed Description

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

This object owns the MemoryBuffer object.

Definition at line 95 of file SourceManager.h.

Constructor & Destructor Documentation

◆ ContentCache() [1/3]

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

Definition at line 153 of file SourceManager.h.

◆ ContentCache() [2/3]

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

Definition at line 155 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 162 of file SourceManager.h.

References ContentsEntry, Diag(), NumLines, OrigEntry, SM, and SourceLineCache.

◆ ~ContentCache()

ContentCache::~ContentCache ( )

Definition at line 53 of file SourceManager.cpp.

References shouldFreeBuffer().

Member Function Documentation

◆ getBuffer()

llvm::MemoryBuffer * ContentCache::getBuffer ( DiagnosticsEngine Diag,
const SourceManager SM,
SourceLocation  Loc = SourceLocation(),
bool Invalid = nullptr 
) const

◆ 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 66 of file SourceManager.cpp.

◆ getRawBuffer()

llvm::MemoryBuffer* clang::SrcMgr::ContentCache::getRawBuffer ( ) const
inline

Get the underlying buffer, returning NULL if the buffer is not yet available.

Definition at line 213 of file SourceManager.h.

Referenced by getBuffer().

◆ 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::FileEntry::getSize().

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

◆ 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 60 of file SourceManager.cpp.

◆ isBufferInvalid()

bool clang::SrcMgr::ContentCache::isBufferInvalid ( ) const
inline

Determine whether the buffer itself is invalid.

Definition at line 220 of file SourceManager.h.

Referenced by getBuffer().

◆ operator=()

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

◆ replaceBuffer()

void ContentCache::replaceBuffer ( llvm::MemoryBuffer *  B,
bool  DoNotFree = false 
)

Replace the existing buffer (which will be deleted) with the given buffer.

Definition at line 86 of file SourceManager.cpp.

References shouldFreeBuffer().

◆ shouldFreeBuffer()

bool clang::SrcMgr::ContentCache::shouldFreeBuffer ( ) const
inline

Determine whether the buffer should be freed.

Definition at line 225 of file SourceManager.h.

Referenced by replaceBuffer(), and ~ContentCache().

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

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

Referenced by ContentCache(), getBuffer(), and getSize().

◆ IsSystemFile

unsigned clang::SrcMgr::ContentCache::IsSystemFile

True if this content cache was initially created for a source file considered as a system one.

Definition at line 146 of file SourceManager.h.

Referenced by getBuffer().

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

◆ NumLines

unsigned clang::SrcMgr::ContentCache::NumLines = 0

The number of lines in this ContentCache.

This is only valid if SourceLineCache is non-null.

Definition at line 135 of file SourceManager.h.

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

◆ 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.

Definition at line 118 of file SourceManager.h.

Referenced by ContentCache(), clang::SourceManager::disableFileContentsOverride(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileEntryForSLocEntry(), clang::SourceManager::getPresumedLoc(), clang::ASTImporter::Import(), clang::SourceManager::initializeForReplay(), and clang::SourceManager::translateFile().

◆ SourceLineCache

unsigned* clang::SrcMgr::ContentCache::SourceLineCache = nullptr

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

This is lazily computed. This is owned by the SourceManager BumpPointerAllocator object.

Definition at line 130 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: