nik created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

...which does not emit anything.

This dummy is useful for filtering. Code expecting a DiagnosticBuilder
object can get a dummy and report further details, without
knowing/checking whether this is needed at all.


Repository:
  rC Clang

https://reviews.llvm.org/D61486

Files:
  include/clang/Basic/Diagnostic.h


Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -1055,6 +1055,9 @@
   // Emit() would end up with if we used that as our status variable.
   mutable bool IsActive = false;
 
+  /// Flag indicating an active dummy builder that will not emit anything.
+  mutable bool IsDummy = false;
+
   /// Flag indicating that this diagnostic is being emitted via a
   /// call to ForceEmit.
   mutable bool IsForceEmit = false;
@@ -1077,6 +1080,7 @@
   void Clear() const {
     DiagObj = nullptr;
     IsActive = false;
+    IsDummy = false;
     IsForceEmit = false;
   }
 
@@ -1095,6 +1099,12 @@
     // (or by a subclass, as in SemaDiagnosticBuilder).
     if (!isActive()) return false;
 
+    if (IsDummy) {
+      DiagObj->Clear();
+      Clear();
+      return false;
+    }
+
     // When emitting diagnostics, we set the final argument count into
     // the DiagnosticsEngine object.
     FlushCounts();
@@ -1114,6 +1124,7 @@
   DiagnosticBuilder(const DiagnosticBuilder &D) {
     DiagObj = D.DiagObj;
     IsActive = D.IsActive;
+    IsDummy = D.IsDummy;
     IsForceEmit = D.IsForceEmit;
     D.Clear();
     NumArgs = D.NumArgs;
@@ -1131,6 +1142,13 @@
     return {};
   }
 
+  /// Retrieve an active diagnostic builder that will not emit anything.
+  static DiagnosticBuilder getDummy(DiagnosticsEngine *diagObj) {
+    DiagnosticBuilder D(diagObj);
+    D.IsDummy = true;
+    return D;
+  }
+
   /// Forces the diagnostic to be emitted.
   const DiagnosticBuilder &setForceEmit() const {
     IsForceEmit = true;


Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -1055,6 +1055,9 @@
   // Emit() would end up with if we used that as our status variable.
   mutable bool IsActive = false;
 
+  /// Flag indicating an active dummy builder that will not emit anything.
+  mutable bool IsDummy = false;
+
   /// Flag indicating that this diagnostic is being emitted via a
   /// call to ForceEmit.
   mutable bool IsForceEmit = false;
@@ -1077,6 +1080,7 @@
   void Clear() const {
     DiagObj = nullptr;
     IsActive = false;
+    IsDummy = false;
     IsForceEmit = false;
   }
 
@@ -1095,6 +1099,12 @@
     // (or by a subclass, as in SemaDiagnosticBuilder).
     if (!isActive()) return false;
 
+    if (IsDummy) {
+      DiagObj->Clear();
+      Clear();
+      return false;
+    }
+
     // When emitting diagnostics, we set the final argument count into
     // the DiagnosticsEngine object.
     FlushCounts();
@@ -1114,6 +1124,7 @@
   DiagnosticBuilder(const DiagnosticBuilder &D) {
     DiagObj = D.DiagObj;
     IsActive = D.IsActive;
+    IsDummy = D.IsDummy;
     IsForceEmit = D.IsForceEmit;
     D.Clear();
     NumArgs = D.NumArgs;
@@ -1131,6 +1142,13 @@
     return {};
   }
 
+  /// Retrieve an active diagnostic builder that will not emit anything.
+  static DiagnosticBuilder getDummy(DiagnosticsEngine *diagObj) {
+    DiagnosticBuilder D(diagObj);
+    D.IsDummy = true;
+    return D;
+  }
+
   /// Forces the diagnostic to be emitted.
   const DiagnosticBuilder &setForceEmit() const {
     IsForceEmit = true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to