1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H |
15 | #define LLVM_CLANG_BASIC_DIAGNOSTIC_H |
16 | |
17 | #include "clang/Basic/DiagnosticIDs.h" |
18 | #include "clang/Basic/DiagnosticOptions.h" |
19 | #include "clang/Basic/SourceLocation.h" |
20 | #include "clang/Basic/Specifiers.h" |
21 | #include "llvm/ADT/ArrayRef.h" |
22 | #include "llvm/ADT/DenseMap.h" |
23 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
24 | #include "llvm/ADT/SmallVector.h" |
25 | #include "llvm/ADT/StringRef.h" |
26 | #include "llvm/ADT/iterator_range.h" |
27 | #include "llvm/Support/Compiler.h" |
28 | #include <cassert> |
29 | #include <cstdint> |
30 | #include <limits> |
31 | #include <list> |
32 | #include <map> |
33 | #include <memory> |
34 | #include <string> |
35 | #include <type_traits> |
36 | #include <utility> |
37 | #include <vector> |
38 | |
39 | namespace clang { |
40 | |
41 | class DeclContext; |
42 | class DiagnosticBuilder; |
43 | class DiagnosticConsumer; |
44 | class IdentifierInfo; |
45 | class LangOptions; |
46 | class Preprocessor; |
47 | class SourceManager; |
48 | class StoredDiagnostic; |
49 | |
50 | namespace tok { |
51 | |
52 | enum TokenKind : unsigned short; |
53 | |
54 | } |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | class FixItHint { |
66 | public: |
67 | |
68 | |
69 | CharSourceRange RemoveRange; |
70 | |
71 | |
72 | |
73 | CharSourceRange InsertFromRange; |
74 | |
75 | |
76 | |
77 | std::string CodeToInsert; |
78 | |
79 | bool BeforePreviousInsertions = false; |
80 | |
81 | |
82 | |
83 | FixItHint() = default; |
84 | |
85 | bool isNull() const { |
86 | return !RemoveRange.isValid(); |
87 | } |
88 | |
89 | |
90 | |
91 | static FixItHint CreateInsertion(SourceLocation InsertionLoc, |
92 | StringRef Code, |
93 | bool BeforePreviousInsertions = false) { |
94 | FixItHint Hint; |
95 | Hint.RemoveRange = |
96 | CharSourceRange::getCharRange(InsertionLoc, InsertionLoc); |
97 | Hint.CodeToInsert = Code; |
98 | Hint.BeforePreviousInsertions = BeforePreviousInsertions; |
99 | return Hint; |
100 | } |
101 | |
102 | |
103 | |
104 | static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, |
105 | CharSourceRange FromRange, |
106 | bool BeforePreviousInsertions = false) { |
107 | FixItHint Hint; |
108 | Hint.RemoveRange = |
109 | CharSourceRange::getCharRange(InsertionLoc, InsertionLoc); |
110 | Hint.InsertFromRange = FromRange; |
111 | Hint.BeforePreviousInsertions = BeforePreviousInsertions; |
112 | return Hint; |
113 | } |
114 | |
115 | |
116 | |
117 | static FixItHint CreateRemoval(CharSourceRange RemoveRange) { |
118 | FixItHint Hint; |
119 | Hint.RemoveRange = RemoveRange; |
120 | return Hint; |
121 | } |
122 | static FixItHint CreateRemoval(SourceRange RemoveRange) { |
123 | return CreateRemoval(CharSourceRange::getTokenRange(RemoveRange)); |
124 | } |
125 | |
126 | |
127 | |
128 | static FixItHint CreateReplacement(CharSourceRange RemoveRange, |
129 | StringRef Code) { |
130 | FixItHint Hint; |
131 | Hint.RemoveRange = RemoveRange; |
132 | Hint.CodeToInsert = Code; |
133 | return Hint; |
134 | } |
135 | |
136 | static FixItHint CreateReplacement(SourceRange RemoveRange, |
137 | StringRef Code) { |
138 | return CreateReplacement(CharSourceRange::getTokenRange(RemoveRange), Code); |
139 | } |
140 | }; |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
149 | public: |
150 | |
151 | enum Level { |
152 | Ignored = DiagnosticIDs::Ignored, |
153 | Note = DiagnosticIDs::Note, |
154 | = DiagnosticIDs::Remark, |
155 | Warning = DiagnosticIDs::Warning, |
156 | Error = DiagnosticIDs::Error, |
157 | Fatal = DiagnosticIDs::Fatal |
158 | }; |
159 | |
160 | enum ArgumentKind { |
161 | |
162 | ak_std_string, |
163 | |
164 | |
165 | ak_c_string, |
166 | |
167 | |
168 | ak_sint, |
169 | |
170 | |
171 | ak_uint, |
172 | |
173 | |
174 | ak_tokenkind, |
175 | |
176 | |
177 | ak_identifierinfo, |
178 | |
179 | |
180 | ak_qual, |
181 | |
182 | |
183 | ak_qualtype, |
184 | |
185 | |
186 | ak_declarationname, |
187 | |
188 | |
189 | ak_nameddecl, |
190 | |
191 | |
192 | ak_nestednamespec, |
193 | |
194 | |
195 | ak_declcontext, |
196 | |
197 | |
198 | ak_qualtype_pair, |
199 | |
200 | |
201 | ak_attr |
202 | }; |
203 | |
204 | |
205 | |
206 | using ArgumentValue = std::pair<ArgumentKind, intptr_t>; |
207 | |
208 | private: |
209 | |
210 | unsigned char AllExtensionsSilenced = 0; |
211 | |
212 | |
213 | bool FatalsAsError = false; |
214 | |
215 | |
216 | bool SuppressAllDiagnostics = false; |
217 | |
218 | |
219 | bool ElideType = true; |
220 | |
221 | |
222 | bool PrintTemplateTree = false; |
223 | |
224 | |
225 | bool ShowColors = false; |
226 | |
227 | |
228 | OverloadsShown ShowOverloads = Ovl_All; |
229 | |
230 | |
231 | unsigned ErrorLimit = 0; |
232 | |
233 | |
234 | unsigned TemplateBacktraceLimit = 0; |
235 | |
236 | |
237 | unsigned ConstexprBacktraceLimit = 0; |
238 | |
239 | IntrusiveRefCntPtr<DiagnosticIDs> Diags; |
240 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; |
241 | DiagnosticConsumer *Client = nullptr; |
242 | std::unique_ptr<DiagnosticConsumer> Owner; |
243 | SourceManager *SourceMgr = nullptr; |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | class DiagState { |
257 | llvm::DenseMap<unsigned, DiagnosticMapping> DiagMap; |
258 | |
259 | public: |
260 | |
261 | |
262 | |
263 | unsigned IgnoreAllWarnings : 1; |
264 | |
265 | |
266 | unsigned EnableAllWarnings : 1; |
267 | |
268 | |
269 | unsigned WarningsAsErrors : 1; |
270 | |
271 | |
272 | unsigned ErrorsAsFatal : 1; |
273 | |
274 | |
275 | unsigned SuppressSystemWarnings : 1; |
276 | |
277 | |
278 | diag::Severity ExtBehavior = diag::Severity::Ignored; |
279 | |
280 | DiagState() |
281 | : IgnoreAllWarnings(false), EnableAllWarnings(false), |
282 | WarningsAsErrors(false), ErrorsAsFatal(false), |
283 | SuppressSystemWarnings(false) {} |
284 | |
285 | using iterator = llvm::DenseMap<unsigned, DiagnosticMapping>::iterator; |
286 | using const_iterator = |
287 | llvm::DenseMap<unsigned, DiagnosticMapping>::const_iterator; |
288 | |
289 | void setMapping(diag::kind Diag, DiagnosticMapping Info) { |
290 | DiagMap[Diag] = Info; |
291 | } |
292 | |
293 | DiagnosticMapping lookupMapping(diag::kind Diag) const { |
294 | return DiagMap.lookup(Diag); |
295 | } |
296 | |
297 | DiagnosticMapping &getOrAddMapping(diag::kind Diag); |
298 | |
299 | const_iterator begin() const { return DiagMap.begin(); } |
300 | const_iterator end() const { return DiagMap.end(); } |
301 | }; |
302 | |
303 | |
304 | std::list<DiagState> DiagStates; |
305 | |
306 | |
307 | |
308 | class DiagStateMap { |
309 | public: |
310 | |
311 | void appendFirst(DiagState *State); |
312 | |
313 | |
314 | void append(SourceManager &SrcMgr, SourceLocation Loc, DiagState *State); |
315 | |
316 | |
317 | DiagState *lookup(SourceManager &SrcMgr, SourceLocation Loc) const; |
318 | |
319 | |
320 | bool empty() const { return Files.empty(); } |
321 | |
322 | |
323 | void clear() { |
324 | Files.clear(); |
325 | FirstDiagState = CurDiagState = nullptr; |
326 | CurDiagStateLoc = SourceLocation(); |
327 | } |
328 | |
329 | |
330 | LLVM_DUMP_METHOD void dump(SourceManager &SrcMgr, |
331 | StringRef DiagName = StringRef()) const; |
332 | |
333 | |
334 | DiagState *getCurDiagState() const { return CurDiagState; } |
335 | |
336 | |
337 | SourceLocation getCurDiagStateLoc() const { return CurDiagStateLoc; } |
338 | |
339 | private: |
340 | friend class ASTReader; |
341 | friend class ASTWriter; |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | |
348 | struct DiagStatePoint { |
349 | DiagState *State; |
350 | unsigned Offset; |
351 | |
352 | DiagStatePoint(DiagState *State, unsigned Offset) |
353 | : State(State), Offset(Offset) {} |
354 | }; |
355 | |
356 | |
357 | |
358 | struct File { |
359 | |
360 | |
361 | |
362 | File *Parent = nullptr; |
363 | |
364 | |
365 | unsigned ParentOffset = 0; |
366 | |
367 | |
368 | |
369 | bool HasLocalTransitions = false; |
370 | |
371 | |
372 | |
373 | llvm::SmallVector<DiagStatePoint, 4> StateTransitions; |
374 | |
375 | DiagState *lookup(unsigned Offset) const; |
376 | }; |
377 | |
378 | |
379 | mutable std::map<FileID, File> Files; |
380 | |
381 | |
382 | DiagState *FirstDiagState; |
383 | |
384 | |
385 | DiagState *CurDiagState; |
386 | |
387 | |
388 | SourceLocation CurDiagStateLoc; |
389 | |
390 | |
391 | File *getFile(SourceManager &SrcMgr, FileID ID) const; |
392 | }; |
393 | |
394 | DiagStateMap DiagStatesByLoc; |
395 | |
396 | |
397 | |
398 | std::vector<DiagState *> DiagStateOnPushStack; |
399 | |
400 | DiagState *GetCurDiagState() const { |
401 | return DiagStatesByLoc.getCurDiagState(); |
402 | } |
403 | |
404 | void PushDiagStatePoint(DiagState *State, SourceLocation L); |
405 | |
406 | |
407 | |
408 | DiagState *GetDiagStateForLoc(SourceLocation Loc) const { |
409 | return SourceMgr ? DiagStatesByLoc.lookup(*SourceMgr, Loc) |
410 | : DiagStatesByLoc.getCurDiagState(); |
411 | } |
412 | |
413 | |
414 | bool ErrorOccurred; |
415 | |
416 | |
417 | |
418 | bool UncompilableErrorOccurred; |
419 | |
420 | |
421 | bool FatalErrorOccurred; |
422 | |
423 | |
424 | bool UnrecoverableErrorOccurred; |
425 | |
426 | |
427 | |
428 | unsigned TrapNumErrorsOccurred; |
429 | unsigned TrapNumUnrecoverableErrorsOccurred; |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | DiagnosticIDs::Level LastDiagLevel; |
436 | |
437 | |
438 | unsigned NumWarnings; |
439 | |
440 | |
441 | unsigned NumErrors; |
442 | |
443 | |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | using ArgToStringFnTy = void (*)( |
454 | ArgumentKind Kind, intptr_t Val, |
455 | StringRef Modifier, StringRef Argument, |
456 | ArrayRef<ArgumentValue> PrevArgs, |
457 | SmallVectorImpl<char> &Output, |
458 | void *Cookie, |
459 | ArrayRef<intptr_t> QualTypeVals); |
460 | |
461 | void *ArgToStringCookie = nullptr; |
462 | ArgToStringFnTy ArgToStringFn; |
463 | |
464 | |
465 | |
466 | |
467 | unsigned DelayedDiagID; |
468 | |
469 | |
470 | std::string DelayedDiagArg1; |
471 | |
472 | |
473 | std::string DelayedDiagArg2; |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | std::string FlagValue; |
481 | |
482 | public: |
483 | explicit DiagnosticsEngine(IntrusiveRefCntPtr<DiagnosticIDs> Diags, |
484 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, |
485 | DiagnosticConsumer *client = nullptr, |
486 | bool ShouldOwnClient = true); |
487 | DiagnosticsEngine(const DiagnosticsEngine &) = delete; |
488 | DiagnosticsEngine &operator=(const DiagnosticsEngine &) = delete; |
489 | ~DiagnosticsEngine(); |
490 | |
491 | LLVM_DUMP_METHOD void dump() const; |
492 | LLVM_DUMP_METHOD void dump(StringRef DiagName) const; |
493 | |
494 | const IntrusiveRefCntPtr<DiagnosticIDs> &getDiagnosticIDs() const { |
495 | return Diags; |
496 | } |
497 | |
498 | |
499 | DiagnosticOptions &getDiagnosticOptions() const { return *DiagOpts; } |
500 | |
501 | using diag_mapping_range = llvm::iterator_range<DiagState::const_iterator>; |
502 | |
503 | |
504 | diag_mapping_range getDiagnosticMappings() const { |
505 | const DiagState &DS = *GetCurDiagState(); |
506 | return diag_mapping_range(DS.begin(), DS.end()); |
507 | } |
508 | |
509 | DiagnosticConsumer *getClient() { return Client; } |
510 | const DiagnosticConsumer *getClient() const { return Client; } |
511 | |
512 | |
513 | bool ownsClient() const { return Owner != nullptr; } |
514 | |
515 | |
516 | |
517 | std::unique_ptr<DiagnosticConsumer> takeClient() { return std::move(Owner); } |
518 | |
519 | bool hasSourceManager() const { return SourceMgr != nullptr; } |
520 | |
521 | SourceManager &getSourceManager() const { |
522 | (0) . __assert_fail ("SourceMgr && \"SourceManager not set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 522, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(SourceMgr && "SourceManager not set!"); |
523 | return *SourceMgr; |
524 | } |
525 | |
526 | void setSourceManager(SourceManager *SrcMgr) { |
527 | (0) . __assert_fail ("DiagStatesByLoc.empty() && \"Leftover diag state from a different SourceManager.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 528, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(DiagStatesByLoc.empty() && |
528 | (0) . __assert_fail ("DiagStatesByLoc.empty() && \"Leftover diag state from a different SourceManager.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 528, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Leftover diag state from a different SourceManager."); |
529 | SourceMgr = SrcMgr; |
530 | } |
531 | |
532 | |
533 | |
534 | |
535 | |
536 | |
537 | |
538 | |
539 | void pushMappings(SourceLocation Loc); |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | |
546 | bool popMappings(SourceLocation Loc); |
547 | |
548 | |
549 | |
550 | |
551 | |
552 | void setClient(DiagnosticConsumer *client, bool ShouldOwnClient = true); |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | void setErrorLimit(unsigned Limit) { ErrorLimit = Limit; } |
559 | |
560 | |
561 | |
562 | void setTemplateBacktraceLimit(unsigned Limit) { |
563 | TemplateBacktraceLimit = Limit; |
564 | } |
565 | |
566 | |
567 | |
568 | unsigned getTemplateBacktraceLimit() const { |
569 | return TemplateBacktraceLimit; |
570 | } |
571 | |
572 | |
573 | |
574 | void setConstexprBacktraceLimit(unsigned Limit) { |
575 | ConstexprBacktraceLimit = Limit; |
576 | } |
577 | |
578 | |
579 | |
580 | unsigned getConstexprBacktraceLimit() const { |
581 | return ConstexprBacktraceLimit; |
582 | } |
583 | |
584 | |
585 | |
586 | |
587 | void setIgnoreAllWarnings(bool Val) { |
588 | GetCurDiagState()->IgnoreAllWarnings = Val; |
589 | } |
590 | bool getIgnoreAllWarnings() const { |
591 | return GetCurDiagState()->IgnoreAllWarnings; |
592 | } |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | void setEnableAllWarnings(bool Val) { |
599 | GetCurDiagState()->EnableAllWarnings = Val; |
600 | } |
601 | bool getEnableAllWarnings() const { |
602 | return GetCurDiagState()->EnableAllWarnings; |
603 | } |
604 | |
605 | |
606 | void setWarningsAsErrors(bool Val) { |
607 | GetCurDiagState()->WarningsAsErrors = Val; |
608 | } |
609 | bool getWarningsAsErrors() const { |
610 | return GetCurDiagState()->WarningsAsErrors; |
611 | } |
612 | |
613 | |
614 | void setErrorsAsFatal(bool Val) { GetCurDiagState()->ErrorsAsFatal = Val; } |
615 | bool getErrorsAsFatal() const { return GetCurDiagState()->ErrorsAsFatal; } |
616 | |
617 | |
618 | |
619 | |
620 | void setFatalsAsError(bool Val) { FatalsAsError = Val; } |
621 | bool getFatalsAsError() const { return FatalsAsError; } |
622 | |
623 | |
624 | void setSuppressSystemWarnings(bool Val) { |
625 | GetCurDiagState()->SuppressSystemWarnings = Val; |
626 | } |
627 | bool getSuppressSystemWarnings() const { |
628 | return GetCurDiagState()->SuppressSystemWarnings; |
629 | } |
630 | |
631 | |
632 | |
633 | |
634 | void setSuppressAllDiagnostics(bool Val = true) { |
635 | SuppressAllDiagnostics = Val; |
636 | } |
637 | bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; } |
638 | |
639 | |
640 | |
641 | void setElideType(bool Val = true) { ElideType = Val; } |
642 | bool getElideType() { return ElideType; } |
643 | |
644 | |
645 | |
646 | void setPrintTemplateTree(bool Val = false) { PrintTemplateTree = Val; } |
647 | bool getPrintTemplateTree() { return PrintTemplateTree; } |
648 | |
649 | |
650 | |
651 | void setShowColors(bool Val = false) { ShowColors = Val; } |
652 | bool getShowColors() { return ShowColors; } |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | void setShowOverloads(OverloadsShown Val) { |
659 | ShowOverloads = Val; |
660 | } |
661 | OverloadsShown getShowOverloads() const { return ShowOverloads; } |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | void setLastDiagnosticIgnored(bool Ignored = true) { |
670 | if (LastDiagLevel == DiagnosticIDs::Fatal) |
671 | FatalErrorOccurred = true; |
672 | LastDiagLevel = Ignored ? DiagnosticIDs::Ignored : DiagnosticIDs::Warning; |
673 | } |
674 | |
675 | |
676 | |
677 | |
678 | bool isLastDiagnosticIgnored() const { |
679 | return LastDiagLevel == DiagnosticIDs::Ignored; |
680 | } |
681 | |
682 | |
683 | |
684 | |
685 | |
686 | void setExtensionHandlingBehavior(diag::Severity H) { |
687 | GetCurDiagState()->ExtBehavior = H; |
688 | } |
689 | diag::Severity getExtensionHandlingBehavior() const { |
690 | return GetCurDiagState()->ExtBehavior; |
691 | } |
692 | |
693 | |
694 | |
695 | |
696 | |
697 | void IncrementAllExtensionsSilenced() { ++AllExtensionsSilenced; } |
698 | void DecrementAllExtensionsSilenced() { --AllExtensionsSilenced; } |
699 | bool hasAllExtensionsSilenced() { return AllExtensionsSilenced != 0; } |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | |
709 | void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc); |
710 | |
711 | |
712 | |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, |
723 | diag::Severity Map, |
724 | SourceLocation Loc = SourceLocation()); |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | |
731 | bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled); |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled); |
739 | |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, |
746 | SourceLocation Loc = SourceLocation()); |
747 | |
748 | bool hasErrorOccurred() const { return ErrorOccurred; } |
749 | |
750 | |
751 | |
752 | bool hasUncompilableErrorOccurred() const { |
753 | return UncompilableErrorOccurred; |
754 | } |
755 | bool hasFatalErrorOccurred() const { return FatalErrorOccurred; } |
756 | |
757 | |
758 | bool hasUnrecoverableErrorOccurred() const { |
759 | return FatalErrorOccurred || UnrecoverableErrorOccurred; |
760 | } |
761 | |
762 | unsigned getNumWarnings() const { return NumWarnings; } |
763 | |
764 | void setNumWarnings(unsigned NumWarnings) { |
765 | this->NumWarnings = NumWarnings; |
766 | } |
767 | |
768 | |
769 | |
770 | |
771 | |
772 | |
773 | |
774 | |
775 | |
776 | template <unsigned N> |
777 | unsigned getCustomDiagID(Level L, const char (&FormatString)[N]) { |
778 | return Diags->getCustomDiagID((DiagnosticIDs::Level)L, |
779 | StringRef(FormatString, N - 1)); |
780 | } |
781 | |
782 | |
783 | |
784 | void ConvertArgToString(ArgumentKind Kind, intptr_t Val, |
785 | StringRef Modifier, StringRef Argument, |
786 | ArrayRef<ArgumentValue> PrevArgs, |
787 | SmallVectorImpl<char> &Output, |
788 | ArrayRef<intptr_t> QualTypeVals) const { |
789 | ArgToStringFn(Kind, Val, Modifier, Argument, PrevArgs, Output, |
790 | ArgToStringCookie, QualTypeVals); |
791 | } |
792 | |
793 | void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie) { |
794 | ArgToStringFn = Fn; |
795 | ArgToStringCookie = Cookie; |
796 | } |
797 | |
798 | |
799 | |
800 | void notePriorDiagnosticFrom(const DiagnosticsEngine &Other) { |
801 | LastDiagLevel = Other.LastDiagLevel; |
802 | } |
803 | |
804 | |
805 | |
806 | void Reset(); |
807 | |
808 | |
809 | |
810 | |
811 | |
812 | |
813 | |
814 | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | bool isIgnored(unsigned DiagID, SourceLocation Loc) const { |
821 | return Diags->getDiagnosticSeverity(DiagID, Loc, *this) == |
822 | diag::Severity::Ignored; |
823 | } |
824 | |
825 | |
826 | |
827 | |
828 | |
829 | |
830 | |
831 | |
832 | |
833 | |
834 | |
835 | Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const { |
836 | return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this); |
837 | } |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | |
845 | |
846 | |
847 | inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID); |
848 | inline DiagnosticBuilder Report(unsigned DiagID); |
849 | |
850 | void Report(const StoredDiagnostic &storedDiag); |
851 | |
852 | |
853 | bool isDiagnosticInFlight() const { |
854 | return CurDiagID != std::numeric_limits<unsigned>::max(); |
855 | } |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | |
862 | |
863 | |
864 | |
865 | |
866 | |
867 | |
868 | |
869 | |
870 | |
871 | |
872 | |
873 | |
874 | |
875 | |
876 | |
877 | |
878 | void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "", |
879 | StringRef Arg2 = ""); |
880 | |
881 | |
882 | void Clear() { CurDiagID = std::numeric_limits<unsigned>::max(); } |
883 | |
884 | |
885 | StringRef getFlagValue() const { return FlagValue; } |
886 | |
887 | private: |
888 | |
889 | |
890 | |
891 | |
892 | |
893 | |
894 | friend class Diagnostic; |
895 | friend class DiagnosticBuilder; |
896 | friend class DiagnosticErrorTrap; |
897 | friend class DiagnosticIDs; |
898 | friend class PartialDiagnostic; |
899 | |
900 | |
901 | void ReportDelayed(); |
902 | |
903 | |
904 | SourceLocation CurDiagLoc; |
905 | |
906 | |
907 | |
908 | |
909 | |
910 | unsigned CurDiagID; |
911 | |
912 | enum { |
913 | |
914 | |
915 | |
916 | |
917 | |
918 | MaxArguments = 10, |
919 | }; |
920 | |
921 | |
922 | signed char NumDiagArgs; |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | unsigned char DiagArgumentsKind[MaxArguments]; |
930 | |
931 | |
932 | |
933 | |
934 | |
935 | std::string DiagArgumentsStr[MaxArguments]; |
936 | |
937 | |
938 | |
939 | |
940 | |
941 | |
942 | intptr_t DiagArgumentsVal[MaxArguments]; |
943 | |
944 | |
945 | SmallVector<CharSourceRange, 8> DiagRanges; |
946 | |
947 | |
948 | |
949 | SmallVector<FixItHint, 8> DiagFixItHints; |
950 | |
951 | DiagnosticMapping makeUserMapping(diag::Severity Map, SourceLocation L) { |
952 | bool isPragma = L.isValid(); |
953 | DiagnosticMapping Mapping = |
954 | DiagnosticMapping::Make(Map, , isPragma); |
955 | |
956 | |
957 | |
958 | if (isPragma) { |
959 | Mapping.setNoWarningAsError(true); |
960 | Mapping.setNoErrorAsFatal(true); |
961 | } |
962 | |
963 | return Mapping; |
964 | } |
965 | |
966 | |
967 | |
968 | |
969 | bool ProcessDiag() { |
970 | return Diags->ProcessDiag(*this); |
971 | } |
972 | |
973 | |
974 | |
975 | protected: |
976 | friend class ASTReader; |
977 | friend class ASTWriter; |
978 | |
979 | |
980 | |
981 | |
982 | |
983 | friend class Sema; |
984 | |
985 | |
986 | |
987 | |
988 | bool EmitCurrentDiagnostic(bool Force = false); |
989 | |
990 | unsigned getCurrentDiagID() const { return CurDiagID; } |
991 | |
992 | SourceLocation getCurrentDiagLoc() const { return CurDiagLoc; } |
993 | |
994 | |
995 | }; |
996 | |
997 | |
998 | |
999 | |
1000 | class DiagnosticErrorTrap { |
1001 | DiagnosticsEngine &Diag; |
1002 | unsigned NumErrors; |
1003 | unsigned NumUnrecoverableErrors; |
1004 | |
1005 | public: |
1006 | explicit DiagnosticErrorTrap(DiagnosticsEngine &Diag) |
1007 | : Diag(Diag) { reset(); } |
1008 | |
1009 | |
1010 | |
1011 | bool hasErrorOccurred() const { |
1012 | return Diag.TrapNumErrorsOccurred > NumErrors; |
1013 | } |
1014 | |
1015 | |
1016 | |
1017 | bool hasUnrecoverableErrorOccurred() const { |
1018 | return Diag.TrapNumUnrecoverableErrorsOccurred > NumUnrecoverableErrors; |
1019 | } |
1020 | |
1021 | |
1022 | void reset() { |
1023 | NumErrors = Diag.TrapNumErrorsOccurred; |
1024 | NumUnrecoverableErrors = Diag.TrapNumUnrecoverableErrorsOccurred; |
1025 | } |
1026 | }; |
1027 | |
1028 | |
1029 | |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
1035 | |
1036 | |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | class DiagnosticBuilder { |
1045 | friend class DiagnosticsEngine; |
1046 | friend class PartialDiagnostic; |
1047 | |
1048 | mutable DiagnosticsEngine *DiagObj = nullptr; |
1049 | mutable unsigned NumArgs = 0; |
1050 | |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | mutable bool IsActive = false; |
1057 | |
1058 | |
1059 | |
1060 | mutable bool IsForceEmit = false; |
1061 | |
1062 | DiagnosticBuilder() = default; |
1063 | |
1064 | explicit DiagnosticBuilder(DiagnosticsEngine *diagObj) |
1065 | : DiagObj(diagObj), IsActive(true) { |
1066 | (0) . __assert_fail ("diagObj && \"DiagnosticBuilder requires a valid DiagnosticsEngine!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1066, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!"); |
1067 | diagObj->DiagRanges.clear(); |
1068 | diagObj->DiagFixItHints.clear(); |
1069 | } |
1070 | |
1071 | protected: |
1072 | void FlushCounts() { |
1073 | DiagObj->NumDiagArgs = NumArgs; |
1074 | } |
1075 | |
1076 | |
1077 | void Clear() const { |
1078 | DiagObj = nullptr; |
1079 | IsActive = false; |
1080 | IsForceEmit = false; |
1081 | } |
1082 | |
1083 | |
1084 | bool isActive() const { return IsActive; } |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | bool Emit() { |
1094 | |
1095 | |
1096 | if (!isActive()) return false; |
1097 | |
1098 | |
1099 | |
1100 | FlushCounts(); |
1101 | |
1102 | |
1103 | bool Result = DiagObj->EmitCurrentDiagnostic(IsForceEmit); |
1104 | |
1105 | |
1106 | Clear(); |
1107 | |
1108 | return Result; |
1109 | } |
1110 | |
1111 | public: |
1112 | |
1113 | |
1114 | DiagnosticBuilder(const DiagnosticBuilder &D) { |
1115 | DiagObj = D.DiagObj; |
1116 | IsActive = D.IsActive; |
1117 | IsForceEmit = D.IsForceEmit; |
1118 | D.Clear(); |
1119 | NumArgs = D.NumArgs; |
1120 | } |
1121 | |
1122 | DiagnosticBuilder &operator=(const DiagnosticBuilder &) = delete; |
1123 | |
1124 | |
1125 | ~DiagnosticBuilder() { |
1126 | Emit(); |
1127 | } |
1128 | |
1129 | |
1130 | static DiagnosticBuilder getEmpty() { |
1131 | return {}; |
1132 | } |
1133 | |
1134 | |
1135 | const DiagnosticBuilder &setForceEmit() const { |
1136 | IsForceEmit = true; |
1137 | return *this; |
1138 | } |
1139 | |
1140 | |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | operator bool() const { return true; } |
1148 | |
1149 | void AddString(StringRef S) const { |
1150 | (0) . __assert_fail ("isActive() && \"Clients must not add to cleared diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1150, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive() && "Clients must not add to cleared diagnostic!"); |
1151 | (0) . __assert_fail ("NumArgs < DiagnosticsEngine..MaxArguments && \"Too many arguments to diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1152, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(NumArgs < DiagnosticsEngine::MaxArguments && |
1152 | (0) . __assert_fail ("NumArgs < DiagnosticsEngine..MaxArguments && \"Too many arguments to diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1152, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Too many arguments to diagnostic!"); |
1153 | DiagObj->DiagArgumentsKind[NumArgs] = DiagnosticsEngine::ak_std_string; |
1154 | DiagObj->DiagArgumentsStr[NumArgs++] = S; |
1155 | } |
1156 | |
1157 | void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const { |
1158 | (0) . __assert_fail ("isActive() && \"Clients must not add to cleared diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1158, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive() && "Clients must not add to cleared diagnostic!"); |
1159 | (0) . __assert_fail ("NumArgs < DiagnosticsEngine..MaxArguments && \"Too many arguments to diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1160, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(NumArgs < DiagnosticsEngine::MaxArguments && |
1160 | (0) . __assert_fail ("NumArgs < DiagnosticsEngine..MaxArguments && \"Too many arguments to diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1160, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Too many arguments to diagnostic!"); |
1161 | DiagObj->DiagArgumentsKind[NumArgs] = Kind; |
1162 | DiagObj->DiagArgumentsVal[NumArgs++] = V; |
1163 | } |
1164 | |
1165 | void AddSourceRange(const CharSourceRange &R) const { |
1166 | (0) . __assert_fail ("isActive() && \"Clients must not add to cleared diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1166, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive() && "Clients must not add to cleared diagnostic!"); |
1167 | DiagObj->DiagRanges.push_back(R); |
1168 | } |
1169 | |
1170 | void AddFixItHint(const FixItHint &Hint) const { |
1171 | (0) . __assert_fail ("isActive() && \"Clients must not add to cleared diagnostic!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1171, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive() && "Clients must not add to cleared diagnostic!"); |
1172 | if (!Hint.isNull()) |
1173 | DiagObj->DiagFixItHints.push_back(Hint); |
1174 | } |
1175 | |
1176 | void addFlagValue(StringRef V) const { DiagObj->FlagValue = V; } |
1177 | }; |
1178 | |
1179 | struct AddFlagValue { |
1180 | StringRef Val; |
1181 | |
1182 | explicit AddFlagValue(StringRef V) : Val(V) {} |
1183 | }; |
1184 | |
1185 | |
1186 | |
1187 | |
1188 | |
1189 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1190 | const AddFlagValue V) { |
1191 | DB.addFlagValue(V.Val); |
1192 | return DB; |
1193 | } |
1194 | |
1195 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1196 | StringRef S) { |
1197 | DB.AddString(S); |
1198 | return DB; |
1199 | } |
1200 | |
1201 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1202 | const char *Str) { |
1203 | DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str), |
1204 | DiagnosticsEngine::ak_c_string); |
1205 | return DB; |
1206 | } |
1207 | |
1208 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) { |
1209 | DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint); |
1210 | return DB; |
1211 | } |
1212 | |
1213 | |
1214 | |
1215 | template <typename T> |
1216 | inline |
1217 | typename std::enable_if<std::is_same<T, bool>::value, |
1218 | const DiagnosticBuilder &>::type |
1219 | operator<<(const DiagnosticBuilder &DB, T I) { |
1220 | DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint); |
1221 | return DB; |
1222 | } |
1223 | |
1224 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1225 | unsigned I) { |
1226 | DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint); |
1227 | return DB; |
1228 | } |
1229 | |
1230 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1231 | tok::TokenKind I) { |
1232 | DB.AddTaggedVal(static_cast<unsigned>(I), DiagnosticsEngine::ak_tokenkind); |
1233 | return DB; |
1234 | } |
1235 | |
1236 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1237 | const IdentifierInfo *II) { |
1238 | DB.AddTaggedVal(reinterpret_cast<intptr_t>(II), |
1239 | DiagnosticsEngine::ak_identifierinfo); |
1240 | return DB; |
1241 | } |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | template <typename T> |
1248 | inline typename std::enable_if< |
1249 | std::is_same<typename std::remove_const<T>::type, DeclContext>::value, |
1250 | const DiagnosticBuilder &>::type |
1251 | operator<<(const DiagnosticBuilder &DB, T *DC) { |
1252 | DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC), |
1253 | DiagnosticsEngine::ak_declcontext); |
1254 | return DB; |
1255 | } |
1256 | |
1257 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1258 | SourceRange R) { |
1259 | DB.AddSourceRange(CharSourceRange::getTokenRange(R)); |
1260 | return DB; |
1261 | } |
1262 | |
1263 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1264 | ArrayRef<SourceRange> Ranges) { |
1265 | for (SourceRange R : Ranges) |
1266 | DB.AddSourceRange(CharSourceRange::getTokenRange(R)); |
1267 | return DB; |
1268 | } |
1269 | |
1270 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1271 | const CharSourceRange &R) { |
1272 | DB.AddSourceRange(R); |
1273 | return DB; |
1274 | } |
1275 | |
1276 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1277 | const FixItHint &Hint) { |
1278 | DB.AddFixItHint(Hint); |
1279 | return DB; |
1280 | } |
1281 | |
1282 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1283 | ArrayRef<FixItHint> Hints) { |
1284 | for (const FixItHint &Hint : Hints) |
1285 | DB.AddFixItHint(Hint); |
1286 | return DB; |
1287 | } |
1288 | |
1289 | |
1290 | |
1291 | using DiagNullabilityKind = std::pair<NullabilityKind, bool>; |
1292 | |
1293 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
1294 | DiagNullabilityKind nullability); |
1295 | |
1296 | inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc, |
1297 | unsigned DiagID) { |
1298 | (0) . __assert_fail ("CurDiagID == std..numeric_limits..max() && \"Multiple diagnostics in flight at once!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1299, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(CurDiagID == std::numeric_limits<unsigned>::max() && |
1299 | (0) . __assert_fail ("CurDiagID == std..numeric_limits..max() && \"Multiple diagnostics in flight at once!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1299, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Multiple diagnostics in flight at once!"); |
1300 | CurDiagLoc = Loc; |
1301 | CurDiagID = DiagID; |
1302 | FlagValue.clear(); |
1303 | return DiagnosticBuilder(this); |
1304 | } |
1305 | |
1306 | inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) { |
1307 | return Report(SourceLocation(), DiagID); |
1308 | } |
1309 | |
1310 | |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | |
1317 | class Diagnostic { |
1318 | const DiagnosticsEngine *DiagObj; |
1319 | StringRef StoredDiagMessage; |
1320 | |
1321 | public: |
1322 | explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {} |
1323 | Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage) |
1324 | : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {} |
1325 | |
1326 | const DiagnosticsEngine *getDiags() const { return DiagObj; } |
1327 | unsigned getID() const { return DiagObj->CurDiagID; } |
1328 | const SourceLocation &getLocation() const { return DiagObj->CurDiagLoc; } |
1329 | bool hasSourceManager() const { return DiagObj->hasSourceManager(); } |
1330 | SourceManager &getSourceManager() const { return DiagObj->getSourceManager();} |
1331 | |
1332 | unsigned getNumArgs() const { return DiagObj->NumDiagArgs; } |
1333 | |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const { |
1341 | (0) . __assert_fail ("Idx < getNumArgs() && \"Argument index out of range!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1341, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < getNumArgs() && "Argument index out of range!"); |
1342 | return (DiagnosticsEngine::ArgumentKind)DiagObj->DiagArgumentsKind[Idx]; |
1343 | } |
1344 | |
1345 | |
1346 | |
1347 | const std::string &getArgStdStr(unsigned Idx) const { |
1348 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_std_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1349, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) == DiagnosticsEngine::ak_std_string && |
1349 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_std_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1349, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1350 | return DiagObj->DiagArgumentsStr[Idx]; |
1351 | } |
1352 | |
1353 | |
1354 | |
1355 | const char *getArgCStr(unsigned Idx) const { |
1356 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_c_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1357, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) == DiagnosticsEngine::ak_c_string && |
1357 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_c_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1357, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1358 | return reinterpret_cast<const char*>(DiagObj->DiagArgumentsVal[Idx]); |
1359 | } |
1360 | |
1361 | |
1362 | |
1363 | int getArgSInt(unsigned Idx) const { |
1364 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_sint && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1365, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) == DiagnosticsEngine::ak_sint && |
1365 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_sint && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1365, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1366 | return (int)DiagObj->DiagArgumentsVal[Idx]; |
1367 | } |
1368 | |
1369 | |
1370 | |
1371 | unsigned getArgUInt(unsigned Idx) const { |
1372 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_uint && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1373, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) == DiagnosticsEngine::ak_uint && |
1373 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_uint && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1373, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1374 | return (unsigned)DiagObj->DiagArgumentsVal[Idx]; |
1375 | } |
1376 | |
1377 | |
1378 | |
1379 | const IdentifierInfo *getArgIdentifier(unsigned Idx) const { |
1380 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_identifierinfo && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1381, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) == DiagnosticsEngine::ak_identifierinfo && |
1381 | (0) . __assert_fail ("getArgKind(Idx) == DiagnosticsEngine..ak_identifierinfo && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1381, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1382 | return reinterpret_cast<IdentifierInfo*>(DiagObj->DiagArgumentsVal[Idx]); |
1383 | } |
1384 | |
1385 | |
1386 | |
1387 | intptr_t getRawArg(unsigned Idx) const { |
1388 | (0) . __assert_fail ("getArgKind(Idx) != DiagnosticsEngine..ak_std_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1389, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getArgKind(Idx) != DiagnosticsEngine::ak_std_string && |
1389 | (0) . __assert_fail ("getArgKind(Idx) != DiagnosticsEngine..ak_std_string && \"invalid argument accessor!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1389, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "invalid argument accessor!"); |
1390 | return DiagObj->DiagArgumentsVal[Idx]; |
1391 | } |
1392 | |
1393 | |
1394 | unsigned getNumRanges() const { |
1395 | return DiagObj->DiagRanges.size(); |
1396 | } |
1397 | |
1398 | |
1399 | const CharSourceRange &getRange(unsigned Idx) const { |
1400 | (0) . __assert_fail ("Idx < getNumRanges() && \"Invalid diagnostic range index!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1400, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < getNumRanges() && "Invalid diagnostic range index!"); |
1401 | return DiagObj->DiagRanges[Idx]; |
1402 | } |
1403 | |
1404 | |
1405 | ArrayRef<CharSourceRange> getRanges() const { |
1406 | return DiagObj->DiagRanges; |
1407 | } |
1408 | |
1409 | unsigned getNumFixItHints() const { |
1410 | return DiagObj->DiagFixItHints.size(); |
1411 | } |
1412 | |
1413 | const FixItHint &getFixItHint(unsigned Idx) const { |
1414 | (0) . __assert_fail ("Idx < getNumFixItHints() && \"Invalid index!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Diagnostic.h", 1414, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < getNumFixItHints() && "Invalid index!"); |
1415 | return DiagObj->DiagFixItHints[Idx]; |
1416 | } |
1417 | |
1418 | ArrayRef<FixItHint> getFixItHints() const { |
1419 | return DiagObj->DiagFixItHints; |
1420 | } |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | void FormatDiagnostic(SmallVectorImpl<char> &OutStr) const; |
1427 | |
1428 | |
1429 | |
1430 | void FormatDiagnostic(const char *DiagStr, const char *DiagEnd, |
1431 | SmallVectorImpl<char> &OutStr) const; |
1432 | }; |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | |
1438 | class StoredDiagnostic { |
1439 | unsigned ID; |
1440 | DiagnosticsEngine::Level Level; |
1441 | FullSourceLoc Loc; |
1442 | std::string Message; |
1443 | std::vector<CharSourceRange> Ranges; |
1444 | std::vector<FixItHint> FixIts; |
1445 | |
1446 | public: |
1447 | StoredDiagnostic() = default; |
1448 | StoredDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info); |
1449 | StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
1450 | StringRef Message); |
1451 | StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
1452 | StringRef Message, FullSourceLoc Loc, |
1453 | ArrayRef<CharSourceRange> Ranges, |
1454 | ArrayRef<FixItHint> Fixits); |
1455 | |
1456 | |
1457 | explicit operator bool() const { return !Message.empty(); } |
1458 | |
1459 | unsigned getID() const { return ID; } |
1460 | DiagnosticsEngine::Level getLevel() const { return Level; } |
1461 | const FullSourceLoc &getLocation() const { return Loc; } |
1462 | StringRef getMessage() const { return Message; } |
1463 | |
1464 | void setLocation(FullSourceLoc Loc) { this->Loc = Loc; } |
1465 | |
1466 | using range_iterator = std::vector<CharSourceRange>::const_iterator; |
1467 | |
1468 | range_iterator range_begin() const { return Ranges.begin(); } |
1469 | range_iterator range_end() const { return Ranges.end(); } |
1470 | unsigned range_size() const { return Ranges.size(); } |
1471 | |
1472 | ArrayRef<CharSourceRange> getRanges() const { |
1473 | return llvm::makeArrayRef(Ranges); |
1474 | } |
1475 | |
1476 | using fixit_iterator = std::vector<FixItHint>::const_iterator; |
1477 | |
1478 | fixit_iterator fixit_begin() const { return FixIts.begin(); } |
1479 | fixit_iterator fixit_end() const { return FixIts.end(); } |
1480 | unsigned fixit_size() const { return FixIts.size(); } |
1481 | |
1482 | ArrayRef<FixItHint> getFixIts() const { |
1483 | return llvm::makeArrayRef(FixIts); |
1484 | } |
1485 | }; |
1486 | |
1487 | |
1488 | |
1489 | class DiagnosticConsumer { |
1490 | protected: |
1491 | unsigned NumWarnings = 0; |
1492 | unsigned NumErrors = 0; |
1493 | |
1494 | public: |
1495 | DiagnosticConsumer() = default; |
1496 | virtual ~DiagnosticConsumer(); |
1497 | |
1498 | unsigned getNumErrors() const { return NumErrors; } |
1499 | unsigned getNumWarnings() const { return NumWarnings; } |
1500 | virtual void clear() { NumWarnings = NumErrors = 0; } |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | |
1513 | virtual void BeginSourceFile(const LangOptions &LangOpts, |
1514 | const Preprocessor *PP = nullptr) {} |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | virtual void EndSourceFile() {} |
1522 | |
1523 | |
1524 | |
1525 | virtual void finish() {} |
1526 | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | virtual bool IncludeInDiagnosticCounts() const; |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
1540 | const Diagnostic &Info); |
1541 | }; |
1542 | |
1543 | |
1544 | class IgnoringDiagConsumer : public DiagnosticConsumer { |
1545 | virtual void anchor(); |
1546 | |
1547 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
1548 | const Diagnostic &Info) override { |
1549 | |
1550 | } |
1551 | }; |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | class ForwardingDiagnosticConsumer : public DiagnosticConsumer { |
1557 | DiagnosticConsumer &Target; |
1558 | |
1559 | public: |
1560 | ForwardingDiagnosticConsumer(DiagnosticConsumer &Target) : Target(Target) {} |
1561 | ~ForwardingDiagnosticConsumer() override; |
1562 | |
1563 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
1564 | const Diagnostic &Info) override; |
1565 | void clear() override; |
1566 | |
1567 | bool IncludeInDiagnosticCounts() const override; |
1568 | }; |
1569 | |
1570 | |
1571 | struct TemplateDiffTypes { |
1572 | intptr_t FromType; |
1573 | intptr_t ToType; |
1574 | unsigned PrintTree : 1; |
1575 | unsigned PrintFromType : 1; |
1576 | unsigned ElideType : 1; |
1577 | unsigned ShowColors : 1; |
1578 | |
1579 | |
1580 | unsigned TemplateDiffUsed : 1; |
1581 | }; |
1582 | |
1583 | |
1584 | |
1585 | const char ToggleHighlight = 127; |
1586 | |
1587 | |
1588 | |
1589 | void ProcessWarningOptions(DiagnosticsEngine &Diags, |
1590 | const DiagnosticOptions &Opts, |
1591 | bool ReportDiags = true); |
1592 | |
1593 | } |
1594 | |
1595 | #endif |
1596 | |