]> granicus.if.org Git - clang/commitdiff
Added virtual method DiagnosticClient::IncludeInDiagnosticCounts(). This is used...
authorTed Kremenek <kremenek@apple.com>
Fri, 23 Jan 2009 20:28:53 +0000 (20:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 23 Jan 2009 20:28:53 +0000 (20:28 +0000)
Implemented DiagCollector::IncludeInDiagnosticCounts() to return 'false' so that the batching of diagnostics for use with BugReporter doesn't mess up the count of real diagnostics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62873 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/BugReporter.h
include/clang/Basic/Diagnostic.h
lib/Analysis/BugReporter.cpp
lib/Basic/Diagnostic.cpp

index 5613ad839beaedb8e80cb4ff0ce579e38c0bec97..ba6f25396388f226bfb65b05675401eaa2fb633d 100644 (file)
@@ -305,50 +305,12 @@ public:
   
   virtual ~DiagCollector() {}
   
-  virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
-                                const DiagnosticInfo &Info) {
-    
-    // FIXME: Use a map from diag::kind to BugType, instead of having just
-    //  one BugType.
-    const char *Desc = Info.getDiags()->getDescription(Info.getID());
-    Reports.push_back(DiagBugReport(Desc, D, Info.getLocation()));
-    DiagBugReport& R = Reports.back();
-    
-    for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
-      R.addRange(Info.getRange(i));
-    
-    // FIXME: This is losing/ignoring formatting.
-    for (unsigned i = 0, e = Info.getNumArgs(); i != e; ++i) {
-      switch (Info.getArgKind(i)) {
-      case Diagnostic::ak_std_string:   
-        R.addString(Info.getArgStdStr(i));
-        break;
-      case Diagnostic::ak_c_string:   
-        R.addString(Info.getArgCStr(i));
-        break;
-      case Diagnostic::ak_sint:
-        R.addString(llvm::itostr(Info.getArgSInt(i)));
-        break;
-      case Diagnostic::ak_uint:
-        R.addString(llvm::utostr_32(Info.getArgUInt(i)));
-        break;
-      case Diagnostic::ak_identifierinfo:
-        R.addString(Info.getArgIdentifier(i)->getName());
-        break;
-      case Diagnostic::ak_qualtype:
-      case Diagnostic::ak_declarationname: {
-        llvm::SmallString<64> Str;
-        Info.getDiags()->ConvertArgToString(Info.getArgKind(i),
-                                            Info.getRawArg(i), 0, 0, 0, 0, Str);
-        R.addString(std::string(Str.begin(), Str.end()));
-        break;
-      }
-      }
-    }
-  }
+  bool IncludeInDiagnosticCounts() const { return false; }
   
-  // Iterators.
+  void HandleDiagnostic(Diagnostic::Level DiagLevel,
+                        const DiagnosticInfo &Info);
   
+  // Iterators.
   typedef std::list<DiagBugReport>::iterator iterator;
   iterator begin() { return Reports.begin(); }
   iterator end() { return Reports.end(); }
index 15883941903b416fbc7dbd5e7e557de15cde29c1..a78f73331574a900ec38d05f7b25fbb5cdbd30a2 100644 (file)
@@ -484,6 +484,12 @@ public:
 class DiagnosticClient {
 public:
   virtual ~DiagnosticClient();
+  
+  /// IncludeInDiagnosticCounts - This method (whose default implementation
+  ///  returns true) indicates whether the diagnostics handled by this
+  ///  DiagnosticClient should be included in the number of diagnostics
+  ///  reported by Diagnostic.
+  virtual bool IncludeInDiagnosticCounts() const;
 
   /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.
index adb3325f53dcc781ceea1729e97bf8bf098e8cbf..e3735670cf63fbbcc109ddf9eeac595295bb868b 100644 (file)
@@ -823,4 +823,46 @@ void BugReporter::EmitBasicReport(const char* name, const char* category,
   for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
     EmitWarning(*I);
 }
+
+void DiagCollector::HandleDiagnostic(Diagnostic::Level DiagLevel,
+                                     const DiagnosticInfo &Info) {
+  
+  // FIXME: Use a map from diag::kind to BugType, instead of having just
+  //  one BugType.
+  const char *Desc = Info.getDiags()->getDescription(Info.getID());
+  Reports.push_back(DiagBugReport(Desc, D, Info.getLocation()));
+  DiagBugReport& R = Reports.back();
+  
+  for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
+    R.addRange(Info.getRange(i));
+  
+  // FIXME: This is losing/ignoring formatting.
+  for (unsigned i = 0, e = Info.getNumArgs(); i != e; ++i) {
+    switch (Info.getArgKind(i)) {
+      case Diagnostic::ak_std_string:   
+        R.addString(Info.getArgStdStr(i));
+        break;
+      case Diagnostic::ak_c_string:   
+        R.addString(Info.getArgCStr(i));
+        break;
+      case Diagnostic::ak_sint:
+        R.addString(llvm::itostr(Info.getArgSInt(i)));
+        break;
+      case Diagnostic::ak_uint:
+        R.addString(llvm::utostr_32(Info.getArgUInt(i)));
+        break;
+      case Diagnostic::ak_identifierinfo:
+        R.addString(Info.getArgIdentifier(i)->getName());
+        break;
+      case Diagnostic::ak_qualtype:
+      case Diagnostic::ak_declarationname: {
+        llvm::SmallString<64> Str;
+        Info.getDiags()->ConvertArgToString(Info.getArgKind(i),
+                                            Info.getRawArg(i), 0, 0, 0, 0, Str);
+        R.addString(std::string(Str.begin(), Str.end()));
+        break;
+      }
+    }
+  }
+}
                                   
index 340ef28846c7e35aca5133309e12419429c53dfe..2271095b59631851674dd847d4082a2ee38a224f 100644 (file)
@@ -255,7 +255,7 @@ void Diagnostic::ProcessDiag() {
 
   // Finally, report it.
   Client->HandleDiagnostic(DiagLevel, Info);
-  ++NumDiagnostics;
+  if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
 }
 
 
@@ -551,3 +551,9 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
     }
   }
 }
+
+/// IncludeInDiagnosticCounts - This method (whose default implementation
+///  returns true) indicates whether the diagnostics handled by this
+///  DiagnosticClient should be included in the number of diagnostics
+///  reported by Diagnostic.
+bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; }