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

Public Member Functions

 edited_line (file_cache &fc, const char *filename, int line_num)
 
 ~edited_line ()
 
int get_line_num () const
 
const char * get_content () const
 
int get_len () const
 
int get_effective_column (int orig_column) const
 
bool apply_fixit (int start_column, int next_column, const char *replacement_str, int replacement_len)
 
int get_effective_line_count () const
 
bool actually_edited_p () const
 
void print_content (pretty_printer *pp) const
 
void print_diff_lines (pretty_printer *pp) const
 

Static Public Member Functions

static void delete_cb (edited_line *el)
 

Private Member Functions

void ensure_capacity (int len)
 
void ensure_terminated ()
 

Private Attributes

int m_line_num
 
char * m_content
 
int m_len
 
int m_alloc_sz
 
auto_vec< line_eventm_line_events
 
auto_vec< added_line * > m_predecessors
 

Detailed Description

The state of one edited line within an edited_file.
As well as the current content of the line, it contains a record of
the changes, so that further changes can be applied in the correct
place.

When handling fix-it hints containing newlines, new lines are added
as added_line predecessors to an edited_line.  Hence it's possible
for an "edited_line" to not actually have been changed, but to merely
be a placeholder for the lines added before it.  This can be tested
for with actuall_edited_p, and has a slight effect on how diff hunks
are generated.   

Constructor & Destructor Documentation

◆ edited_line()

edited_line::edited_line ( file_cache & fc,
const char * filename,
int line_num )
Implementation of class edited_line.   
edited_line's ctor.   

References ensure_capacity(), ensure_terminated(), char_span::get_buffer(), file_cache::get_source_line(), char_span::length(), m_content, and m_len.

◆ ~edited_line()

edited_line::~edited_line ( )
edited_line's dtor.   

References FOR_EACH_VEC_ELT, free(), i, m_content, and m_predecessors.

Member Function Documentation

◆ actually_edited_p()

bool edited_line::actually_edited_p ( ) const
inline

◆ apply_fixit()

bool edited_line::apply_fixit ( 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 the 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.
Return true if successful; false if an error occurred.   

References ensure_capacity(), ensure_terminated(), gcc_assert, get_effective_column(), m_content, m_len, m_line_events, and m_predecessors.

◆ delete_cb()

void edited_line::delete_cb ( edited_line * el)
static
A callback for deleting edited_line *, for use as a
delete_value_fn for edited_file::m_edited_lines.   

◆ ensure_capacity()

void edited_line::ensure_capacity ( int len)
private
Ensure that the buffer for m_content is at least large enough to hold
a string of length LEN and its 0-terminator, doubling on repeated
allocations.   

References m_alloc_sz, and m_content.

Referenced by apply_fixit(), and edited_line().

◆ ensure_terminated()

void edited_line::ensure_terminated ( )
private
Ensure that m_content is 0-terminated.   

References gcc_assert, m_alloc_sz, m_content, and m_len.

Referenced by apply_fixit(), and edited_line().

◆ get_content()

const char * edited_line::get_content ( ) const
inline

References m_content.

◆ get_effective_column()

int edited_line::get_effective_column ( int orig_column) const
Map a location before the edits to a column number after the edits,
within a specific line.   

References FOR_EACH_VEC_ELT, line_event::get_effective_column(), i, and m_line_events.

Referenced by apply_fixit().

◆ get_effective_line_count()

int edited_line::get_effective_line_count ( ) const
Determine the number of lines that will be present after
editing for this line.  Typically this is just 1, but
if newlines have been added before this line, they will
also be counted.   

References m_predecessors.

◆ get_len()

int edited_line::get_len ( ) const
inline

References m_len.

◆ get_line_num()

int edited_line::get_line_num ( ) const
inline

References m_line_num.

Referenced by edited_file::print_diff().

◆ print_content()

void edited_line::print_content ( pretty_printer * pp) const
Subroutine of edited_file::print_content.
Print this line and any new lines added before it, to PP.   

References FOR_EACH_VEC_ELT, added_line::get_content(), i, m_content, m_predecessors, pp_newline(), and pp_string().

◆ print_diff_lines()

void edited_line::print_diff_lines ( pretty_printer * pp) const
Subroutine of edited_file::print_run_of_changed_lines for
printing diff hunks to PP.
Print the '+' line for this line, and any newlines added
before it.
Note that if this edited_line was actually edited, the '-'
line has already been printed.  If it wasn't, then we merely
have a placeholder edited_line for adding newlines to, and
we need to print a ' ' line for the edited_line as we haven't
printed it yet.   

References actually_edited_p(), FOR_EACH_VEC_ELT, added_line::get_content(), added_line::get_len(), i, m_content, m_len, m_predecessors, and print_diff_line().

Referenced by edited_file::print_run_of_changed_lines().

Field Documentation

◆ m_alloc_sz

int edited_line::m_alloc_sz
private

◆ m_content

◆ m_len

int edited_line::m_len
private

◆ m_line_events

auto_vec<line_event> edited_line::m_line_events
private

◆ m_line_num

int edited_line::m_line_num
private

Referenced by get_line_num().

◆ m_predecessors

auto_vec<added_line *> edited_line::m_predecessors
private

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