GCC Middle and Back End API Reference
file_cache_slot Class Reference
Collaboration diagram for file_cache_slot:

Data Structures

class  line_info
 

Public Member Functions

 file_cache_slot ()
 
 ~file_cache_slot ()
 
void dump (FILE *out, int indent) const
 
void DEBUG_FUNCTION dump () const
 
bool read_line_num (size_t line_num, char **line, ssize_t *line_len)
 
const char * get_file_path () const
 
unsigned get_use_count () const
 
bool missing_trailing_newline_p () const
 
char_span get_full_file_content ()
 
void inc_use_count ()
 
bool create (const file_cache::input_context &in_context, const char *file_path, FILE *fp, unsigned highest_use_count)
 
void evict ()
 
void set_content (const char *buf, size_t sz)
 

Static Public Member Functions

static void tune (size_t line_record_size_)
 

Private Member Functions

bool needs_read_p () const
 
bool needs_grow_p () const
 
void maybe_grow ()
 
bool read_data ()
 
bool maybe_read_data ()
 
bool get_next_line (char **line, ssize_t *line_len)
 
bool read_next_line (char **line, ssize_t *line_len)
 
bool goto_next_line ()
 
void offset_buffer (int offset)
 

Private Attributes

unsigned m_use_count
 
const char * m_file_path
 
FILE * m_fp
 
bool m_error
 
char * m_data
 
int m_alloc_offset
 
size_t m_size
 
size_t m_nb_read
 
size_t m_line_start_idx
 
size_t m_line_num
 
bool m_missing_trailing_newline
 
vec< line_info, va_heapm_line_record
 
vec< line_info, va_heapm_line_recent
 
size_t m_line_recent_last
 
size_t m_line_recent_first
 

Static Private Attributes

static const size_t buffer_size = 4 * 1024
 
static size_t line_record_size = 0
 
static size_t recent_cached_lines_shift = 8
 

Detailed Description

This is a cache used by get_next_line to store the content of a
file to be searched for file lines.   

Constructor & Destructor Documentation

◆ file_cache_slot()

file_cache_slot::file_cache_slot ( )

◆ ~file_cache_slot()

file_cache_slot::~file_cache_slot ( )
Destructor for a cache of file used by caret diagnostic.   

References m_alloc_offset, m_data, m_fp, m_line_recent, m_line_record, NULL, and offset_buffer().

Member Function Documentation

◆ create()

bool file_cache_slot::create ( const file_cache::input_context & in_context,
const char * file_path,
FILE * fp,
unsigned highest_use_count )

◆ dump() [1/2]

void DEBUG_FUNCTION file_cache_slot::dump ( ) const
inline

References DEBUG_FUNCTION, and dump().

Referenced by dump().

◆ dump() [2/2]

void file_cache_slot::dump ( FILE * out,
int indent ) const

◆ evict()

◆ get_file_path()

const char * file_cache_slot::get_file_path ( ) const
inline

◆ get_full_file_content()

char_span file_cache_slot::get_full_file_content ( )
Get a borrowed char_span to the full content of this file
as decoded according to the input charset, encoded as UTF-8.   

References get_next_line(), m_data, and m_nb_read.

Referenced by file_cache::get_source_file_content().

◆ get_next_line()

bool file_cache_slot::get_next_line ( char ** line,
ssize_t * line_len )
private
Read a new line from file FP, using C as a cache for the data
coming from the file.  Upon successful completion, *LINE is set to
the beginning of the line found.  *LINE points directly in the
line cache and is only valid until the next call of get_next_line.
*LINE_LEN is set to the length of the line.  Note that the line
does not contain any terminal delimiter.  This function returns
true if some data was read or process from the cache, false
otherwise.  Note that subsequent calls to get_next_line might
make the content of *LINE invalid.   

References find_end_of_line(), gcc_assert, i, line_record_size, line_start(), m_data, m_error, m_line_num, m_line_recent, m_line_recent_first, m_line_recent_last, m_line_record, m_line_start_idx, m_missing_trailing_newline, m_nb_read, maybe_read_data(), NULL, and recent_cached_lines_shift.

Referenced by get_full_file_content(), goto_next_line(), and read_line_num().

◆ get_use_count()

unsigned file_cache_slot::get_use_count ( ) const
inline

◆ goto_next_line()

bool file_cache_slot::goto_next_line ( )
private
Consume the next bytes coming from the cache (or from its
underlying file if there are remaining unread bytes in the file)
until we reach the next end-of-line (or end-of-file).  There is no
copying from the cache involved.  Return TRUE upon successful
completion.   

References get_next_line().

Referenced by read_line_num().

◆ inc_use_count()

