1 /* Declarations relating to class gcc_rich_location
2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_RICH_LOCATION_H
21 #define GCC_RICH_LOCATION_H
23 #include "rich-location.h"
25 class diagnostic_source_print_policy
;
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. */
31 class gcc_rich_location
: public rich_location
36 /* Constructing from a location. */
37 explicit gcc_rich_location (location_t loc
)
38 : rich_location (line_table
, loc
, nullptr, nullptr)
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
)
50 /* Methods for adding ranges via gcc entities. */
54 const char *highlight_color
);
57 maybe_add_expr (tree t
,
59 const char *highlight_color
);
61 void add_fixit_misspelled_id (location_t misspelled_token_loc
,
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
68 Otherwise return false.
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.:
75 gcc_rich_location richloc (primary_loc);
76 bool added secondary = richloc.add_location_if_nearby (*global_dc,
78 error_at (&richloc, "main message");
80 inform (secondary_loc, "message for secondary");
82 Implemented in diagnostic-show-locus.cc. */
84 bool add_location_if_nearby (const diagnostic_source_print_policy
&policy
,
86 bool restrict_to_current_line_spans
= true,
87 const range_label
*label
= NULL
);
89 bool add_location_if_nearby (const diagnostic_context
&dc
,
91 bool restrict_to_current_line_spans
= true,
92 const range_label
*label
= NULL
);
94 /* Add a fix-it hint suggesting the insertion of CONTENT before
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.
102 For example, adding "CONTENT;" with the closing brace as the insertion
103 point and using "INDENT;" for indentation:
124 if () {INDENT;CONTENT;}
126 void add_fixit_insert_formatted (const char *content
,
127 location_t insertion_point
,
131 #endif /* GCC_RICH_LOCATION_H */