[cfe-commits] r126281 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/VerifyDiagnosticsClient.cpp

Chandler Carruth chandlerc at gmail.com
Tue Feb 22 16:47:48 PST 2011


Author: chandlerc
Date: Tue Feb 22 18:47:48 2011
New Revision: 126281

URL: http://llvm.org/viewvc/llvm-project?rev=126281&view=rev
Log:
Switch the VerifyDiagnosticsClient to use PresumedLocs now that they
exist. Cheat and do this by adding some wrappers around the PresumedLoc
machinery that directly return the line and column number.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=126281&r1=126280&r2=126281&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb 22 18:47:48 2011
@@ -684,10 +684,10 @@
   /// before calling this method.
   unsigned getColumnNumber(FileID FID, unsigned FilePos, 
                            bool *Invalid = 0) const;
-  unsigned getSpellingColumnNumber(SourceLocation Loc,
-                                   bool *Invalid = 0) const;
+  unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid = 0) const;
   unsigned getInstantiationColumnNumber(SourceLocation Loc,
                                         bool *Invalid = 0) const;
+  unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid = 0) const;
 
 
   /// getLineNumber - Given a SourceLocation, return the spelling line number
@@ -695,10 +695,10 @@
   /// line offsets for the MemoryBuffer, so this is not cheap: use only when
   /// about to emit a diagnostic.
   unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = 0) const;
-
+  unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
   unsigned getInstantiationLineNumber(SourceLocation Loc, 
                                       bool *Invalid = 0) const;
-  unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
+  unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
 
   /// Return the filename or buffer identifier of the buffer the location is in.
   /// Note that this name does not respect #line directives.  Use getPresumedLoc

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=126281&r1=126280&r2=126281&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb 22 18:47:48 2011
@@ -823,6 +823,12 @@
   return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
 }
 
+unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
+                                                bool *Invalid) const {
+  if (isInvalid(Loc, Invalid)) return 0;
+  return getPresumedLoc(Loc).getColumn();
+}
+
 static LLVM_ATTRIBUTE_NOINLINE void
 ComputeLineNumbers(Diagnostic &Diag, ContentCache *FI,
                    llvm::BumpPtrAllocator &Alloc,
@@ -985,17 +991,22 @@
   return LineNo;
 }
 
+unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc, 
+                                              bool *Invalid) const {
+  if (isInvalid(Loc, Invalid)) return 0;
+  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
+  return getLineNumber(LocInfo.first, LocInfo.second);
+}
 unsigned SourceManager::getInstantiationLineNumber(SourceLocation Loc, 
                                                    bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return 0;
   std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
   return getLineNumber(LocInfo.first, LocInfo.second);
 }
-unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc, 
+unsigned SourceManager::getPresumedLineNumber(SourceLocation Loc,
                                               bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return 0;
-  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
-  return getLineNumber(LocInfo.first, LocInfo.second);
+  return getPresumedLoc(Loc).getLine();
 }
 
 /// getFileCharacteristic - return the file characteristic of the specified

Modified: cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp?rev=126281&r1=126280&r2=126281&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp (original)
+++ cfe/trunk/lib/Frontend/VerifyDiagnosticsClient.cpp Tue Feb 22 18:47:48 2011
@@ -369,7 +369,7 @@
     if (I->first.isInvalid() || !SourceMgr)
       OS << "\n  (frontend)";
     else
-      OS << "\n  Line " << SourceMgr->getInstantiationLineNumber(I->first);
+      OS << "\n  Line " << SourceMgr->getPresumedLineNumber(I->first);
     OS << ": " << I->second;
   }
 
@@ -391,7 +391,7 @@
     if (D.Location.isInvalid() || !SourceMgr)
       OS << "\n  (frontend)";
     else
-      OS << "\n  Line " << SourceMgr->getInstantiationLineNumber(D.Location);
+      OS << "\n  Line " << SourceMgr->getPresumedLineNumber(D.Location);
     OS << ": " << D.Text;
   }
 
@@ -413,12 +413,12 @@
 
   for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) {
     Directive& D = **I;
-    unsigned LineNo1 = SourceMgr.getInstantiationLineNumber(D.Location);
+    unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.Location);
 
     for (unsigned i = 0; i < D.Count; ++i) {
       DiagList::iterator II, IE;
       for (II = Right.begin(), IE = Right.end(); II != IE; ++II) {
-        unsigned LineNo2 = SourceMgr.getInstantiationLineNumber(II->first);
+        unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first);
         if (LineNo1 != LineNo2)
           continue;
 





More information about the cfe-commits mailing list