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 ()
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 ()

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
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
size_t m_total_lines
bool m_missing_trailing_newline
vec< line_info, va_heapm_line_record

Static Private Attributes

static const size_t buffer_size = 4 * 1024
static const size_t line_record_size = 100

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 ( )
Default constructor for a cache of file used by caret

References m_line_record.

◆ ~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_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 )

◆ evict()

◆ get_file_path()

const char * file_cache_slot::get_file_path ( ) const

◆ 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 )
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, line_record_size, line_start(), m_data, m_fp, m_line_num, m_line_record, m_line_start_idx, m_missing_trailing_newline, m_nb_read, m_total_lines, maybe_read_data(), and NULL.

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

◆ get_use_count()

unsigned file_cache_slot::get_use_count ( ) const

◆ goto_next_line()

bool file_cache_slot::goto_next_line ( )
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

References get_next_line().

Referenced by read_line_num().

◆ inc_use_count()

void file_cache_slot::inc_use_count ( )

References m_use_count.

Referenced by file_cache::lookup_file().

◆ maybe_grow()

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

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

Referenced by read_data().

◆ maybe_read_data()

bool file_cache_slot::maybe_read_data ( )
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

◆ needs_grow_p()

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

References m_nb_read, and m_size.

Referenced by maybe_grow().

◆ needs_read_p()

bool file_cache_slot::needs_read_p ( ) const
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 maybe_read_data().

◆ offset_buffer()

void file_cache_slot::offset_buffer ( int offset)

◆ read_data()

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

References m_data, 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 gcc_assert, get_next_line(), goto_next_line(), i, line_record_size, m_data, m_line_num, m_line_record, m_line_start_idx, m_total_lines, and NULL.

Referenced by file_cache::get_source_line().

◆ read_next_line()

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

Field Documentation

◆ buffer_size

const size_t file_cache_slot::buffer_size = 4 * 1024

Referenced by maybe_grow().

◆ line_record_size

const size_t file_cache_slot::line_record_size = 100

Referenced by get_next_line(), and read_line_num().

◆ m_alloc_offset

int file_cache_slot::m_alloc_offset

◆ m_data

◆ m_file_path

const char* file_cache_slot::m_file_path

Referenced by create(), evict(), and get_file_path().

◆ m_fp

FILE* file_cache_slot::m_fp

◆ m_line_num

size_t file_cache_slot::m_line_num

◆ m_line_record

vec<line_info, va_heap> file_cache_slot::m_line_record

◆ m_line_start_idx

size_t file_cache_slot::m_line_start_idx

◆ m_missing_trailing_newline

bool file_cache_slot::m_missing_trailing_newline

◆ m_nb_read

size_t file_cache_slot::m_nb_read

◆ m_size

size_t file_cache_slot::m_size

◆ m_total_lines

size_t file_cache_slot::m_total_lines

◆ m_use_count

unsigned file_cache_slot::m_use_count

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