[PATCH] Use DiagnosticIDs::getWarningOption to pass check names.

Alexander Kornienko alexfh at google.com
Thu Jan 30 14:07:33 PST 2014


Hi klimek,

This patch depends on D2660. I'm posting it now as an example of usage
of functionality added in D2660.

http://llvm-reviews.chandlerc.com/D2661

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h

Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -41,9 +41,7 @@
                                          SourceLocation Loc,
                                          StringRef Description) {
   unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Warning, Description);
-  if (CheckNamesByDiagnosticID.count(ID) == 0)
-    CheckNamesByDiagnosticID.insert(std::make_pair(ID, CheckName.str()));
+      DiagnosticIDs::Warning, Description, CheckName);
   return DiagEngine->Report(Loc, ID);
 }
 
@@ -60,14 +58,6 @@
   Errors->push_back(Error);
 }
 
-StringRef ClangTidyContext::getCheckName(unsigned DiagnosticID) const {
-  llvm::DenseMap<unsigned, std::string>::const_iterator I =
-      CheckNamesByDiagnosticID.find(DiagnosticID);
-  if (I != CheckNamesByDiagnosticID.end())
-    return I->second;
-  return "";
-}
-
 ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx)
     : Context(Ctx) {
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
@@ -82,11 +72,12 @@
   // FIXME: Demultiplex diagnostics.
   // FIXME: Ensure that we don't get notes from user code related to errors
   // from non-user code.
-  if (Diags->getSourceManager().isInSystemHeader(Info.getLocation()))
+  if (Info.getDiags()->getSourceManager().isInSystemHeader(Info.getLocation()))
     return;
   if (DiagLevel != DiagnosticsEngine::Note) {
-    Errors.push_back(
-        ClangTidyError(Context.getCheckName(Info.getID()), getMessage(Info)));
+    Errors.push_back(ClangTidyError(
+        Info.getDiags()->getDiagnosticIDs()->getWarningOption(Info.getID()),
+        getMessage(Info)));
   } else {
     assert(!Errors.empty() &&
            "A diagnostic note can only be appended to a message.");
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -13,7 +13,6 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Refactoring.h"
-#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
 
@@ -88,19 +87,14 @@
   /// This is called from the \c ClangTidyCheck base class.
   void setSourceManager(SourceManager *SourceMgr);
 
-  /// \brief Returns the name of the clang-tidy check which produced this
-  /// diagnostic ID.
-  StringRef getCheckName(unsigned DiagnosticID) const;
-
 private:
   friend class ClangTidyDiagnosticConsumer; // Calls storeError().
 
   /// \brief Store a \c ClangTidyError.
   void storeError(const ClangTidyError &Error);
 
   SmallVectorImpl<ClangTidyError> *Errors;
   DiagnosticsEngine *DiagEngine;
-  llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
 };
 
 /// \brief A diagnostic consumer that turns each \c Diagnostic into a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2661.1.patch
Type: text/x-patch
Size: 3011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140130/325f0719/attachment.bin>


More information about the cfe-commits mailing list