GCC Middle and Back End API Reference
diagnostics::changes::changed_file Class Reference
Collaboration diagram for diagnostics::changes::changed_file:

Public Member Functions

 changed_file (change_set &ec, const char *filename)
const char * get_filename () const
char * get_content ()
bool apply_fixit (int line, int start_column, int next_column, const char *replacement_str, int replacement_len)
int get_effective_column (int line, int column)
file_cacheget_file_cache () const

Static Public Member Functions

static void delete_cb (changed_file *file)
static int call_print_diff (const char *, changed_file *file, void *user_data)

Private Member Functions

bool print_content (pretty_printer *pp)
void print_diff (pretty_printer *pp, bool show_filenames)
int print_diff_hunk (pretty_printer *pp, int old_start_of_hunk, int old_end_of_hunk, int new_start_of_hunk)
changed_lineget_line (int line)
changed_lineget_or_insert_line (int line)
int get_num_lines (bool *missing_trailing_newline)
int get_effective_line_count (int old_start_of_hunk, int old_end_of_hunk)
void print_run_of_changed_lines (pretty_printer *pp, int start_of_run, int end_of_run)

Private Attributes

change_setm_change_set
const char * m_filename
typed_splay_tree< int, changed_line * > m_changed_lines
int m_num_lines

Detailed Description

The state of one named file within an change_set: the filename,
and the lines that have been edited so far.   

Constructor & Destructor Documentation

◆ changed_file()

diagnostics::changes::changed_file::changed_file ( change_set & ec,
const char * filename )

Member Function Documentation

◆ apply_fixit()

bool diagnostics::changes::changed_file::apply_fixit ( int line,
int start_column,
int next_column,
const char * replacement_str,
int replacement_len )
Attempt to replace columns START_COLUMN up to but not including NEXT_COLUMN
of LINE with the string REPLACEMENT_STR of length REPLACEMENT_LEN,
updating the in-memory copy of the line, and the record of edits to
the line.   

References get_or_insert_line().

Referenced by diagnostics::changes::change_set::apply_fixit().

◆ call_print_diff()

int diagnostics::changes::changed_file::call_print_diff ( const char * ,
changed_file * file,
void * user_data )
inlinestatic

◆ delete_cb()

void diagnostics::changes::changed_file::delete_cb ( changed_file * file)
static
A callback for deleting changed_file *, for use as a
delete_value_fn for change_set::m_files.   

References changed_file().

Referenced by changed_file().

◆ get_content()

char * diagnostics::changes::changed_file::get_content ( )
Get the content of the file, with fix-its applied.
The ptr should be freed by the caller.   

References NULL, pp_formatted_text(), and print_content().

Referenced by diagnostics::changes::change_set::get_content().

◆ get_effective_column()

int diagnostics::changes::changed_file::get_effective_column ( int line,
int column )
Given line LINE, map from COLUMN in the input file to its current
column after edits have been applied.   

References get_line().

Referenced by diagnostics::changes::change_set::get_effective_column().

◆ get_effective_line_count()

int diagnostics::changes::changed_file::get_effective_line_count ( int old_start_of_hunk,
int old_end_of_hunk )
private
Determine the number of lines that will be present after
editing for the range of lines from OLD_START_OF_HUNK to
OLD_END_OF_HUNK inclusive.   

References get_line().

Referenced by print_diff_hunk().

◆ get_file_cache()

file_cache & diagnostics::changes::changed_file::get_file_cache ( ) const
inline

◆ get_filename()

const char * diagnostics::changes::changed_file::get_filename ( ) const
inline

References m_filename.

◆ get_line()

changed_line * diagnostics::changes::changed_file::get_line ( int line)
private
Get the state of LINE within the file, or NULL if it is untouched.   

References m_changed_lines.

Referenced by get_effective_column(), get_effective_line_count(), get_or_insert_line(), print_content(), print_diff_hunk(), and print_run_of_changed_lines().

◆ get_num_lines()

int diagnostics::changes::changed_file::get_num_lines ( bool * missing_trailing_newline)
private
Get the total number of lines in m_content, writing
true to *MISSING_TRAILING_NEWLINE if the final line
if missing a newline, false otherwise.   

References gcc_assert, get_file_cache(), diagnostics::file_cache::get_source_line(), m_filename, m_num_lines, and diagnostics::file_cache::missing_trailing_newline_p().

Referenced by print_content(), and print_diff().

◆ get_or_insert_line()

changed_line * diagnostics::changes::changed_file::get_or_insert_line ( int line)
private
Get the state of LINE within the file, creating a state for it
if necessary.  Return NULL if an error occurs.   

References get_file_cache(), get_line(), m_changed_lines, m_filename, and NULL.

Referenced by apply_fixit().

◆ print_content()

bool diagnostics::changes::changed_file::print_content ( pretty_printer * pp)
private
Attempt to print the content of the file to PP, with edits applied.
Return true if successful, false otherwise.   

References get_file_cache(), get_line(), get_num_lines(), diagnostics::file_cache::get_source_line(), i, diagnostics::char_span::length(), m_filename, and pp_character().

Referenced by get_content().

◆ print_diff()

void diagnostics::changes::changed_file::print_diff ( pretty_printer * pp,
bool show_filenames )
private
Print a unified diff to PP, showing any changes that have occurred
to this file.   

References colorize_start(), colorize_stop(), diagnostics::changes::changed_line::get_line_num(), get_num_lines(), m_changed_lines, m_filename, pp_newline(), pp_show_color(), pp_string(), and print_diff_hunk().

Referenced by call_print_diff().

◆ print_diff_hunk()

int diagnostics::changes::changed_file::print_diff_hunk ( pretty_printer * pp,
int old_start_of_hunk,
int old_end_of_hunk,
int new_start_of_hunk )
private
Print one hunk within a unified diff to PP, covering the
given range of lines.  OLD_START_OF_HUNK and OLD_END_OF_HUNK are
line numbers in the unedited version of the file.
NEW_START_OF_HUNK is a line number in the edited version of the file.
Return the change in the line count within the hunk.   

References colorize_start(), colorize_stop(), diagnostics::char_span::get_buffer(), get_effective_line_count(), get_file_cache(), get_line(), diagnostics::file_cache::get_source_line(), diagnostics::char_span::length(), m_filename, pp_printf(), pp_show_color(), pp_string(), diagnostics::changes::print_diff_line(), and print_run_of_changed_lines().

Referenced by print_diff().

◆ print_run_of_changed_lines()

void diagnostics::changes::changed_file::print_run_of_changed_lines ( pretty_printer * pp,
int start_of_run,
int end_of_run )
private

Field Documentation

◆ m_change_set

change_set& diagnostics::changes::changed_file::m_change_set
private

Referenced by changed_file(), and get_file_cache().

◆ m_changed_lines

typed_splay_tree<int, changed_line *> diagnostics::changes::changed_file::m_changed_lines
private

◆ m_filename

const char* diagnostics::changes::changed_file::m_filename
private

◆ m_num_lines

int diagnostics::changes::changed_file::m_num_lines
private

Referenced by changed_file(), and get_num_lines().


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