[cfe-commits] r63698 - in /cfe/trunk: include/clang/Basic/SourceLocation.h include/clang/Basic/SourceManager.h lib/Analysis/GRExprEngine.cpp lib/Basic/SourceLocation.cpp lib/Basic/SourceManager.cpp lib/Driver/HTMLDiagnostics.cpp lib/Driver/TextDiagnosticPrinter.cpp

Chris Lattner sabre at nondot.org
Tue Feb 3 16:55:58 PST 2009


Author: lattner
Date: Tue Feb  3 18:55:58 2009
New Revision: 63698

URL: http://llvm.org/viewvc/llvm-project?rev=63698&view=rev
Log:
make SM::getColumnNumber take a predecomposed FileID/offset, which
makes it clear to clients that they have to pick an instantiation
or spelling location before calling it and allows optimization based
on that.

Modified:
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Basic/SourceLocation.cpp
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Driver/HTMLDiagnostics.cpp
    cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue Feb  3 18:55:58 2009
@@ -201,7 +201,6 @@
   FullSourceLoc getSpellingLoc() const;
 
   unsigned getLineNumber() const;
-  unsigned getColumnNumber() const;
   
   unsigned getInstantiationLineNumber() const;
   unsigned getInstantiationColumnNumber() const;

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb  3 18:55:58 2009
@@ -481,14 +481,9 @@
   /// returns zero if the column number isn't known.  This may only be called on
   /// a file sloc, so you must choose a spelling or instantiation location
   /// before calling this method.
-  unsigned getColumnNumber(SourceLocation Loc) const;
-  
-  unsigned getSpellingColumnNumber(SourceLocation Loc) const {
-    return getColumnNumber(getSpellingLoc(Loc));
-  }
-  unsigned getInstantiationColumnNumber(SourceLocation Loc) const {
-    return getColumnNumber(getInstantiationLoc(Loc));
-  }
+  unsigned getColumnNumber(FileID FID, unsigned FilePos) const;
+  unsigned getSpellingColumnNumber(SourceLocation Loc) const;
+  unsigned getInstantiationColumnNumber(SourceLocation Loc) const;
   
   
   /// getLineNumber - Given a SourceLocation, return the spelling line number

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=63698&r1=63697&r2=63698&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Tue Feb  3 18:55:58 2009
@@ -2783,8 +2783,10 @@
           
           if (SLoc.isFileID()) {        
             Out << "\\lline="
-              << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
-              << GraphPrintSourceManager->getColumnNumber(SLoc) << "\\l";
+              << GraphPrintSourceManager->getInstantiationLineNumber(SLoc)
+              << " col="
+              << GraphPrintSourceManager->getInstantiationColumnNumber(SLoc)
+              << "\\l";
           }
           
           if (GraphPrintCheckerState->isImplicitNullDeref(N))
@@ -2827,8 +2829,9 @@
           
           if (SLoc.isFileID()) {
             Out << "\\lline="
-              << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
-              << GraphPrintSourceManager->getColumnNumber(SLoc);
+              << GraphPrintSourceManager->getInstantiationLineNumber(SLoc)
+              << " col="
+              << GraphPrintSourceManager->getInstantiationColumnNumber(SLoc);
           }
             
           if (isa<SwitchStmt>(T)) {

Modified: cfe/trunk/lib/Basic/SourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceLocation.cpp?rev=63698&r1=63697&r2=63698&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceLocation.cpp (original)
+++ cfe/trunk/lib/Basic/SourceLocation.cpp Tue Feb  3 18:55:58 2009
@@ -83,12 +83,6 @@
   return SrcMgr->getLineNumber(*this);
 }
 
-unsigned FullSourceLoc::getColumnNumber() const {
-  assert(isValid());
-  return SrcMgr->getColumnNumber(*this);
-}
-
-
 unsigned FullSourceLoc::getInstantiationLineNumber() const {
   assert(isValid());
   return SrcMgr->getInstantiationLineNumber(*this);

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=63698&r1=63697&r2=63698&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb  3 18:55:58 2009
@@ -112,9 +112,6 @@
 };
 } // namespace clang
 
-
-
-
 unsigned LineTableInfo::getLineTableFilenameID(const char *Ptr, unsigned Len) {
   // Look up the filename in the string table, returning the pre-existing value
   // if it exists.
@@ -466,23 +463,28 @@
 
 
 /// getColumnNumber - Return the column # for the specified file position.
-/// this is significantly cheaper to compute than the line number.  This returns
-/// zero if the column number isn't known.
-unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
-  if (Loc.isInvalid()) return 0;
-  assert(Loc.isFileID() && "Don't know what part of instantiation loc to get");
+/// this is significantly cheaper to compute than the line number.
+unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos) const {
+  const char *Buf = getBuffer(FID)->getBufferStart();
   
-  std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
-  unsigned FilePos = LocInfo.second;
-  
-  const char *Buf = getBuffer(LocInfo.first)->getBufferStart();
-
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
     --LineStart;
   return FilePos-LineStart+1;
 }
 
+unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc) const {
+  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
+  return getColumnNumber(LocInfo.first, LocInfo.second);
+}
+
+unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc) const {
+  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
+  return getColumnNumber(LocInfo.first, LocInfo.second);
+}
+
+
+
 static void ComputeLineNumbers(ContentCache* FI,
                                llvm::BumpPtrAllocator &Alloc) DISABLE_INLINE;
 static void ComputeLineNumbers(ContentCache* FI, llvm::BumpPtrAllocator &Alloc){ 
@@ -634,8 +636,9 @@
   if (Loc.isInvalid()) return PresumedLoc();
   
   // Presumed locations are always for instantiation points.
+  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
   Loc = getInstantiationLoc(Loc);
-  
+
   // FIXME: Could just decompose Loc once!
   
   const SrcMgr::FileInfo &FI = getSLocEntry(getFileID(Loc)).getFile();
@@ -646,7 +649,8 @@
   const char *Filename = 
     C->Entry ? C->Entry->getName() : C->getBuffer()->getBufferIdentifier();
   
-  return PresumedLoc(Filename, getLineNumber(Loc), getColumnNumber(Loc),
+  return PresumedLoc(Filename, getLineNumber(Loc),
+                     getColumnNumber(LocInfo.first, LocInfo.second),
                      FI.getIncludeLoc());
 }
 

Modified: cfe/trunk/lib/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/HTMLDiagnostics.cpp?rev=63698&r1=63697&r2=63698&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Driver/HTMLDiagnostics.cpp Tue Feb  3 18:55:58 2009
@@ -336,20 +336,19 @@
     return;  
   
   SourceManager &SM = R.getSourceMgr();
-  FullSourceLoc LPos = Pos.getInstantiationLoc();
-  FileID FID = SM.getFileID(LPos);
-  assert(&LPos.getManager() == &SM && "SourceManagers are different!");
+  assert(&Pos.getManager() == &SM && "SourceManagers are different!");
+  std::pair<FileID, unsigned> LPosInfo = SM.getDecomposedInstantiationLoc(Pos);
   
-  if (SM.getFileID(LPos) != BugFileID)
+  if (LPosInfo.first != BugFileID)
     return;
   
-  const llvm::MemoryBuffer *Buf = SM.getBuffer(FID);
+  const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
   const char* FileStart = Buf->getBufferStart();  
   
   // Compute the column number.  Rewind from the current position to the start
   // of the line.
-  unsigned ColNo = LPos.getColumnNumber();
-  const char *TokInstantiationPtr = LPos.getCharacterData();
+  unsigned ColNo = SM.getColumnNumber(LPosInfo.first, LPosInfo.second);
+  const char *TokInstantiationPtr =Pos.getInstantiationLoc().getCharacterData();
   const char *LineStart = TokInstantiationPtr-ColNo;
 
   // Only compute LineEnd if we display below a line.
@@ -445,7 +444,7 @@
     }
     
     SourceLocation Loc = 
-      SM.getLocForStartOfFile(FID).getFileLocWithOffset(DisplayPos);
+      SM.getLocForStartOfFile(LPosInfo.first).getFileLocWithOffset(DisplayPos);
     R.InsertStrBefore(Loc, os.str());
   }
   
@@ -453,7 +452,7 @@
   
   for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end();
         I != E; ++I)
-    HighlightRange(R, FID, *I);
+    HighlightRange(R, LPosInfo.first, *I);
 }
 
 void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
@@ -475,7 +474,7 @@
     return;
     
   // Compute the column number of the end.
-  unsigned EndColNo = SM.getColumnNumber(InstantiationEnd);
+  unsigned EndColNo = SM.getInstantiationColumnNumber(InstantiationEnd);
   unsigned OldEndColNo = EndColNo;
 
   if (EndColNo) {

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

==============================================================================
--- cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp Tue Feb  3 18:55:58 2009
@@ -56,7 +56,7 @@
   // Compute the column number of the start.
   unsigned StartColNo = 0;
   if (StartLineNo == LineNo) {
-    StartColNo = SM.getColumnNumber(Begin);
+    StartColNo = SM.getInstantiationColumnNumber(Begin);
     if (StartColNo) --StartColNo;  // Zero base the col #.
   }
 
@@ -68,7 +68,7 @@
   // Compute the column number of the end.
   unsigned EndColNo = CaretLine.size();
   if (EndLineNo == LineNo) {
-    EndColNo = SM.getColumnNumber(End);
+    EndColNo = SM.getInstantiationColumnNumber(End);
     if (EndColNo) {
       --EndColNo;  // Zero base the col #.
       





More information about the cfe-commits mailing list