[cfe-commits] r119731 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Checker/PathDiagnostic.cpp lib/Frontend/ASTMerge.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/TextDiagnosticBuffer.cpp lib/Frontend/TextDiagnosticPrinter.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Nov 18 12:06:46 PST 2010


Author: akirtzidis
Date: Thu Nov 18 14:06:46 2010
New Revision: 119731

URL: http://llvm.org/viewvc/llvm-project?rev=119731&view=rev
Log:
Since multiple diagnostics can share one diagnostic client, have the client keeping track
of the total number of warnings/errors reported.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Checker/PathDiagnostic.cpp
    cfe/trunk/lib/Frontend/ASTMerge.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Nov 18 14:06:46 2010
@@ -894,7 +894,15 @@
 /// DiagnosticClient - This is an abstract interface implemented by clients of
 /// the front-end, which formats and prints fully processed diagnostics.
 class DiagnosticClient {
+  unsigned NumWarnings;       // Number of warnings reported
+  unsigned NumErrors;         // Number of errors reported
+  
 public:
+  DiagnosticClient() : NumWarnings(0), NumErrors(0) { }
+
+  unsigned getNumErrors() const { return NumErrors; }
+  unsigned getNumWarnings() const { return NumWarnings; }
+
   virtual ~DiagnosticClient();
 
   /// BeginSourceFile - Callback to inform the diagnostic client that processing
@@ -924,8 +932,11 @@
 
   /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.
+  ///
+  /// Default implementation just keeps track of the total number of warnings
+  /// and errors.
   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
-                                const DiagnosticInfo &Info) = 0;
+                                const DiagnosticInfo &Info);
 };
 
 }  // end namespace clang

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu Nov 18 14:06:46 2010
@@ -145,6 +145,16 @@
 
 DiagnosticClient::~DiagnosticClient() {}
 
+void DiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
+                                        const DiagnosticInfo &Info) {
+  if (!IncludeInDiagnosticCounts())
+    return;
+
+  if (DiagLevel == Diagnostic::Warning)
+    ++NumWarnings;
+  else if (DiagLevel >= Diagnostic::Error)
+    ++NumErrors;
+}
 
 /// ModifierIs - Return true if the specified modifier matches specified string.
 template <std::size_t StrLen>

Modified: cfe/trunk/lib/Checker/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/PathDiagnostic.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/Checker/PathDiagnostic.cpp Thu Nov 18 14:06:46 2010
@@ -84,6 +84,8 @@
 
 void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
                                             const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticClient::HandleDiagnostic(DiagLevel, Info);
 
   // Create a PathDiagnostic with a single piece.
 

Modified: cfe/trunk/lib/Frontend/ASTMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTMerge.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTMerge.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTMerge.cpp Thu Nov 18 14:06:46 2010
@@ -69,15 +69,6 @@
       Importer.Import(*D);
     }
 
-    // Aggregate the number of warnings/errors from all diagnostics so
-    // that at CompilerInstance::ExecuteAction we can report the total numbers.
-    // FIXME: This is hacky, maybe keep track of total number of warnings/errors
-    // in DiagnosticClient and have CompilerInstance query that ?
-    CI.getDiagnostics().setNumWarnings(CI.getDiagnostics().getNumWarnings() +
-                                       Diags->getNumWarnings());
-    CI.getDiagnostics().setNumErrors(CI.getDiagnostics().getNumErrors() +
-                                     Diags->getNumErrors());
-
     delete Unit;
   }
 

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Nov 18 14:06:46 2010
@@ -440,6 +440,9 @@
 
 void StoredDiagnosticClient::HandleDiagnostic(Diagnostic::Level Level,
                                               const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticClient::HandleDiagnostic(Level, Info);
+
   StoredDiags.push_back(StoredDiagnostic(Level, Info));
 }
 

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Nov 18 14:06:46 2010
@@ -553,9 +553,10 @@
   }
 
   if (getDiagnosticOpts().ShowCarets) {
-    unsigned NumWarnings = getDiagnostics().getNumWarnings();
-    unsigned NumErrors = getDiagnostics().getNumErrors() - 
-                               getDiagnostics().getNumErrorsSuppressed();
+    // We can have multiple diagnostics sharing one diagnostic client.
+    // Get the total number of warnings/errors from the client.
+    unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings();
+    unsigned NumErrors = getDiagnostics().getClient()->getNumErrors();
     
     if (NumWarnings)
       OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s");

Modified: cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticBuffer.cpp Thu Nov 18 14:06:46 2010
@@ -20,6 +20,9 @@
 ///
 void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
                                             const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticClient::HandleDiagnostic(Level, Info);
+
   llvm::SmallString<100> Buf;
   Info.FormatDiagnostic(Buf);
   switch (Level) {

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=119731&r1=119730&r2=119731&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Thu Nov 18 14:06:46 2010
@@ -764,6 +764,9 @@
 
 void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
                                              const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticClient::HandleDiagnostic(Level, Info);
+
   // Keeps track of the the starting position of the location
   // information (e.g., "foo.c:10:4:") that precedes the error
   // message. We use this information to determine how long the





More information about the cfe-commits mailing list