Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: tools/clang/plugins/SuppressibleDiagnosticBuilder.h

Issue 1385193002: Bisect clang Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 246985 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/plugins/README.chromium ('k') | tools/clang/plugins/tests/base_refcounted.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/SuppressibleDiagnosticBuilder.h
diff --git a/tools/clang/plugins/SuppressibleDiagnosticBuilder.h b/tools/clang/plugins/SuppressibleDiagnosticBuilder.h
new file mode 100644
index 0000000000000000000000000000000000000000..a56e5169a1974d47e43157cb3a1caf283bec7ac1
--- /dev/null
+++ b/tools/clang/plugins/SuppressibleDiagnosticBuilder.h
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
+#define TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace chrome_checker {
+
+// A simple wrapper around DiagnosticBuilder that allows a diagnostic to be
+// suppressed. The intended use case is for helper functions that return a
+// DiagnosticBuilder, but only want to emit the diagnostic if some conditions
+// are met.
+class SuppressibleDiagnosticBuilder : public clang::DiagnosticBuilder {
+ public:
+ SuppressibleDiagnosticBuilder(clang::DiagnosticsEngine* diagnostics,
+ clang::SourceLocation loc,
+ unsigned diagnostic_id,
+ bool suppressed)
+ : DiagnosticBuilder(diagnostics->Report(loc, diagnostic_id)),
+ diagnostics_(diagnostics),
+ suppressed_(suppressed) {}
+
+ ~SuppressibleDiagnosticBuilder() {
+ if (suppressed_) {
+ // Clear the counts and underlying data, so the base class destructor
+ // doesn't try to emit the diagnostic.
+ FlushCounts();
+ Clear();
+ // Also clear the current diagnostic being processed by the
+ // DiagnosticsEngine, since it won't be emitted.
+ diagnostics_->Clear();
+ }
+ }
+
+ template <typename T>
+ friend const SuppressibleDiagnosticBuilder& operator<<(
+ const SuppressibleDiagnosticBuilder& builder,
+ const T& value) {
+ const DiagnosticBuilder& base_builder = builder;
+ base_builder << value;
+ return builder;
+ }
+
+ private:
+ clang::DiagnosticsEngine* const diagnostics_;
+ const bool suppressed_;
+};
+
+} // namespace chrome_checker
+
+#endif // TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
« no previous file with comments | « tools/clang/plugins/README.chromium ('k') | tools/clang/plugins/tests/base_refcounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698