GCC Middle and Back End API Reference
edit-context.h
Go to the documentation of this file.
1/* Determining the results of applying fix-it hints.
2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_EDIT_CONTEXT_H
21#define GCC_EDIT_CONTEXT_H
22
23#include "typed-splay-tree.h"
24
25class fixit_hint;
26class edit_context;
27class edited_file;
28
29/* A set of changes to the source code.
30
31 The changes are "atomic" - if any changes can't be applied,
32 none of them can be (tracked by the m_valid flag).
33 Similarly, attempts to add the changes from a rich_location flagged
34 as containing invalid changes mean that the whole of the edit_context
35 is flagged as invalid.
36
37 A complication here is that fix-its are expressed relative to coordinates
38 in the files when they were parsed, before any changes have been made, and
39 so if there's more that one fix-it to be applied, we have to adjust
40 later fix-its to allow for the changes made by earlier ones. This
41 is done by the various "get_effective_column" methods. */
42
44{
45 public:
47
48 bool valid_p () const { return m_valid; }
49
50 void add_fixits (rich_location *richloc);
51
52 char *get_content (const char *filename);
53
54 int get_effective_column (const char *filename, int line, int column);
55
56 char *generate_diff (bool show_filenames);
58
60
61 private:
62 bool apply_fixit (const fixit_hint *hint);
63 edited_file *get_file (const char *filename);
64 edited_file &get_or_insert_file (const char *filename);
65
67 bool m_valid;
69};
70
71#endif /* GCC_EDIT_CONTEXT_H. */
Definition edit-context.h:44
edited_file & get_or_insert_file(const char *filename)
Definition edit-context.cc:335
bool apply_fixit(const fixit_hint *hint)
Definition edit-context.cc:301
int get_effective_column(const char *filename, int line, int column)
Definition edit-context.cc:261
char * get_content(const char *filename)
Definition edit-context.cc:249
void print_diff(pretty_printer *pp, bool show_filenames)
Definition edit-context.cc:289
edited_file * get_file(const char *filename)
Definition edit-context.cc:326
typed_splay_tree< const char *, edited_file * > m_files
Definition edit-context.h:68
char * generate_diff(bool show_filenames)
Definition edit-context.cc:275
file_cache & get_file_cache() const
Definition edit-context.h:59
bool valid_p() const
Definition edit-context.h:48
void add_fixits(rich_location *richloc)
Definition edit-context.cc:227
bool m_valid
Definition edit-context.h:67
edit_context(file_cache &)
Definition edit-context.cc:217
file_cache & m_file_cache
Definition edit-context.h:66
Definition edit-context.cc:65
Definition input.h:136
Definition pretty-print.h:244
Definition typed-splay-tree.h:26
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184