GCC Middle and Back End API Reference
|
#include <input.h>
Data Structures | |
struct | input_context |
Public Member Functions | |
file_cache () | |
~file_cache () | |
file_cache_slot * | lookup_or_add_file (const char *file_path) |
void | forcibly_evict_file (const char *file_path) |
void | initialize_input_context (diagnostic_input_charset_callback ccb, bool should_skip_bom) |
char_span | get_source_file_content (const char *file_path) |
char_span | get_source_line (const char *file_path, int line) |
bool | missing_trailing_newline_p (const char *file_path) |
Private Member Functions | |
file_cache_slot * | evicted_cache_tab_entry (unsigned *highest_use_count) |
file_cache_slot * | add_file (const char *file_path) |
file_cache_slot * | lookup_file (const char *file_path) |
Private Attributes | |
file_cache_slot * | m_file_slots |
input_context | m_input_context |
Static Private Attributes | |
static const size_t | num_file_slots = 16 |
A cache of source files for use when emitting diagnostics (and in a few places in the C/C++ frontends). Results are only valid until the next call to the cache, as slots can be evicted. Filenames are stored by pointer, and so must outlive the cache instance.
file_cache::file_cache | ( | ) |
file_cache's ctor.
References initialize_input_context().
file_cache::~file_cache | ( | ) |
file_cache's dtor.
References m_file_slots.
|
private |
Create the cache used for the content of a given file to be accessed by caret diagnostic. This cache is added to an array of cache and can be retrieved by lookup_file_in_cache_tab. This function returns the created cache. Note that only the last num_file_slots files are cached. This can return nullptr if the FILE_PATH can't be opened for reading, or if the content can't be converted to the input_charset.
References evicted_cache_tab_entry(), fopen, m_input_context, NULL, and r.
Referenced by lookup_or_add_file().
|
private |
Return the file cache that has been less used, recently, or the first empty one. If HIGHEST_USE_COUNT is non-null, *HIGHEST_USE_COUNT is set to the highest use count of the entries in the cache table.
References file_cache_slot::get_file_path(), file_cache_slot::get_use_count(), i, m_file_slots, NULL, and num_file_slots.
Referenced by add_file().
void file_cache::forcibly_evict_file | ( | const char * | file_path | ) |
Purge any mention of FILENAME from the cache of files used for printing source code. For use in selftests when working with tempfiles.
References gcc_assert, lookup_file(), and r.
char_span file_cache::get_source_file_content | ( | const char * | file_path | ) |
References file_cache_slot::get_full_file_content(), and lookup_or_add_file().
Referenced by sarif_builder::maybe_make_artifact_content_object().
char_span file_cache::get_source_line | ( | const char * | file_path, |
int | line ) |
Return the physical source line that corresponds to FILE_PATH/LINE. The line is not nul-terminated. The returned pointer is only valid until the next call of location_get_source_line. Note that the line can contain several null characters, so the returned value's length has the actual length of the line. If the function fails, a NULL char_span is returned.
References lookup_or_add_file(), NULL, and file_cache_slot::read_line_num().
Referenced by asm_show_source(), blank_line_before_p(), dump_location_info(), edited_line::edited_line(), edited_file::get_num_lines(), sarif_builder::get_source_lines(), get_source_text_between(), get_substring_ranges_for_loc(), location_compute_display_column(), edited_file::print_content(), edited_file::print_diff_hunk(), and edited_file::print_run_of_changed_lines().
void file_cache::initialize_input_context | ( | diagnostic_input_charset_callback | ccb, |
bool | should_skip_bom ) |
References file_cache::input_context::ccb, default_charset_callback(), m_input_context, and file_cache::input_context::should_skip_bom.
Referenced by file_cache(), and diagnostic_context::initialize_input_context().
|
private |
Lookup the cache used for the content of a given file accessed by caret diagnostic. Return the found cached file, or NULL if no cached file was found.
References gcc_assert, file_cache_slot::get_file_path(), i, file_cache_slot::inc_use_count(), m_file_slots, NULL, num_file_slots, and r.
Referenced by forcibly_evict_file(), and lookup_or_add_file().
file_cache_slot * file_cache::lookup_or_add_file | ( | const char * | file_path | ) |
Lookup the cache used for the content of a given file accessed by caret diagnostic. If no cached file was found, create a new cache for this file, add it to the array of cached file and return it. This can return nullptr on a cache miss if FILE_PATH can't be opened for reading, or if the content can't be converted to the input_charset.
References add_file(), lookup_file(), NULL, and r.
Referenced by get_source_file_content(), get_source_line(), and missing_trailing_newline_p().
bool file_cache::missing_trailing_newline_p | ( | const char * | file_path | ) |
Determine if FILE_PATH missing a trailing newline on its final line. Only valid to call once all of the file has been loaded, by requesting a line number beyond the end of the file.
References gcc_assert, lookup_or_add_file(), and r.
Referenced by edited_file::get_num_lines().
|
private |
Referenced by evicted_cache_tab_entry(), lookup_file(), and ~file_cache().
|
private |
Referenced by add_file(), and initialize_input_context().
|
staticprivate |
Referenced by evicted_cache_tab_entry(), and lookup_file().