[PATCH] D61486: [Basic] Introduce active dummy DiagnosticBuilder
Nikolai Kosjar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 3 03:58:33 PDT 2019
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61486.197951.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190503/fc9e541f/attachment.bin>
More information about the cfe-commits
mailing list