From: Ted Kremenek Date: Fri, 23 Jan 2009 20:28:53 +0000 (+0000) Subject: Added virtual method DiagnosticClient::IncludeInDiagnosticCounts(). This is used... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cabe66811fe43835b8c5a0854552768fc53261e3;p=clang Added virtual method DiagnosticClient::IncludeInDiagnosticCounts(). This is used by Diagnostics to determine if a diagnostic sent to a given DiagnosticClient should be included in the count of diagnostics. The default implementation of this method returns 'true'. 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 --- diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h index 5613ad839b..ba6f253963 100644 --- a/include/clang/Analysis/PathSensitive/BugReporter.h +++ b/include/clang/Analysis/PathSensitive/BugReporter.h @@ -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::iterator iterator; iterator begin() { return Reports.begin(); } iterator end() { return Reports.end(); } diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 1588394190..a78f733315 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -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. diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index adb3325f53..e3735670cf 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -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; + } + } + } +} diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 340ef28846..2271095b59 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -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 &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; }