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

Public Member Functions

 edited_file (edit_context &ec, const char *filename)
 
const charget_filename () const
 
charget_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 (edited_file *file)
 
static int call_print_diff (const char *, edited_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)
 
edited_lineget_line (int line)
 
edited_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

edit_contextm_edit_context
 
const charm_filename
 
typed_splay_tree< int, edited_line * > m_edited_lines
 
int m_num_lines
 

Detailed Description

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

Constructor & Destructor Documentation

◆ edited_file()

edited_file::edited_file ( edit_context & ec,
const char * filename )
edited_file's constructor.   

Member Function Documentation

◆ apply_fixit()

bool edited_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(), and ggc_alloc().

Referenced by edit_context::apply_fixit().

◆ call_print_diff()

static int edited_file::call_print_diff ( const char * ,
edited_file * file,
void * user_data )
inlinestatic

◆ delete_cb()

void edited_file::delete_cb ( edited_file * file)
static
A callback for deleting edited_file *, for use as a
delete_value_fn for edit_context::m_files.   

◆ get_content()

char * edited_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 edit_context::get_content().

◆ get_effective_column()

int edited_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 edit_context::get_effective_column().

◆ get_effective_line_count()

int edited_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(), and ggc_alloc().

Referenced by print_diff_hunk().

◆ get_file_cache()

◆ get_filename()

const char * edited_file::get_filename ( ) const
inline

References m_filename.

◆ get_line()

edited_line * edited_file::get_line ( int line)
private

◆ get_num_lines()

int edited_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(), file_cache::get_source_line(), ggc_alloc(), m_filename, m_num_lines, and file_cache::missing_trailing_newline_p().

Referenced by print_content(), and print_diff().

◆ get_or_insert_line()

edited_line * edited_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(), typed_splay_tree< KEY_TYPE, VALUE_TYPE >::insert(), m_edited_lines, m_filename, and NULL.

Referenced by apply_fixit().

◆ print_content()

bool edited_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(), file_cache::get_source_line(), ggc_alloc(), i, char_span::length(), m_filename, and pp_character().

Referenced by get_content().

◆ print_diff()

void edited_file::print_diff ( pretty_printer * pp,
bool show_filenames )
private

◆ print_diff_hunk()

int edited_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(), get_effective_line_count(), get_file_cache(), get_line(), file_cache::get_source_line(), ggc_alloc(), m_filename, pp_printf(), pp_show_color, pp_string(), print_diff_line(), and print_run_of_changed_lines().

Referenced by print_diff().

◆ print_run_of_changed_lines()

void edited_file::print_run_of_changed_lines ( pretty_printer * pp,
int start_of_run,
int end_of_run )
private
Subroutine of edited_file::print_diff_hunk: given a run of lines
from START_OF_RUN to END_OF_RUN that all have edited_line instances,
print the diff to PP.   

References colorize_start(), colorize_stop(), gcc_assert, get_file_cache(), get_line(), file_cache::get_source_line(), ggc_alloc(), m_filename, pp_show_color, pp_string(), and print_diff_line().

Referenced by print_diff_hunk().

Field Documentation

◆ m_edit_context

edit_context& edited_file::m_edit_context
private

Referenced by get_file_cache().

◆ m_edited_lines

typed_splay_tree<int, edited_line *> edited_file::m_edited_lines
private

◆ m_filename

◆ m_num_lines

int edited_file::m_num_lines
private

Referenced by get_num_lines().


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