]> granicus.if.org Git - clang/commitdiff
Since multiple diagnostics can share one diagnostic client, have the client keeping...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Nov 2010 20:06:46 +0000 (20:06 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Nov 2010 20:06:46 +0000 (20:06 +0000)
of the total number of warnings/errors reported.

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

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

index 3eab3c0429dc45d0bc9b59814b3e4b637d5af434..c3eaea153935d7cad6d7cd8f5f6ec538dbe0232a 100644 (file)
@@ -894,7 +894,15 @@ public:
 /// 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 @@ public:
 
   /// 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
index a26f49764c3d0d019a2ed0f41612dc3d98ba298a..858b70a712348a87efaf59e5b1ea6c2f24cf8676 100644 (file)
@@ -145,6 +145,16 @@ bool DiagnosticBuilder::Emit() {
 
 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>
index 1ddc08ee436c768f005be4c2077772d559afbba7..0f0dddc6d7819fe847272024f53f8cd1ca51d6ea 100644 (file)
@@ -84,6 +84,8 @@ PathDiagnostic::PathDiagnostic(llvm::StringRef bugtype, llvm::StringRef desc,
 
 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.
 
index 7c8763d09d9ec63a2074203a31398b193f1f4c2d..d4ed8d3e0385c33fcca31b5feff9cf2d062d8da6 100644 (file)
@@ -69,15 +69,6 @@ void ASTMergeAction::ExecuteAction() {
       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;
   }
 
index fb93fca84a3f0691b0174eaef2ca81ba2c266a13..3956cc23e350cccdf7d31fda392681a530a121bd 100644 (file)
@@ -440,6 +440,9 @@ public:
 
 void StoredDiagnosticClient::HandleDiagnostic(Diagnostic::Level Level,
                                               const DiagnosticInfo &Info) {
+  // Default implementation (Warnings/errors count).
+  DiagnosticClient::HandleDiagnostic(Level, Info);
+
   StoredDiags.push_back(StoredDiagnostic(Level, Info));
 }
 
index dafbef1824b20126a4e3f9974afae4659653fdf8..152dd6d5b6b637bb5dd0fb5c7382eafd46263ffc 100644 (file)
@@ -553,9 +553,10 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
   }
 
   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");
index fdf2ec8ccf5d016b64b4d15c4536ac08d134e3ee..069c86de137f66b2f92f6661b89e299d3990a9b8 100644 (file)
@@ -20,6 +20,9 @@ using namespace clang;
 ///
 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) {
index 2528777cd8c0a098846dc5a10c34300e0d29d49b..200054ab11ca60796425a4971ab5d02fbcd26087 100644 (file)
@@ -764,6 +764,9 @@ static bool PrintWordWrapped(llvm::raw_ostream &OS,
 
 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