PR c++/77777 improve location for diagnostic
[official-gcc.git] / gcc / gcc-rich-location.h
blob9c705c86a726612c8c3102c594c53c83329781ef
1 /* Declarations relating to class gcc_rich_location
2 Copyright (C) 2014-2018 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
9 version.
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
14 for more details.
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 /* A gcc_rich_location is libcpp's rich_location with additional
24 helper methods for working with gcc's types. */
25 class gcc_rich_location : public rich_location
27 public:
28 /* Constructors. */
30 /* Constructing from a location. */
31 gcc_rich_location (source_location loc) :
32 rich_location (line_table, loc) {}
34 /* Methods for adding ranges via gcc entities. */
35 void
36 add_expr (tree expr);
38 void
39 maybe_add_expr (tree t);
41 void add_fixit_misspelled_id (location_t misspelled_token_loc,
42 tree hint_id);
44 /* If LOC is within the spans of lines that will already be printed for
45 this gcc_rich_location, then add it as a secondary location
46 and return true.
48 Otherwise return false.
50 This allows for a diagnostic to compactly print secondary locations
51 in one diagnostic when these are near enough the primary locations for
52 diagnostics-show-locus.c to cope with them, and to fall back to
53 printing them via a note otherwise e.g.:
55 gcc_rich_location richloc (primary_loc);
56 bool added secondary = richloc.add_location_if_nearby (secondary_loc);
57 error_at_rich_loc (&richloc, "main message");
58 if (!added secondary)
59 inform (secondary_loc, "message for secondary");
61 Implemented in diagnostic-show-locus.c. */
63 bool add_location_if_nearby (location_t loc);
65 /* Add a fix-it hint suggesting the insertion of CONTENT before
66 INSERTION_POINT.
68 Attempt to handle formatting: if INSERTION_POINT is the first thing on
69 its line, and INDENT is sufficiently sane, then add CONTENT on its own
70 line, using the indentation of INDENT.
71 Otherwise, add CONTENT directly before INSERTION_POINT.
73 For example, adding "CONTENT;" with the closing brace as the insertion
74 point and using "INDENT;" for indentation:
76 if ()
78 INDENT;
81 would lead to:
83 if ()
85 INDENT;
86 CONTENT;
89 but adding it to:
91 if () {INDENT;}
93 would lead to:
95 if () {INDENT;CONTENT;}
97 void add_fixit_insert_formatted (const char *content,
98 location_t insertion_point,
99 location_t indent);
102 #endif /* GCC_RICH_LOCATION_H */