GCC Middle and Back End API Reference
changes.h
Go to the documentation of this file.
1/* Determining the results of applying fix-it hints.
2 Copyright (C) 2016-2025 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_DIAGNOSTICS_CHANGES_H
21#define GCC_DIAGNOSTICS_CHANGES_H
22
23#include "typed-splay-tree.h"
24
25class fixit_hint;
26
27namespace diagnostics {
28namespace changes {
29
30class change_set;
31class changed_file;
32
33/* A set of changes to the source code.
34
35 The changes are "atomic" - if any changes can't be applied,
36 none of them can be (tracked by the m_valid flag).
37 Similarly, attempts to add the changes from a rich_location flagged
38 as containing invalid changes mean that the whole of the change_set
39 is flagged as invalid.
40
41 A complication here is that fix-its are expressed relative to coordinates
42 in the files when they were parsed, before any changes have been made, and
43 so if there's more that one fix-it to be applied, we have to adjust
44 later fix-its to allow for the changes made by earlier ones. This
45 is done by the various "get_effective_column" methods. */
46
48{
49 public:
51
52 bool valid_p () const { return m_valid; }
53
54 void add_fixits (rich_location *richloc);
55
56 char *get_content (const char *filename);
57
58 int get_effective_column (const char *filename, int line, int column);
59
60 char *generate_diff (bool show_filenames);
61 void print_diff (pretty_printer *pp, bool show_filenames);
62
64
65 private:
66 bool apply_fixit (const fixit_hint *hint);
67 changed_file *get_file (const char *filename);
68 changed_file &get_or_insert_file (const char *filename);
69
71 bool m_valid;
73};
74
75} // namespace diagnostics::changes
76} // namespace diagnostics
77
78#endif /* GCC_DIAGNOSTICS_CHANGES_H. */
Definition changes.h:48
char * get_content(const char *filename)
Definition changes.cc:253
void print_diff(pretty_printer *pp, bool show_filenames)
Definition changes.cc:293
file_cache & get_file_cache() const
Definition changes.h:63
char * generate_diff(bool show_filenames)
Definition changes.cc:279
file_cache & m_file_cache
Definition changes.h:70
bool valid_p() const
Definition changes.h:52
bool apply_fixit(const fixit_hint *hint)
Definition changes.cc:305
change_set(file_cache &)
Definition changes.cc:221
changed_file & get_or_insert_file(const char *filename)
Definition changes.cc:339
changed_file * get_file(const char *filename)
Definition changes.cc:330
bool m_valid
Definition changes.h:71
void add_fixits(rich_location *richloc)
Definition changes.cc:231
typed_splay_tree< const char *, changed_file * > m_files
Definition changes.h:72
int get_effective_column(const char *filename, int line, int column)
Definition changes.cc:265
Definition changes.cc:69
Definition file-cache.h:82
Definition pretty-print.h:241
Definition typed-splay-tree.h:26
Definition changes.cc:31
Definition coretypes.h:167