[cfe-commits] r39615 - in /cfe/cfe/trunk: Basic/Diagnostic.cpp Driver/TextDiagnosticPrinter.cpp Driver/clang.cpp include/clang/Basic/Diagnostic.h

bwendlin at cs.uiuc.edu bwendlin at cs.uiuc.edu
Wed Jul 11 09:46:16 PDT 2007


Author: bwendlin
Date: Wed Jul 11 11:46:16 2007
New Revision: 39615

URL: http://llvm.org/viewvc/llvm-project?rev=39615&view=rev
Log:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Make the counting of errors and diagnostic messages sane. Place them into the
  Diagnostic class instead of in the DiagnosticClient class.

Modified:
    cfe/cfe/trunk/Basic/Diagnostic.cpp
    cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/include/clang/Basic/Diagnostic.h

Modified: cfe/cfe/trunk/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/Diagnostic.cpp?rev=39615&r1=39614&r2=39615&view=diff

==============================================================================
--- cfe/cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/cfe/trunk/Basic/Diagnostic.cpp Wed Jul 11 11:46:16 2007
@@ -59,6 +59,8 @@
   memset(DiagMappings, 0, sizeof(DiagMappings));
   
   ErrorOccurred = false;
+  NumDiagnostics = 0;
+  NumErrors = 0;
 }
 
 /// isNoteWarningOrExtension - Return true if the unmapped diagnostic level of
@@ -128,8 +130,10 @@
   if (DiagLevel == Diagnostic::Ignored)
     return;
   
-  if (DiagLevel >= Diagnostic::Error)
+  if (DiagLevel >= Diagnostic::Error) {
     ErrorOccurred = true;
+    ++NumErrors;
+  }
   
   // Finally, report it.
   Client.HandleDiagnostic(DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs,

Modified: cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=39615&r1=39614&r2=39615&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp Wed Jul 11 11:46:16 2007
@@ -47,7 +47,6 @@
        << ":" << LineNo << ":\n";
 }
 
-
 /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
 /// any characters in LineNo that intersect the SourceRange.
 void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, 
@@ -101,7 +100,6 @@
     CaratLine[i] = '~';
 }
 
-
 /// GetTokenLength - Given the source location of a token, determine its length.
 /// This is a fully general function that uses a lexer to relex the token.
 unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
@@ -123,7 +121,6 @@
   return TheTok.getLength();
 }
 
-
 void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, 
                                              SourceLocation Pos,
                                              diag::kind ID,
@@ -185,11 +182,11 @@
   
   switch (Level) {
   default: assert(0 && "Unknown diagnostic type!");
-  case Diagnostic::Note:                 cerr << "note: "; break;
-  case Diagnostic::Warning:              cerr << "warning: "; break;
-  case Diagnostic::Error:   ++NumErrors; cerr << "error: "; break;
-  case Diagnostic::Fatal:   ++NumErrors; cerr << "fatal error: "; break;
-  case Diagnostic::Sorry:   ++NumErrors; cerr << "sorry, unimplemented: ";
+  case Diagnostic::Note:    cerr << "note: "; break;
+  case Diagnostic::Warning: cerr << "warning: "; break;
+  case Diagnostic::Error:   cerr << "error: "; break;
+  case Diagnostic::Fatal:   cerr << "fatal error: "; break;
+  case Diagnostic::Sorry:   cerr << "sorry, unimplemented: ";
     break;
   }
   
@@ -252,6 +249,4 @@
     cerr << SourceLine << "\n";
     cerr << CaratLine << "\n";
   }
-  
-  ++NumDiagnostics;
 }

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39615&r1=39614&r2=39615&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:46:16 2007
@@ -808,7 +808,6 @@
     if (File) MainFileID = SourceMgr.createFileID(File, SourceLocation());
     if (MainFileID == 0) {
       std::cerr << "Error reading '" << InFile << "'!\n";
-      OurDiagnosticClient.incrNumErrors();
       return;
     }
   } else {
@@ -816,7 +815,6 @@
     if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB);
     if (MainFileID == 0) {
       std::cerr << "Error reading standard input!  Empty?\n";
-      OurDiagnosticClient.incrNumErrors();
       return;
     }
   }
@@ -951,9 +949,10 @@
     ProcessInputFile(InputFilenames[i], SourceMgr, Diags, OurDiagnosticClient,
                      HeaderInfo, *Target, LangInfo);
   
-  if (OurDiagnosticClient.getNumDiagnostics())
-    std::cerr << OurDiagnosticClient.getNumDiagnostics() << " diagnostic"
-              << (OurDiagnosticClient.getNumDiagnostics() == 1 ? "" : "s")
+  unsigned NumDiagnostics = Diags.getNumDiagnostics();
+  if (NumDiagnostics)
+    std::cerr << NumDiagnostics << " diagnostic"
+              << (NumDiagnostics == 1 ? "" : "s")
               << " generated.\n";
   
   if (Stats) {
@@ -963,5 +962,5 @@
     std::cerr << "\n";
   }
   
-  return OurDiagnosticClient.getNumErrors() != 0;
+  return Diags.getNumErrors() != 0;
 }

Modified: cfe/cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=39615&r1=39614&r2=39615&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jul 11 11:46:16 2007
@@ -59,6 +59,9 @@
   /// ErrorOccurred - This is set to true when an error is emitted, and is
   /// sticky.
   bool ErrorOccurred;
+
+  unsigned NumDiagnostics;    // Number of diagnostics reported
+  unsigned NumErrors;         // Number of diagnostics that are errors
 public:
   explicit Diagnostic(DiagnosticClient &client);
   
@@ -98,6 +101,9 @@
   }
   
   bool hasErrorOccurred() const { return ErrorOccurred; }
+
+  unsigned getNumErrors() const { return NumErrors; }
+  unsigned getNumDiagnostics() const { return NumDiagnostics; }
   
   //===--------------------------------------------------------------------===//
   // Diagnostic classification and reporting interfaces.
@@ -131,20 +137,10 @@
 /// DiagnosticClient - This is an abstract interface implemented by clients of
 /// the front-end, which formats and prints fully processed diagnostics.
 class DiagnosticClient {
-protected:
-  unsigned NumDiagnostics;
-  unsigned NumErrors;
 public:
-  DiagnosticClient() : NumDiagnostics(0), NumErrors(0) {}
   virtual ~DiagnosticClient();
 
-  unsigned getNumDiagnostics() const { return NumDiagnostics; }
-  unsigned getNumErrors() const { return NumErrors; }
-
-  void incrNumDiagnostics() { ++NumDiagnostics; }
-  void incrNumErrors() { ++NumErrors; }
-  
-  /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or 
+  /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.
   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, SourceLocation Pos,
                                 diag::kind ID, const std::string *Strs,





More information about the cfe-commits mailing list