1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_DIAGNOSTICIDS_H |
15 | #define LLVM_CLANG_BASIC_DIAGNOSTICIDS_H |
16 | |
17 | #include "clang/Basic/LLVM.h" |
18 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
19 | #include "llvm/ADT/StringRef.h" |
20 | #include <vector> |
21 | |
22 | namespace clang { |
23 | class DiagnosticsEngine; |
24 | class SourceLocation; |
25 | |
26 | |
27 | namespace diag { |
28 | |
29 | enum { |
30 | DIAG_SIZE_COMMON = 300, |
31 | DIAG_SIZE_DRIVER = 200, |
32 | DIAG_SIZE_FRONTEND = 150, |
33 | DIAG_SIZE_SERIALIZATION = 120, |
34 | DIAG_SIZE_LEX = 400, |
35 | DIAG_SIZE_PARSE = 500, |
36 | DIAG_SIZE_AST = 150, |
37 | = 100, |
38 | DIAG_SIZE_CROSSTU = 100, |
39 | DIAG_SIZE_SEMA = 3500, |
40 | DIAG_SIZE_ANALYSIS = 100, |
41 | DIAG_SIZE_REFACTORING = 1000, |
42 | }; |
43 | |
44 | enum { |
45 | DIAG_START_COMMON = 0, |
46 | DIAG_START_DRIVER = DIAG_START_COMMON + DIAG_SIZE_COMMON, |
47 | DIAG_START_FRONTEND = DIAG_START_DRIVER + DIAG_SIZE_DRIVER, |
48 | DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + DIAG_SIZE_FRONTEND, |
49 | DIAG_START_LEX = DIAG_START_SERIALIZATION + DIAG_SIZE_SERIALIZATION, |
50 | DIAG_START_PARSE = DIAG_START_LEX + DIAG_SIZE_LEX, |
51 | DIAG_START_AST = DIAG_START_PARSE + DIAG_SIZE_PARSE, |
52 | = DIAG_START_AST + DIAG_SIZE_AST, |
53 | DIAG_START_CROSSTU = DIAG_START_COMMENT + DIAG_SIZE_CROSSTU, |
54 | DIAG_START_SEMA = DIAG_START_CROSSTU + DIAG_SIZE_COMMENT, |
55 | DIAG_START_ANALYSIS = DIAG_START_SEMA + DIAG_SIZE_SEMA, |
56 | DIAG_START_REFACTORING = DIAG_START_ANALYSIS + DIAG_SIZE_ANALYSIS, |
57 | DIAG_UPPER_LIMIT = DIAG_START_REFACTORING + DIAG_SIZE_REFACTORING |
58 | }; |
59 | |
60 | class CustomDiagInfo; |
61 | |
62 | |
63 | typedef unsigned kind; |
64 | |
65 | |
66 | enum { |
67 | #define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ |
68 | SFINAE,CATEGORY,NOWERROR,SHOWINSYSHEADER) ENUM, |
69 | #define COMMONSTART |
70 | #include "clang/Basic/DiagnosticCommonKinds.inc" |
71 | NUM_BUILTIN_COMMON_DIAGNOSTICS |
72 | #undef DIAG |
73 | }; |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | enum class Severity { |
80 | |
81 | Ignored = 1, |
82 | = 2, |
83 | Warning = 3, |
84 | Error = 4, |
85 | Fatal = 5 |
86 | }; |
87 | |
88 | |
89 | |
90 | enum class Flavor { |
91 | WarningOrError, |
92 | |
93 | |
94 | |
95 | }; |
96 | } |
97 | |
98 | class DiagnosticMapping { |
99 | unsigned Severity : 3; |
100 | unsigned IsUser : 1; |
101 | unsigned IsPragma : 1; |
102 | unsigned HasNoWarningAsError : 1; |
103 | unsigned HasNoErrorAsFatal : 1; |
104 | unsigned WasUpgradedFromWarning : 1; |
105 | |
106 | public: |
107 | static DiagnosticMapping Make(diag::Severity Severity, bool IsUser, |
108 | bool IsPragma) { |
109 | DiagnosticMapping Result; |
110 | Result.Severity = (unsigned)Severity; |
111 | Result.IsUser = IsUser; |
112 | Result.IsPragma = IsPragma; |
113 | Result.HasNoWarningAsError = 0; |
114 | Result.HasNoErrorAsFatal = 0; |
115 | Result.WasUpgradedFromWarning = 0; |
116 | return Result; |
117 | } |
118 | |
119 | diag::Severity getSeverity() const { return (diag::Severity)Severity; } |
120 | void setSeverity(diag::Severity Value) { Severity = (unsigned)Value; } |
121 | |
122 | bool isUser() const { return IsUser; } |
123 | bool isPragma() const { return IsPragma; } |
124 | |
125 | bool isErrorOrFatal() const { |
126 | return getSeverity() == diag::Severity::Error || |
127 | getSeverity() == diag::Severity::Fatal; |
128 | } |
129 | |
130 | bool hasNoWarningAsError() const { return HasNoWarningAsError; } |
131 | void setNoWarningAsError(bool Value) { HasNoWarningAsError = Value; } |
132 | |
133 | bool hasNoErrorAsFatal() const { return HasNoErrorAsFatal; } |
134 | void setNoErrorAsFatal(bool Value) { HasNoErrorAsFatal = Value; } |
135 | |
136 | |
137 | |
138 | |
139 | bool wasUpgradedFromWarning() const { return WasUpgradedFromWarning; } |
140 | void setUpgradedFromWarning(bool Value) { WasUpgradedFromWarning = Value; } |
141 | |
142 | |
143 | unsigned serialize() const { |
144 | return (IsUser << 7) | (IsPragma << 6) | (HasNoWarningAsError << 5) | |
145 | (HasNoErrorAsFatal << 4) | (WasUpgradedFromWarning << 3) | Severity; |
146 | } |
147 | |
148 | static DiagnosticMapping deserialize(unsigned Bits) { |
149 | DiagnosticMapping Result; |
150 | Result.IsUser = (Bits >> 7) & 1; |
151 | Result.IsPragma = (Bits >> 6) & 1; |
152 | Result.HasNoWarningAsError = (Bits >> 5) & 1; |
153 | Result.HasNoErrorAsFatal = (Bits >> 4) & 1; |
154 | Result.WasUpgradedFromWarning = (Bits >> 3) & 1; |
155 | Result.Severity = Bits & 0x7; |
156 | return Result; |
157 | } |
158 | }; |
159 | |
160 | |
161 | |
162 | |
163 | class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> { |
164 | public: |
165 | |
166 | enum Level { |
167 | Ignored, Note, , Warning, Error, Fatal |
168 | }; |
169 | |
170 | private: |
171 | |
172 | diag::CustomDiagInfo *CustomDiagInfo; |
173 | |
174 | public: |
175 | DiagnosticIDs(); |
176 | ~DiagnosticIDs(); |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | unsigned getCustomDiagID(Level L, StringRef FormatString); |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | StringRef getDescription(unsigned DiagID) const; |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | static bool isBuiltinWarningOrExtension(unsigned DiagID); |
202 | |
203 | |
204 | |
205 | static bool isDefaultMappingAsError(unsigned DiagID); |
206 | |
207 | |
208 | static bool isBuiltinNote(unsigned DiagID); |
209 | |
210 | |
211 | |
212 | static bool isBuiltinExtensionDiag(unsigned DiagID) { |
213 | bool ignored; |
214 | return isBuiltinExtensionDiag(DiagID, ignored); |
215 | } |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | static bool isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault); |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | static StringRef getWarningOptionForDiag(unsigned DiagID); |
232 | |
233 | |
234 | |
235 | static unsigned getCategoryNumberForDiag(unsigned DiagID); |
236 | |
237 | |
238 | static unsigned getNumberOfCategories(); |
239 | |
240 | |
241 | static StringRef getCategoryNameFromID(unsigned CategoryID); |
242 | |
243 | |
244 | |
245 | static bool isARCDiagnostic(unsigned DiagID); |
246 | |
247 | |
248 | |
249 | enum SFINAEResponse { |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | SFINAE_SubstitutionFailure, |
256 | |
257 | |
258 | |
259 | |
260 | SFINAE_Suppress, |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | SFINAE_Report, |
267 | |
268 | |
269 | |
270 | SFINAE_AccessControl |
271 | }; |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID); |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | static std::vector<std::string> getDiagnosticFlags(); |
289 | |
290 | |
291 | |
292 | |
293 | |
294 | bool getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group, |
295 | SmallVectorImpl<diag::kind> &Diags) const; |
296 | |
297 | |
298 | static void getAllDiagnostics(diag::Flavor Flavor, |
299 | std::vector<diag::kind> &Diags); |
300 | |
301 | |
302 | |
303 | static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group); |
304 | |
305 | private: |
306 | |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | |
313 | |
314 | DiagnosticIDs::Level |
315 | getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, |
316 | const DiagnosticsEngine &Diag) const LLVM_READONLY; |
317 | |
318 | diag::Severity |
319 | getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc, |
320 | const DiagnosticsEngine &Diag) const LLVM_READONLY; |
321 | |
322 | |
323 | |
324 | |
325 | |
326 | bool ProcessDiag(DiagnosticsEngine &Diag) const; |
327 | |
328 | |
329 | |
330 | void EmitDiag(DiagnosticsEngine &Diag, Level DiagLevel) const; |
331 | |
332 | |
333 | |
334 | bool isUnrecoverable(unsigned DiagID) const; |
335 | |
336 | friend class DiagnosticsEngine; |
337 | }; |
338 | |
339 | } |
340 | |
341 | #endif |
342 | |