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

Ted Kremenek kremenek at apple.com
Tue Dec 11 14:57:36 PST 2007


Author: kremenek
Date: Tue Dec 11 16:57:35 2007
New Revision: 44887

URL: http://llvm.org/viewvc/llvm-project?rev=44887&view=rev
Log:
Modified the internals of Diagnostic and DiagnosticClient to use
SourceManager*'s instead of SourceManager&'s. This allows the client specify a
NULL SourceManager when using a default constructed SourceLocation. Thus the
SourceManager can be NULL when the SourceLocation's isValid() == false.

The interface to most clients of Diagnostic remains the same.
Diagnostic::Report() is overload to either accept a SourceLocation and a
SourceManager&, or neither. Thus clients that do not have a SourceManager
cannot specify a SourceLocation.

Modified TextDiagnostics* to use this new interface.
Modified the driver to not passed in SourceManager when warning about "-I-".

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

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

==============================================================================
--- cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/Basic/Diagnostic.cpp Tue Dec 11 16:57:35 2007
@@ -198,7 +198,7 @@
 /// compilation, return true, otherwise return false.  DiagID is a member of
 /// the diag::kind enum.  
 void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
-                        SourceManager& SrcMgr,
+                        SourceManager* SrcMgr,
                         const std::string *Strs, unsigned NumStrs,
                         const SourceRange *Ranges, unsigned NumRanges) {
   // Figure out the diagnostic level of this message.

Modified: cfe/trunk/Driver/TextDiagnosticBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.cpp?rev=44887&r1=44886&r2=44887&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.cpp Tue Dec 11 16:57:35 2007
@@ -21,7 +21,7 @@
                                             Diagnostic::Level Level,
                                             SourceLocation Pos,
                                             diag::kind ID,
-                                            SourceManager& SrcMgr,
+                                            SourceManager* SrcMgr,
                                             const std::string *Strs,
                                             unsigned NumStrs,
                                             const SourceRange *,

Modified: cfe/trunk/Driver/TextDiagnosticBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.h?rev=44887&r1=44886&r2=44887&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.h (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.h Tue Dec 11 16:57:35 2007
@@ -41,7 +41,7 @@
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 

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

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Tue Dec 11 16:57:35 2007
@@ -47,24 +47,24 @@
 /// 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,
-                                           SourceManager& SourceMgr,
+                                           SourceManager* SourceMgr,
                                            unsigned LineNo,
                                            std::string &CaratLine,
-                                           const std::string &SourceLine) {
+                                           const std::string &SourceLine) {  
   assert(CaratLine.size() == SourceLine.size() &&
          "Expect a correspondence between source and carat line!");
   if (!R.isValid()) return;
 
-  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
+  unsigned StartLineNo = SourceMgr->getLogicalLineNumber(R.getBegin());
   if (StartLineNo > LineNo) return;  // No intersection.
   
-  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
+  unsigned EndLineNo = SourceMgr->getLogicalLineNumber(R.getEnd());
   if (EndLineNo < LineNo) return;  // No intersection.
   
   // Compute the column number of the start.
   unsigned StartColNo = 0;
   if (StartLineNo == LineNo) {
-    StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());
+    StartColNo = SourceMgr->getLogicalColumnNumber(R.getBegin());
     if (StartColNo) --StartColNo;  // Zero base the col #.
   }
 
@@ -76,12 +76,12 @@
   // Compute the column number of the end.
   unsigned EndColNo = CaratLine.size();
   if (EndLineNo == LineNo) {
-    EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());
+    EndColNo = SourceMgr->getLogicalColumnNumber(R.getEnd());
     if (EndColNo) {
       --EndColNo;  // Zero base the col #.
       
       // Add in the length of the token, so that we cover multi-char tokens.
-      EndColNo += Lexer::MeasureTokenLength(R.getEnd(), SourceMgr);
+      EndColNo += Lexer::MeasureTokenLength(R.getEnd(), *SourceMgr);
     } else {
       EndColNo = CaratLine.size();
     }
@@ -102,7 +102,7 @@
                                              Diagnostic::Level Level, 
                                              SourceLocation Pos,
                                              diag::kind ID,
-                                             SourceManager& SourceMgr,
+                                             SourceManager* SourceMgr,
                                              const std::string *Strs,
                                              unsigned NumStrs,
                                              const SourceRange *Ranges,
@@ -111,25 +111,25 @@
   const char *LineStart = 0, *LineEnd = 0;
   
   if (Pos.isValid()) {
-    SourceLocation LPos = SourceMgr.getLogicalLoc(Pos);
-    LineNo = SourceMgr.getLineNumber(LPos);
+    SourceLocation LPos = SourceMgr->getLogicalLoc(Pos);
+    LineNo = SourceMgr->getLineNumber(LPos);
     
     // First, if this diagnostic is not in the main file, print out the
     // "included from" lines.
-    if (LastWarningLoc != SourceMgr.getIncludeLoc(LPos)) {
-      LastWarningLoc = SourceMgr.getIncludeLoc(LPos);
-      PrintIncludeStack(LastWarningLoc,SourceMgr);
+    if (LastWarningLoc != SourceMgr->getIncludeLoc(LPos)) {
+      LastWarningLoc = SourceMgr->getIncludeLoc(LPos);
+      PrintIncludeStack(LastWarningLoc,*SourceMgr);
     }
   
     // Compute the column number.  Rewind from the current position to the start
     // of the line.
-    ColNo = SourceMgr.getColumnNumber(LPos);
-    const char *TokLogicalPtr = SourceMgr.getCharacterData(LPos);
+    ColNo = SourceMgr->getColumnNumber(LPos);
+    const char *TokLogicalPtr = SourceMgr->getCharacterData(LPos);
     LineStart = TokLogicalPtr-ColNo+1;  // Column # is 1-based
   
     // Compute the line end.  Scan forward from the error position to the end of
     // the line.
-    const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(LPos.getFileID());
+    const llvm::MemoryBuffer *Buffer = SourceMgr->getBuffer(LPos.getFileID());
     const char *BufEnd = Buffer->getBufferEnd();
     LineEnd = TokLogicalPtr;
     while (LineEnd != BufEnd && 

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

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.h Tue Dec 11 16:57:35 2007
@@ -28,7 +28,7 @@
 
   void PrintIncludeStack(SourceLocation Pos, SourceManager& SrcMgr);
   void HighlightRange(const SourceRange &R,
-                      SourceManager& SrcMgr,
+                      SourceManager* SrcMgr,
                       unsigned LineNo,
                       std::string &CaratLine,
                       const std::string &SourceLine);
@@ -36,7 +36,7 @@
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 

Modified: cfe/trunk/Driver/TextDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.cpp?rev=44887&r1=44886&r2=44887&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.cpp (original)
+++ cfe/trunk/Driver/TextDiagnostics.cpp Tue Dec 11 16:57:35 2007
@@ -41,12 +41,12 @@
 
 bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
                                        SourceLocation Pos,
-                                       SourceManager& SourceMgr) {
+                                       SourceManager* SourceMgr) {
   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) {
-      if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) {
+      if (const FileEntry *F = SourceMgr->getFileEntryForLoc(Pos)) {
         DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
         if (DirInfo == DirectoryLookup::SystemHeaderDir ||
             DirInfo == DirectoryLookup::ExternCSystemHeaderDir)

Modified: cfe/trunk/Driver/TextDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.h?rev=44887&r1=44886&r2=44887&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.h (original)
+++ cfe/trunk/Driver/TextDiagnostics.h Tue Dec 11 16:57:35 2007
@@ -36,12 +36,12 @@
 
   virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
                                 SourceLocation Pos,
-                                SourceManager& SrcMgr);
+                                SourceManager* SrcMgr);
 
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 

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

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Dec 11 16:57:35 2007
@@ -1026,9 +1026,7 @@
   // -I- is a deprecated GCC feature, scan for it and reject it.
   for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
     if (I_dirs[i] == "-") {
-      Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported,
-                   SourceMgr);
-      
+      Diags.Report(diag::err_pp_I_dash_not_supported);      
       I_dirs.erase(I_dirs.begin()+i);
       --i;
     }

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

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Dec 11 16:57:35 2007
@@ -14,12 +14,12 @@
 #ifndef LLVM_CLANG_DIAGNOSTIC_H
 #define LLVM_CLANG_DIAGNOSTIC_H
 
+#include "clang/Basic/SourceLocation.h"
 #include <string>
 #include <cassert>
 
 namespace clang {
   class DiagnosticClient;
-  class SourceLocation;
   class SourceRange;
   class SourceManager;
   
@@ -149,7 +149,23 @@
   /// diag::kind enum.  
   void Report(SourceLocation Pos, unsigned DiagID, SourceManager& SrcMgr,
               const std::string *Strs = 0, unsigned NumStrs = 0,
-              const SourceRange *Ranges = 0, unsigned NumRanges = 0);
+              const SourceRange *Ranges = 0, unsigned NumRanges = 0) {
+    Report(Pos,DiagID,&SrcMgr,Strs,NumStrs,Ranges,NumRanges);
+  }
+    
+  
+  /// Report - Issue the message to the client.  DiagID is a member of the
+  /// diag::kind enum.  
+  void Report(unsigned DiagID, const std::string *Strs = 0,
+              unsigned NumStrs = 0, const SourceRange *Ranges = 0,
+              unsigned NumRanges = 0) {
+    Report(SourceLocation(),DiagID,NULL,Strs,NumStrs,Ranges,NumRanges);
+  }
+  
+private:
+  void Report(SourceLocation Pos, unsigned DiagID, SourceManager* SrcMgr,
+              const std::string *Strs, unsigned NumStrs,
+              const SourceRange *Ranges, unsigned NumRanges);
 };
 
 /// DiagnosticClient - This is an abstract interface implemented by clients of
@@ -162,13 +178,13 @@
   /// return true.
   virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
-                                SourceManager& SrcMgr) = 0;
+                                SourceManager* SrcMgr) = 0;
 
   /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.
   virtual void HandleDiagnostic(Diagnostic &Diags, 
                                 Diagnostic::Level DiagLevel, SourceLocation Pos,
-                                diag::kind ID, SourceManager& SrcMgr,
+                                diag::kind ID, SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs, const SourceRange *Ranges, 
                                 unsigned NumRanges) = 0;





More information about the cfe-commits mailing list