[cfe-commits] r39650 - in /cfe/cfe/trunk/Driver: TextDiagnosticPrinter.cpp TextDiagnosticPrinter.h TextDiagnostics.cpp TextDiagnostics.h

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


Author: bwendlin
Date: Wed Jul 11 11:46:39 2007
New Revision: 39650

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

- Created a base class (TextDiagnostics) for all text diagnostic classes.
  Moved the "IgnoreDiagnostic" method up there, and created a method that
  will format the diagnostic string, replacing %# with the appropriate
  string. This is in preparation for adding a text diagnostic checker.

Added:
    cfe/cfe/trunk/Driver/TextDiagnostics.cpp   (with props)
    cfe/cfe/trunk/Driver/TextDiagnostics.h   (with props)
Modified:
    cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp
    cfe/cfe/trunk/Driver/TextDiagnosticPrinter.h

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

==============================================================================
--- cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/cfe/trunk/Driver/TextDiagnosticPrinter.cpp Wed Jul 11 11:46:39 2007
@@ -121,27 +121,6 @@
   return TheTok.getLength();
 }
 
-bool TextDiagnosticPrinter::IgnoreDiagnostic(Diagnostic::Level Level, 
-                                             SourceLocation Pos) {
-  if (Pos.isValid()) {
-    // If this is a warning or note, and if it a system header, suppress the
-    // diagnostic.
-    if (Level == Diagnostic::Warning ||
-        Level == Diagnostic::Note) {
-      SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
-      const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
-      if (F) {
-        DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
-        if (DirInfo == DirectoryLookup::SystemHeaderDir ||
-            DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
-          return true;
-      }
-    }
-  }
-
-  return false;
-}
-
 void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, 
                                              SourceLocation Pos,
                                              diag::kind ID,
@@ -197,18 +176,7 @@
     break;
   }
   
