]>
Commit | Line | Data |
---|---|---|
1da2ed5f JM |
1 | /* Declarations of core diagnostic functionality for code that does |
2 | not need to deal with diagnostic contexts or diagnostic info | |
4e9ee996 | 3 | structures. These functions implicitly use global_dc. |
6441eb6d | 4 | Copyright (C) 1998-2025 Free Software Foundation, Inc. |
1da2ed5f JM |
5 | |
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 3, or (at your option) any later | |
11 | version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #ifndef GCC_DIAGNOSTIC_CORE_H | |
23 | #define GCC_DIAGNOSTIC_CORE_H | |
24 | ||
7c475d11 | 25 | #include "bversion.h" |
1da2ed5f JM |
26 | |
27 | /* Constants used to discriminate diagnostics. */ | |
28 | typedef enum | |
29 | { | |
4b84d650 | 30 | #define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K, |
1da2ed5f JM |
31 | #include "diagnostic.def" |
32 | #undef DEFINE_DIAGNOSTIC_KIND | |
cd7fe53b DD |
33 | DK_LAST_DIAGNOSTIC_KIND, |
34 | /* This is used for tagging pragma pops in the diagnostic | |
35 | classification history chain. */ | |
44ba7bcb LH |
36 | DK_POP, |
37 | /* This is used internally to note that a diagnostic is enabled | |
38 | without mandating any specific type. */ | |
39 | DK_ANY, | |
1da2ed5f JM |
40 | } diagnostic_t; |
41 | ||
4e9ee996 | 42 | /* RAII-style class for grouping related diagnostics within global_dc. */ |
097f82ec DM |
43 | |
44 | class auto_diagnostic_group | |
45 | { | |
46 | public: | |
47 | auto_diagnostic_group (); | |
48 | ~auto_diagnostic_group (); | |
49 | }; | |
50 | ||
4e9ee996 | 51 | /* RAII-style class for nesting hierarchical diagnostics within global_dc. |
a5af2ec1 DM |
52 | Any diagnostics emitted within the lifetime of this object |
53 | will be treated as one level of nesting deeper than diagnostics | |
54 | emitted outside the lifetime of the object. */ | |
55 | ||
56 | class auto_diagnostic_nesting_level | |
57 | { | |
58 | public: | |
59 | auto_diagnostic_nesting_level (); | |
60 | ~auto_diagnostic_nesting_level (); | |
61 | }; | |
62 | ||
6d4a35ca DM |
63 | /* Forward decl. */ |
64 | class diagnostic_metadata; /* See diagnostic-metadata.h. */ | |
65 | ||
89991f31 DM |
66 | /* A class to use for the ID of an option that controls |
67 | a particular diagnostic. | |
68 | This is just a wrapper around "int", but better documents | |
69 | the intent of the code. */ | |
70 | ||
71 | struct diagnostic_option_id | |
72 | { | |
73 | diagnostic_option_id () : m_idx (0) {} | |
74 | ||
75 | diagnostic_option_id (int idx) : m_idx (idx) {} | |
76 | /* Ideally we'd take an enum opt_code here, but we don't | |
77 | want to depend on its decl. */ | |
78 | ||
79 | bool operator== (diagnostic_option_id other) const | |
80 | { | |
81 | return m_idx == other.m_idx; | |
82 | } | |
83 | ||
84 | int m_idx; | |
85 | }; | |
86 | ||
1da2ed5f JM |
87 | extern const char *progname; |
88 | ||
89 | extern const char *trim_filename (const char *); | |
90 | ||
4e9ee996 DM |
91 | /* Various functions for emitting diagnostics follow. |
92 | All of these implicitly use global_dc. */ | |
93 | ||
1da2ed5f JM |
94 | /* If we haven't already defined a front-end-specific diagnostics |
95 | style, use the generic one. */ | |
96 | #ifndef GCC_DIAG_STYLE | |
97 | #define GCC_DIAG_STYLE __gcc_tdiag__ | |
98 | #endif | |
99 | /* None of these functions are suitable for ATTRIBUTE_PRINTF, because | |
100 | each language front end can extend them with its own set of format | |
101 | specifiers. We must use custom format checks. */ | |
b2b29377 | 102 | #if (CHECKING_P && GCC_VERSION >= 4001) || GCC_VERSION == BUILDING_GCC_VERSION |
1da2ed5f JM |
103 | #define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m) |
104 | #else | |
105 | #define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m) | |
106 | #endif | |
107 | extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2) | |
108 | ATTRIBUTE_NORETURN; | |
b55f40c1 JJ |
109 | extern void internal_error_no_backtrace (const char *, ...) |
110 | ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN; | |
1da2ed5f | 111 | /* Pass one of the OPT_W* from options.h as the first parameter. */ |
89991f31 DM |
112 | extern bool warning (diagnostic_option_id, |
113 | const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); | |
114 | extern bool warning_n (location_t, | |
115 | diagnostic_option_id, | |
116 | unsigned HOST_WIDE_INT, | |
1c89478a | 117 | const char *, const char *, ...) |
26e82579 | 118 | ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6); |
89991f31 DM |
119 | extern bool warning_n (rich_location *, |
120 | diagnostic_option_id, | |
121 | unsigned HOST_WIDE_INT, | |
1c89478a | 122 | const char *, const char *, ...) |
64a5912c | 123 | ATTRIBUTE_GCC_DIAG(4, 6) ATTRIBUTE_GCC_DIAG(5, 6); |
89991f31 DM |
124 | extern bool warning_at (location_t, |
125 | diagnostic_option_id, | |
126 | const char *, ...) | |
1da2ed5f | 127 | ATTRIBUTE_GCC_DIAG(3,4); |
89991f31 DM |
128 | extern bool warning_at (rich_location *, |
129 | diagnostic_option_id, | |
130 | const char *, ...) | |
8a645150 | 131 | ATTRIBUTE_GCC_DIAG(3,4); |
6c8e5844 | 132 | extern bool warning_meta (rich_location *, |
89991f31 DM |
133 | const diagnostic_metadata &, |
134 | diagnostic_option_id, | |
6c8e5844 | 135 | const char *, ...) |
6d4a35ca | 136 | ATTRIBUTE_GCC_DIAG(4,5); |
1da2ed5f | 137 | extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); |
1c89478a MS |
138 | extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *, |
139 | const char *, ...) | |
1da2ed5f JM |
140 | ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5); |
141 | extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); | |
64a5912c | 142 | extern void error_at (rich_location *, const char *, ...) |
8a645150 | 143 | ATTRIBUTE_GCC_DIAG(2,3); |
1ad5ae5a DM |
144 | extern void error_meta (rich_location *, const diagnostic_metadata &, |
145 | const char *, ...) | |
146 | ATTRIBUTE_GCC_DIAG(3,4); | |
3d00119c AB |
147 | extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3) |
148 | ATTRIBUTE_NORETURN; | |
1da2ed5f | 149 | /* Pass one of the OPT_W* from options.h as the second parameter. */ |
89991f31 DM |
150 | extern bool pedwarn (location_t, |
151 | diagnostic_option_id, | |
152 | const char *, ...) | |
1da2ed5f | 153 | ATTRIBUTE_GCC_DIAG(3,4); |
89991f31 DM |
154 | extern bool pedwarn (rich_location *, |
155 | diagnostic_option_id, | |
156 | const char *, ...) | |
1a4f11c8 | 157 | ATTRIBUTE_GCC_DIAG(3,4); |
1da2ed5f | 158 | extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); |
64a5912c | 159 | extern bool permerror (rich_location *, const char *, |
8a645150 | 160 | ...) ATTRIBUTE_GCC_DIAG(2,3); |
89991f31 DM |
161 | extern bool permerror_opt (location_t, |
162 | diagnostic_option_id, | |
163 | const char *, ...) | |
164 | ATTRIBUTE_GCC_DIAG(3,4); | |
165 | extern bool permerror_opt (rich_location *, | |
166 | diagnostic_option_id, | |
167 | const char *, ...) | |
1ec36bcd | 168 | ATTRIBUTE_GCC_DIAG(3,4); |
1da2ed5f | 169 | extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); |
ad172f72 | 170 | extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); |
1da2ed5f | 171 | extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); |
64a5912c | 172 | extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); |
1c89478a MS |
173 | extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *, |
174 | const char *, ...) | |
1da2ed5f JM |
175 | ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5); |
176 | extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); | |
89991f31 DM |
177 | extern bool emit_diagnostic (diagnostic_t, |
178 | location_t, | |
179 | diagnostic_option_id, | |
1da2ed5f | 180 | const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); |
89991f31 DM |
181 | extern bool emit_diagnostic (diagnostic_t, |
182 | rich_location *, | |
183 | diagnostic_option_id, | |
8ba109ce | 184 | const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); |
89991f31 DM |
185 | extern bool emit_diagnostic_valist (diagnostic_t, |
186 | location_t, | |
187 | diagnostic_option_id, | |
188 | const char *, va_list *) | |
189 | ATTRIBUTE_GCC_DIAG (4,0); | |
b753ef8f DM |
190 | extern bool emit_diagnostic_valist_meta (diagnostic_t, |
191 | rich_location *, | |
192 | const diagnostic_metadata *, | |
89991f31 | 193 | diagnostic_option_id, |
b753ef8f DM |
194 | const char *, |
195 | va_list *) ATTRIBUTE_GCC_DIAG (5,0); | |
1da2ed5f JM |
196 | extern bool seen_error (void); |
197 | ||
198 | #ifdef BUFSIZ | |
199 | /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and | |
200 | therefore it can have ATTRIBUTE_PRINTF. */ | |
201 | extern void fnotice (FILE *, const char *, ...) | |
202 | ATTRIBUTE_PRINTF_2; | |
203 | #endif | |
204 | ||
205 | #endif /* ! GCC_DIAGNOSTIC_CORE_H */ |