[cfe-commits] r63701 - in /cfe/trunk: Driver/PrintPreprocessedOutput.cpp Driver/RewriteObjC.cpp include/clang/Basic/SourceLocation.h include/clang/Basic/SourceManager.h lib/Basic/SourceLocation.cpp lib/Basic/SourceManager.cpp lib/CodeGen/CGDebugInfo.cpp lib/Driver/HTMLDiagnostics.cpp lib/Driver/TextDiagnosticPrinter.cpp

Chris Lattner sabre at nondot.org
Tue Feb 3 17:06:56 PST 2009


Author: lattner
Date: Tue Feb  3 19:06:56 2009
New Revision: 63701

URL: http://llvm.org/viewvc/llvm-project?rev=63701&view=rev
Log:
lower the interface to getLineNumber like we did for
getColumnNumber.  This fixes a FIXME in 
SourceManager::getPresumedLoc because we now just decompose
the sloc once.

Modified:
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceLocation.cpp
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/Driver/HTMLDiagnostics.cpp
    cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=63701&r1=63700&r2=63701&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Tue Feb  3 19:06:56 2009
@@ -162,7 +162,7 @@
   }
   
   Loc = SourceMgr.getInstantiationLoc(Loc);
-  CurLine = SourceMgr.getLineNumber(Loc);
+  CurLine = SourceMgr.getInstantiationLineNumber(Loc);
 
   if (DisableLineMarkers) return;
 

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=63701&r1=63700&r2=63701&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Feb  3 19:06:56 2009
@@ -766,7 +766,8 @@
   SourceLocation LocStart = Method->getLocStart();
   SourceLocation LocEnd = Method->getLocEnd();
     
-  if (SM->getLineNumber(LocEnd) > SM->getLineNumber(LocStart)) {
+  if (SM->getInstantiationLineNumber(LocEnd) >
+      SM->getInstantiationLineNumber(LocStart)) {
     InsertText(LocStart, "#if 0\n", 6);
     ReplaceText(LocEnd, 1, ";\n#endif\n", 9);
   } else {

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue Feb  3 19:06:56 2009
@@ -200,8 +200,6 @@
   FullSourceLoc getInstantiationLoc() const;
   FullSourceLoc getSpellingLoc() const;
 
-  unsigned getLineNumber() 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=63701&r1=63700&r2=63701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb  3 19:06:56 2009
@@ -490,14 +490,10 @@
   /// for the position indicated.  This requires building and caching a table of
   /// line offsets for the MemoryBuffer, so this is not cheap: use only when
   /// about to emit a diagnostic.
-  unsigned getLineNumber(SourceLocation Loc) const;
+  unsigned getLineNumber(FileID FID, unsigned FilePos) const;
   
-  unsigned getInstantiationLineNumber(SourceLocation Loc) const {
-    return getLineNumber(getInstantiationLoc(Loc));
-  }
-  unsigned getSpellingLineNumber(SourceLocation Loc) const {
-    return getLineNumber(getSpellingLoc(Loc));
-  }
+  unsigned getInstantiationLineNumber(SourceLocation Loc) const;
+  unsigned getSpellingLineNumber(SourceLocation Loc) const;
   
   // FIXME: This should handle #line.
   SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const {

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

==============================================================================
--- cfe/trunk/lib/Basic/SourceLocation.cpp (original)
+++ cfe/trunk/lib/Basic/SourceLocation.cpp Tue Feb  3 19:06:56 2009
@@ -78,11 +78,6 @@
   return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr);
 }
 
-unsigned FullSourceLoc::getLineNumber() const {
-  assert(isValid());
-  return SrcMgr->getLineNumber(*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=63701&r1=63700&r2=63701&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb  3 19:06:56 2009
@@ -474,11 +474,13 @@
 }
 
 unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc) const {
+  if (Loc.isInvalid()) return 0;
   std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
   return getColumnNumber(LocInfo.first, LocInfo.second);
 }
 
 unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc) const {
+  if (Loc.isInvalid()) return 0;
   std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
   return getColumnNumber(LocInfo.first, LocInfo.second);
 }
@@ -535,17 +537,12 @@
 /// for the position indicated.  This requires building and caching a table of
 /// line offsets for the MemoryBuffer, so this is not cheap: use only when
 /// about to emit a diagnostic.