-  std::string Msg = Diagnostic::getDescription(ID);
-  
-  // Replace all instances of %0 in Msg with 'Extra'.
-  for (unsigned i = 0; i < Msg.size()-1; ++i) {
-    if (Msg[i] == '%' && isdigit(Msg[i+1])) {
-      unsigned StrNo = Msg[i+1]-'0';
-      Msg = std::string(Msg.begin(), Msg.begin()+i) +
-            (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
-            std::string(Msg.begin()+i+2, Msg.end());
-    }
-  }
-  cerr << Msg << "\n";
+  cerr << FormatDiagnostic(Level, ID, Strs, NumStrs) << "\n";
   
   if (!NoCaretDiagnostics && Pos.isValid()) {
     // Get the line of the source file.

Modified: cfe/cfe/trunk/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/TextDiagnosticPrinter.h?rev=39650&r1=39649&r2=39650&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/cfe/trunk/Driver/TextDiagnosticPrinter.h Wed Jul 11 11:46:39 2007
@@ -15,26 +15,18 @@
 #ifndef TEXT_DIAGNOSTIC_PRINTER_H_
 #define TEXT_DIAGNOSTIC_PRINTER_H_
 
-#include "clang/Basic/Diagnostic.h"
+#include "TextDiagnostics.h"
 #include "clang/Basic/SourceLocation.h"
 
 namespace llvm {
   namespace clang {
     class SourceManager;
-    class HeaderSearch;
-    class Preprocessor;
 
-    class TextDiagnosticPrinter : public DiagnosticClient {
-      SourceManager &SourceMgr;
+    class TextDiagnosticPrinter : public TextDiagnostics {
       SourceLocation LastWarningLoc;
-      HeaderSearch *TheHeaderSearch;
-      Preprocessor *ThePreprocessor;
     public:
       TextDiagnosticPrinter(SourceManager &sourceMgr)
-        : SourceMgr(sourceMgr) {}
-
-      void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
-      void setPreprocessor(Preprocessor &P) { ThePreprocessor = &P; }
+        : TextDiagnostics(sourceMgr) {}
 
       void PrintIncludeStack(SourceLocation Pos);
       void HighlightRange(const SourceRange &R, unsigned LineNo,
@@ -42,8 +34,6 @@
                           const std::string &SourceLine);
       unsigned GetTokenLength(SourceLocation Loc);
 
-      virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
-                                    SourceLocation Pos);
       virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
                                     SourceLocation Pos,
                                     diag::kind ID, const std::string *Strs,

Added: cfe/cfe/trunk/Driver/TextDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/TextDiagnostics.cpp?rev=39650&view=auto

==============================================================================
--- cfe/cfe/trunk/Driver/TextDiagnostics.cpp (added)
+++ cfe/cfe/trunk/Driver/TextDiagnostics.cpp Wed Jul 11 11:46:39 2007
@@ -0,0 +1,61 @@
+//===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the parent class for all text diagnostics.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TextDiagnostics.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/HeaderSearch.h"
+using namespace llvm;
+using namespace clang;
+
+TextDiagnostics:: ~TextDiagnostics() {}
+
+std::string TextDiagnostics::FormatDiagnostic(Diagnostic::Level Level,
+                                              diag::kind ID,
+                                              const std::string *Strs,
+                                              unsigned NumStrs) {
+  std::string Msg = Diagnostic::getDescription(ID);
+  
+  // Replace all instances of %0 in Msg with 'Extra'.
+  for (unsigned i = 0; i < Msg.size() - 1; ++i) {
+    if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
+      unsigned StrNo = Msg[i + 1] - '0';
+      Msg = std::string(Msg.begin(), Msg.begin() + i) +
+            (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
+            std::string(Msg.begin() + i + 2, Msg.end());
+    }
+  }
+
+  return Msg;
+}
+
+bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
+                                       SourceLocation Pos) {
+  if (Pos.isValid()) {
+    // If this is a warning or note, and if it a system header, suppress the
+    // diagnostic.
+    if (Level == Diagnostic::Warning ||
+        Level == Diagnostic::Note) {
+      SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
+      const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
+      if (F) {
+        DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
+        if (DirInfo == DirectoryLookup::SystemHeaderDir ||
+            DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
+          return true;
+      }
+    }
+  }
+
+  return false;
+}

Propchange: cfe/cfe/trunk/Driver/TextDiagnostics.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Driver/TextDiagnostics.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: cfe/cfe/trunk/Driver/TextDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/TextDiagnostics.h?rev=39650&view=auto

==============================================================================
--- cfe/cfe/trunk/Driver/TextDiagnostics.h (added)
+++ cfe/cfe/trunk/Driver/TextDiagnostics.h Wed Jul 11 11:46:39 2007
@@ -0,0 +1,55 @@
+//===--- TextDiagnostics.h - Text Diagnostics Checkers ----------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the parent class for all text diagnostics.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEXT_DIAGNOSTICS_H_
+#define TEXT_DIAGNOSTICS_H_
+
+#include "clang/Basic/Diagnostic.h"
+
+namespace llvm {
+  namespace clang {
+    class SourceManager;
+    class HeaderSearch;
+    class Preprocessor;
+
+    class TextDiagnostics : public DiagnosticClient {
+      HeaderSearch *TheHeaderSearch;
+    protected:
+      SourceManager &SourceMgr;
+      Preprocessor *ThePreprocessor;
+
+      std::string FormatDiagnostic(Diagnostic::Level Level,
+                                   diag::kind ID,
+                                   const std::string *Strs,
+                                   unsigned NumStrs);
+    public:
+      TextDiagnostics(SourceManager &sourceMgr) : SourceMgr(sourceMgr) {}
+      virtual ~TextDiagnostics();
+
+      void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
+      void setPreprocessor(Preprocessor &P) { ThePreprocessor = &P; }
+
+      virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
+                                    SourceLocation Pos);
+      virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+                                    SourceLocation Pos,
+                                    diag::kind ID, const std::string *Strs,
+                                    unsigned NumStrs,
+                                    const SourceRange *Ranges, 
+                                    unsigned NumRanges) = 0;
+    };
+
+  } // end namspace clang
+} // end namespace llvm
+
+#endif

Propchange: cfe/cfe/trunk/Driver/TextDiagnostics.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Driver/TextDiagnostics.h

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision





More information about the cfe-commits mailing list