void file_cache_slot::inc_use_count ( )
inline

References m_use_count.

Referenced by file_cache::lookup_file().

◆ maybe_grow()

void file_cache_slot::maybe_grow ( )
private
Grow the cache if it needs to be extended.   

References buffer_size, gcc_assert, m_alloc_offset, m_data, m_size, needs_grow_p(), and offset_buffer().

Referenced by read_data().

◆ maybe_read_data()

bool file_cache_slot::maybe_read_data ( )
private
Read new data iff the cache needs to be filled with more data
coming from the file FP.  Return TRUE iff the cache was filled with
mode data.   

References needs_read_p(), and read_data().

Referenced by get_next_line().

◆ missing_trailing_newline_p()

bool file_cache_slot::missing_trailing_newline_p ( ) const
inline

◆ needs_grow_p()

bool file_cache_slot::needs_grow_p ( ) const
private
Return TRUE iff the cache is full and thus needs to be
extended.   

References m_nb_read, and m_size.

Referenced by dump(), and maybe_grow().

◆ needs_read_p()

bool file_cache_slot::needs_read_p ( ) const
private
Returns TRUE iff the cache would need to be filled with data coming
from the file.  That is, either the cache is empty or full or the
current line is empty.  Note that if the cache is full, it would
need to be extended and filled again.   

References m_fp, m_line_start_idx, m_nb_read, and m_size.

Referenced by dump(), and maybe_read_data().

◆ offset_buffer()

void file_cache_slot::offset_buffer ( int offset)
inlineprivate

◆ read_data()

bool file_cache_slot::read_data ( )
private
Read more data into the cache.  Extends the cache if need be.
Returns TRUE iff new data could be read.   

References m_data, m_error, m_fp, m_nb_read, m_size, and maybe_grow().

Referenced by create(), and maybe_read_data().

◆ read_line_num()

bool file_cache_slot::read_line_num ( size_t line_num,
char ** line,
ssize_t * line_len )
Read an arbitrary line number LINE_NUM from the file cached in C.
If the line was read successfully, *LINE points to the beginning
of the line in the file cache and *LINE_LEN is the length of the
line.  *LINE is not nul-terminated, but may contain zero bytes.
*LINE is only valid until the next call of read_line_num.
This function returns bool if a line was read.   

References file_cache_slot::line_info::end_pos, gcc_assert, get_next_line(), goto_next_line(), i, last, file_cache_slot::line_info::less_than(), file_cache_slot::line_info::line_num, m_data, m_line_num, m_line_recent, m_line_recent_first, m_line_recent_last, m_line_record, m_line_start_idx, recent_cached_lines_shift, and file_cache_slot::line_info::start_pos.

Referenced by file_cache::get_source_line().

◆ read_next_line()

bool file_cache_slot::read_next_line ( char ** line,
ssize_t * line_len )
private

◆ set_content()

void file_cache_slot::set_content ( const char * buf,
size_t sz )

References m_alloc_offset, m_data, m_fp, m_nb_read, and m_size.

◆ tune()

static void file_cache_slot::tune ( size_t line_record_size_)
inlinestatic

References line_record_size.

Referenced by file_cache::tune().

Field Documentation

◆ buffer_size

const size_t file_cache_slot::buffer_size = 4 * 1024
staticprivate

Referenced by maybe_grow().

◆ line_record_size

size_t file_cache_slot::line_record_size = 0
staticprivate

Referenced by get_next_line(), and tune().

◆ m_alloc_offset

int file_cache_slot::m_alloc_offset
private

◆ m_data

◆ m_error

bool file_cache_slot::m_error
private

◆ m_file_path

const char* file_cache_slot::m_file_path
private

◆ m_fp

FILE* file_cache_slot::m_fp
private

◆ m_line_num

size_t file_cache_slot::m_line_num
private

◆ m_line_recent

vec<line_info, va_heap> file_cache_slot::m_line_recent
private

◆ m_line_recent_first

size_t file_cache_slot::m_line_recent_first
private

◆ m_line_recent_last

size_t file_cache_slot::m_line_recent_last
private

◆ m_line_record

vec<line_info, va_heap> file_cache_slot::m_line_record
private

◆ m_line_start_idx

size_t file_cache_slot::m_line_start_idx
private

◆ m_missing_trailing_newline

bool file_cache_slot::m_missing_trailing_newline
private

◆ m_nb_read

◆ m_size

size_t file_cache_slot::m_size
private

◆ m_use_count

unsigned file_cache_slot::m_use_count
private

◆ recent_cached_lines_shift

size_t file_cache_slot::recent_cached_lines_shift = 8
staticprivate

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