|
18 | 18 | #include "clang/Basic/DiagnosticOptions.h" |
19 | 19 | #include "clang/Basic/SourceLocation.h" |
20 | 20 | #include "clang/Basic/Specifiers.h" |
| 21 | +#include "clang/Basic/UnsignedOrNone.h" |
21 | 22 | #include "llvm/ADT/ArrayRef.h" |
22 | 23 | #include "llvm/ADT/DenseMap.h" |
23 | 24 | #include "llvm/ADT/FunctionExtras.h" |
@@ -49,6 +50,7 @@ class FileSystem; |
49 | 50 | namespace clang { |
50 | 51 |
|
51 | 52 | class DeclContext; |
| 53 | +class Diagnostic; |
52 | 54 | class DiagnosticBuilder; |
53 | 55 | class DiagnosticConsumer; |
54 | 56 | class IdentifierInfo; |
@@ -228,6 +230,8 @@ class DiagStorageAllocator { |
228 | 230 | class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
229 | 231 | public: |
230 | 232 | /// The level of the diagnostic, after it has been through mapping. |
| 233 | + // FIXME: Make this an alias for DiagnosticIDs::Level as soon as |
| 234 | + // we can use 'using enum'. |
231 | 235 | enum Level { |
232 | 236 | Ignored = DiagnosticIDs::Ignored, |
233 | 237 | Note = DiagnosticIDs::Note, |
@@ -420,10 +424,13 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
420 | 424 | bool empty() const { return Files.empty(); } |
421 | 425 |
|
422 | 426 | /// Clear out this map. |
423 | | - void clear() { |
| 427 | + void clear(bool Soft) { |
| 428 | + // Just clear the cache when in soft mode. |
424 | 429 | Files.clear(); |
425 | | - FirstDiagState = CurDiagState = nullptr; |
426 | | - CurDiagStateLoc = SourceLocation(); |
| 430 | + if (!Soft) { |
| 431 | + FirstDiagState = CurDiagState = nullptr; |
| 432 | + CurDiagStateLoc = SourceLocation(); |
| 433 | + } |
427 | 434 | } |
428 | 435 |
|
429 | 436 | /// Produce a debugging dump of the diagnostic state. |
@@ -532,7 +539,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
532 | 539 | /// |
533 | 540 | /// This is used to emit continuation diagnostics with the same level as the |
534 | 541 | /// diagnostic that they follow. |
535 | | - DiagnosticIDs::Level LastDiagLevel; |
| 542 | + Level LastDiagLevel; |
536 | 543 |
|
537 | 544 | /// Number of warnings reported |
538 | 545 | unsigned NumWarnings; |
@@ -777,18 +784,16 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
777 | 784 | /// the middle of another diagnostic. |
778 | 785 | /// |
779 | 786 | /// This can be used by clients who suppress diagnostics themselves. |
780 | | - void setLastDiagnosticIgnored(bool Ignored) { |
781 | | - if (LastDiagLevel == DiagnosticIDs::Fatal) |
| 787 | + void setLastDiagnosticIgnored(bool IsIgnored) { |
| 788 | + if (LastDiagLevel == Fatal) |
782 | 789 | FatalErrorOccurred = true; |
783 | | - LastDiagLevel = Ignored ? DiagnosticIDs::Ignored : DiagnosticIDs::Warning; |
| 790 | + LastDiagLevel = IsIgnored ? Ignored : Warning; |
784 | 791 | } |
785 | 792 |
|
786 | 793 | /// Determine whether the previous diagnostic was ignored. This can |
787 | 794 | /// be used by clients that want to determine whether notes attached to a |
788 | 795 | /// diagnostic will be suppressed. |
789 | | - bool isLastDiagnosticIgnored() const { |
790 | | - return LastDiagLevel == DiagnosticIDs::Ignored; |
791 | | - } |
| 796 | + bool isLastDiagnosticIgnored() const { return LastDiagLevel == Ignored; } |
792 | 797 |
|
793 | 798 | /// Controls whether otherwise-unmapped extension diagnostics are |
794 | 799 | /// mapped onto ignore/warning/error. |
@@ -918,6 +923,10 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
918 | 923 | /// Reset the state of the diagnostic object to its initial configuration. |
919 | 924 | /// \param[in] soft - if true, doesn't reset the diagnostic mappings and state |
920 | 925 | void Reset(bool soft = false); |
| 926 | + /// We keep a cache of FileIDs for diagnostics mapped by pragmas. These might |
| 927 | + /// get invalidated when diagnostics engine is shared across different |
| 928 | + /// compilations. Provide users with a way to reset that. |
| 929 | + void ResetPragmas(); |
921 | 930 |
|
922 | 931 | //===--------------------------------------------------------------------===// |
923 | 932 | // DiagnosticsEngine classification and reporting interfaces. |
@@ -1024,9 +1033,10 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { |
1024 | 1033 | /// Used to report a diagnostic that is finally fully formed. |
1025 | 1034 | /// |
1026 | 1035 | /// \returns true if the diagnostic was emitted, false if it was suppressed. |
1027 | | - bool ProcessDiag(const DiagnosticBuilder &DiagBuilder) { |
1028 | | - return Diags->ProcessDiag(*this, DiagBuilder); |
1029 | | - } |
| 1036 | + bool ProcessDiag(const DiagnosticBuilder &DiagBuilder); |
| 1037 | + |
| 1038 | + /// Forward a diagnostic to the DiagnosticConsumer. |
| 1039 | + void Report(Level DiagLevel, const Diagnostic &Info); |
1030 | 1040 |
|
1031 | 1041 | /// @name Diagnostic Emission |
1032 | 1042 | /// @{ |
|
0 commit comments