GCC Middle and Back End API Reference
|
#include <edit-context.h>
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_cache & | get_file_cache () const |
Private Member Functions | |
bool | apply_fixit (const fixit_hint *hint) |
edited_file * | get_file (const char *filename) |
edited_file & | get_or_insert_file (const char *filename) |
Private Attributes | |
file_cache & | m_file_cache |
bool | m_valid |
typed_splay_tree< const char *, edited_file * > | m_files |
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.
edit_context::edit_context | ( | file_cache & | fc | ) |
Implementation of class edit_context.
edit_context's ctor.
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.
Referenced by diagnostic_context::report_diagnostic().
|
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().
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().
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.
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().
|
private |
Locate the edited_file * for FILENAME, if any Return NULL if there isn't one.
References gcc_assert, typed_splay_tree< KEY_TYPE, VALUE_TYPE >::lookup(), and m_files.
Referenced by get_effective_column(), and get_or_insert_file().
|
inline |
References m_file_cache.
Referenced by edited_file::get_file_cache().
|
private |
Locate the edited_file for FILENAME, adding one if there isn't one.
References gcc_assert, get_file(), typed_splay_tree< KEY_TYPE, VALUE_TYPE >::insert(), and m_files.
Referenced by apply_fixit(), and get_content().
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(), typed_splay_tree< KEY_TYPE, VALUE_TYPE >::foreach(), m_files, and m_valid.
Referenced by generate_diff().
|
private |
Referenced by get_file_cache().
|
private |
Referenced by get_file(), get_or_insert_file(), and print_diff().
|
private |
Referenced by add_fixits(), apply_fixit(), generate_diff(), get_content(), print_diff(), and valid_p().