GCC Middle and Back End API Reference
gcc-rich-location.h
Go to the documentation of this file.
1/* Declarations relating to class gcc_rich_location
2 Copyright (C) 2014-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_RICH_LOCATION_H
21#define GCC_RICH_LOCATION_H
22
23#include "rich-location.h"
24
26
27/* A gcc_rich_location is libcpp's rich_location with additional
28 helper methods for working with gcc's types. The class is not
29 copyable or assignable because rich_location isn't. */
30
31class gcc_rich_location : public rich_location
32{
33 public:
34 /* Constructors. */
35
36 /* Constructing from a location. */
37 explicit gcc_rich_location (location_t loc)
38 : rich_location (line_table, loc, nullptr, nullptr)
39 {
40 }
41
42 /* Constructing from a location with a label and a highlight color. */
43 explicit gcc_rich_location (location_t loc,
44 const range_label *label,
45 const char *highlight_color)
46 : rich_location (line_table, loc, label, highlight_color)
47 {
48 }
49
50 /* Methods for adding ranges via gcc entities. */
51 void
53 range_label *label,
54 const char *highlight_color);
55
56 void
58 range_label *label,
59 const char *highlight_color);
60
61 void add_fixit_misspelled_id (location_t misspelled_token_loc,
62 tree hint_id);
63
64 /* If LOC is within the spans of lines that will already be printed for
65 this gcc_rich_location, then add it as a secondary location
66 and return true.
67
68 Otherwise return false.
69
70 This allows for a diagnostic to compactly print secondary locations
71 in one diagnostic when these are near enough the primary locations for
72 diagnostics-show-locus.c to cope with them, and to fall back to
73 printing them via a note otherwise e.g.:
74
75 gcc_rich_location richloc (primary_loc);
76 bool added secondary = richloc.add_location_if_nearby (*global_dc,
77 secondary_loc);
78 error_at (&richloc, "main message");
79 if (!added secondary)
80 inform (secondary_loc, "message for secondary");
81
82 Implemented in diagnostic-show-locus.cc. */
83
85 location_t loc,
86 bool restrict_to_current_line_spans = true,
87 const range_label *label = NULL);
88
90 location_t loc,
91 bool restrict_to_current_line_spans = true,
92 const range_label *label = NULL);
93
94 /* Add a fix-it hint suggesting the insertion of CONTENT before
95 INSERTION_POINT.
96
97 Attempt to handle formatting: if INSERTION_POINT is the first thing on
98 its line, and INDENT is sufficiently sane, then add CONTENT on its own
99 line, using the indentation of INDENT.
100 Otherwise, add CONTENT directly before INSERTION_POINT.
101
102 For example, adding "CONTENT;" with the closing brace as the insertion
103 point and using "INDENT;" for indentation:
104
105 if ()
106 {
107 INDENT;
108 }
109
110 would lead to:
111
112 if ()
113 {
114 INDENT;
115 CONTENT;
116 }
117
118 but adding it to:
119
120 if () {INDENT;}
121
122 would lead to:
123
124 if () {INDENT;CONTENT;}
125 */
126 void add_fixit_insert_formatted (const char *content,
127 location_t insertion_point,
128 location_t indent);
129};
130
131#endif /* GCC_RICH_LOCATION_H */
Definition diagnostic.h:458
Definition diagnostic.h:406
Definition genmatch.cc:832
Definition gcc-rich-location.h:32
gcc_rich_location(location_t loc, const range_label *label, const char *highlight_color)
Definition gcc-rich-location.h:43
void add_expr(tree expr, range_label *label, const char *highlight_color)
Definition gcc-rich-location.cc:45
void maybe_add_expr(tree t, range_label *label, const char *highlight_color)
Definition gcc-rich-location.cc:60
void add_fixit_insert_formatted(const char *content, location_t insertion_point, location_t indent)
Definition gcc-rich-location.cc:166
void add_fixit_misspelled_id(location_t misspelled_token_loc, tree hint_id)
Definition gcc-rich-location.cc:71
bool add_location_if_nearby(const diagnostic_source_print_policy &policy, location_t loc, bool restrict_to_current_line_spans=true, const range_label *label=NULL)
Definition diagnostic-show-locus.cc:3227
gcc_rich_location(location_t loc)
Definition gcc-rich-location.h:37
union tree_node * tree
Definition coretypes.h:97
class line_maps * line_table
Definition input.cc:192
#define NULL
Definition system.h:50