-unsigned SourceManager::getLineNumber(SourceLocation Loc) const {
-  if (Loc.isInvalid()) return 0;
-  assert(Loc.isFileID() && "Don't know what part of instantiation loc to get");
-
-  std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
-  
+unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos) const {
   ContentCache *Content;
-  if (LastLineNoFileIDQuery == LocInfo.first)
+  if (LastLineNoFileIDQuery == FID)
     Content = LastLineNoContentCache;
   else
-    Content = const_cast<ContentCache*>(getSLocEntry(LocInfo.first)
+    Content = const_cast<ContentCache*>(getSLocEntry(FID)
                                         .getFile().getContentCache());
   
   // If this is the first use of line information for this buffer, compute the
@@ -559,12 +556,12 @@
   unsigned *SourceLineCacheStart = SourceLineCache;
   unsigned *SourceLineCacheEnd = SourceLineCache + Content->NumLines;
   
-  unsigned QueriedFilePos = LocInfo.second+1;
+  unsigned QueriedFilePos = FilePos+1;
 
   // If the previous query was to the same file, we know both the file pos from
   // that query and the line number returned.  This allows us to narrow the
   // search space from the entire file to something near the match.
-  if (LastLineNoFileIDQuery == LocInfo.first) {
+  if (LastLineNoFileIDQuery == FID) {
     if (QueriedFilePos >= LastLineNoFilePos) {
       SourceLineCache = SourceLineCache+LastLineNoResult-1;
       
@@ -618,13 +615,25 @@
     = std::lower_bound(SourceLineCache, SourceLineCacheEnd, QueriedFilePos);
   unsigned LineNo = Pos-SourceLineCacheStart;
   
-  LastLineNoFileIDQuery = LocInfo.first;
+  LastLineNoFileIDQuery = FID;
   LastLineNoContentCache = Content;
   LastLineNoFilePos = QueriedFilePos;
   LastLineNoResult = LineNo;
   return LineNo;
 }
 
+unsigned SourceManager::getInstantiationLineNumber(SourceLocation Loc) const {
+  if (Loc.isInvalid()) return 0;
+  std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
+  return getLineNumber(LocInfo.first, LocInfo.second);
+}
+unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc) const {
+  if (Loc.isInvalid()) return 0;
+  std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
+  return getLineNumber(LocInfo.first, LocInfo.second);
+}
+
+
 /// getPresumedLoc - This method returns the "presumed" location of a
 /// SourceLocation specifies.  A "presumed location" can be modified by #line
 /// or GNU line marker directives.  This provides a view on the data that a
@@ -637,11 +646,8 @@
   
   // 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();
+  const SrcMgr::FileInfo &FI = getSLocEntry(LocInfo.first).getFile();
   const SrcMgr::ContentCache *C = FI.getContentCache();
 
   // To get the source name, first consult the FileEntry (if one exists) before
@@ -649,7 +655,8 @@
   const char *Filename = 
     C->Entry ? C->Entry->getName() : C->getBuffer()->getBufferIdentifier();
   
-  return PresumedLoc(Filename, getLineNumber(Loc),
+  return PresumedLoc(Filename,
+                     getLineNumber(LocInfo.first, LocInfo.second),
                      getColumnNumber(LocInfo.first, LocInfo.second),
                      FI.getIncludeLoc());
 }

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=63701&r1=63700&r2=63701&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Feb  3 19:06:56 2009
@@ -455,7 +455,8 @@
   // Don't bother if things are the same as last time.
   SourceManager &SM = M->getContext().getSourceManager();
   if (CurLoc == PrevLoc 
-       || (SM.getLineNumber(CurLoc) == SM.getLineNumber(PrevLoc)
+       || (SM.getInstantiationLineNumber(CurLoc) ==
+           SM.getInstantiationLineNumber(PrevLoc)
            && SM.isFromSameFile(CurLoc, PrevLoc)))
     return;
 

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

==============================================================================
--- cfe/trunk/lib/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Driver/HTMLDiagnostics.cpp Tue Feb  3 19:06:56 2009
@@ -461,10 +461,10 @@
   SourceManager& SM = R.getSourceMgr();
   
   SourceLocation InstantiationStart = SM.getInstantiationLoc(Range.getBegin());
-  unsigned StartLineNo = SM.getLineNumber(InstantiationStart);
+  unsigned StartLineNo = SM.getInstantiationLineNumber(InstantiationStart);
   
   SourceLocation InstantiationEnd = SM.getInstantiationLoc(Range.getEnd());
-  unsigned EndLineNo = SM.getLineNumber(InstantiationEnd);
+  unsigned EndLineNo = SM.getInstantiationLineNumber(InstantiationEnd);
   
   if (EndLineNo < StartLineNo)
     return;

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

==============================================================================
--- cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp Tue Feb  3 19:06:56 2009
@@ -45,11 +45,11 @@
   SourceLocation Begin = SM.getInstantiationLoc(R.getBegin());
   SourceLocation End = SM.getInstantiationLoc(R.getEnd());
   
-  unsigned StartLineNo = SM.getLineNumber(Begin);
+  unsigned StartLineNo = SM.getInstantiationLineNumber(Begin);
   if (StartLineNo > LineNo || SM.getFileID(Begin) != FID)
     return;  // No intersection.
   
-  unsigned EndLineNo = SM.getLineNumber(End);
+  unsigned EndLineNo = SM.getInstantiationLineNumber(End);
   if (EndLineNo < LineNo || SM.getFileID(End) != FID)
     return;  // No intersection.
   
@@ -167,7 +167,8 @@
 
     // Highlight all of the characters covered by Ranges with ~ characters.
     for (unsigned i = 0; i != Info.getNumRanges(); ++i)
-      HighlightRange(Info.getRange(i), ILoc.getManager(), ILoc.getLineNumber(),
+      HighlightRange(Info.getRange(i), ILoc.getManager(),
+                     ILoc.getInstantiationLineNumber(),
                      ILoc.getFileID(), CaretLine, SourceLine);
     
     // Next, insert the caret itself.





More information about the cfe-commits mailing list