GCC Middle and Back End API Reference
edit_context Class Reference

#include <edit-context.h>

Collaboration diagram for edit_context:

Public Member Functions

 edit_context (file_cache &)
 
bool valid_p () const
 
void add_fixits (rich_location *richloc)
 
char * get_content (const char *filename)
 
int get_effective_column (const char *filename, int line, int column)
 
char * generate_diff (bool show_filenames)
 
void print_diff (pretty_printer *pp, bool show_filenames)
 
file_cacheget_file_cache () const
 

Private Member Functions

bool apply_fixit (const fixit_hint *hint)
 
edited_fileget_file (const char *filename)
 
edited_fileget_or_insert_file (const char *filename)
 

Private Attributes

file_cachem_file_cache
 
bool m_valid
 
typed_splay_tree< const char *, edited_file * > m_files
 

Detailed Description

A set of changes to the source code. The changes are "atomic" - if any changes can't be applied, none of them can be (tracked by the m_valid flag). Similarly, attempts to add the changes from a rich_location flagged as containing invalid changes mean that the whole of the edit_context is flagged as invalid. A complication here is that fix-its are expressed relative to coordinates in the files when they were parsed, before any changes have been made, and so if there's more that one fix-it to be applied, we have to adjust later fix-its to allow for the changes made by earlier ones. This is done by the various "get_effective_column" methods.

Constructor & Destructor Documentation

◆ edit_context()

edit_context::edit_context ( file_cache & fc)
Implementation of class edit_context.
edit_context's ctor.

References m_file_cache, m_files, m_valid, NULL, and true.

Member Function Documentation

◆ add_fixits()

void edit_context::add_fixits ( rich_location * richloc)
Add any fixits within RICHLOC to this context, recording the changes that they make.

References apply_fixit(), i, and m_valid.

◆ apply_fixit()

bool edit_context::apply_fixit ( const fixit_hint * hint)
private
Attempt to apply the given fixit. Return true if it can be applied, or false otherwise.

References edited_file::apply_fixit(), expand_location(), get_or_insert_file(), and m_valid.

Referenced by add_fixits().

◆ generate_diff()

char * edit_context::generate_diff ( bool show_filenames)
Generate a unified diff. The resulting string should be freed by the caller. Primarily for selftests. If any errors occurred in this edit_context, return NULL.

References m_valid, NULL, pp_formatted_text(), and print_diff().

◆ get_content()

char * edit_context::get_content ( const char * filename)
Get the content of the given file, with fix-its applied. If any errors occurred in this edit_context, return NULL. The ptr should be freed by the caller.

References edited_file::get_content(), get_or_insert_file(), m_valid, and NULL.

◆ get_effective_column()

int edit_context::get_effective_column ( const char * filename,
int line,
int column )
Map a location before the edits to a column number after the edits. This method is for the selftests.

References edited_file::get_effective_column(), and get_file().

◆ get_file()

edited_file * edit_context::get_file ( const char * filename)
private
Locate the edited_file * for FILENAME, if any Return NULL if there isn't one.

References gcc_assert, and m_files.

Referenced by get_effective_column(), and get_or_insert_file().

◆ get_file_cache()

file_cache & edit_context::get_file_cache ( ) const
inline

References m_file_cache.

◆ get_or_insert_file()

edited_file & edit_context::get_or_insert_file ( const char * filename)
private
Locate the edited_file for FILENAME, adding one if there isn't one.

References gcc_assert, get_file(), and m_files.

Referenced by apply_fixit(), and get_content().

◆ print_diff()

void edit_context::print_diff ( pretty_printer * pp,
bool show_filenames )
Print a unified diff to PP, showing the changes made within the context.

References edited_file::call_print_diff(), m_files, and m_valid.

Referenced by generate_diff().

◆ valid_p()

bool edit_context::valid_p ( ) const
inline

References m_valid.

Field Documentation

◆ m_file_cache

file_cache& edit_context::m_file_cache
private

Referenced by edit_context(), and get_file_cache().

◆ m_files

typed_splay_tree<const char *, edited_file *> edit_context::m_files
private

◆ m_valid

bool edit_context::m_valid
private

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