]> granicus.if.org Git - clang/commitdiff
lower the interface to getLineNumber like we did for
authorChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 01:06:56 +0000 (01:06 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 01:06:56 +0000 (01:06 +0000)
getColumnNumber.  This fixes a FIXME in
SourceManager::getPresumedLoc because we now just decompose
the sloc once.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63701 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2c764ade008ddf1482ba195a2c7e0be34f541cbd..370adc72c44acd8db9f91328ab558136af12a8a8 100644 (file)
@@ -162,7 +162,7 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
   }
   
   Loc = SourceMgr.getInstantiationLoc(Loc);
-  CurLine = SourceMgr.getLineNumber(Loc);
+  CurLine = SourceMgr.getInstantiationLineNumber(Loc);
 
   if (DisableLineMarkers) return;
 
index facb1954305e4e807856223945abeab0e38649f5..f860433c29eb46dd85edf00f2a17de02fad0bd25 100644 (file)
@@ -766,7 +766,8 @@ void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
   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 {
index 5c7ef1ba4b81aba8d66b24ddc19aab3660762693..b75214004949c7def0bcb4e5aa04b1a6e53a7fd4 100644 (file)
@@ -200,8 +200,6 @@ public:
   FullSourceLoc getInstantiationLoc() const;
   FullSourceLoc getSpellingLoc() const;
 
-  unsigned getLineNumber() const;
-  
   unsigned getInstantiationLineNumber() const;
   unsigned getInstantiationColumnNumber() const;
 
index 340c2e562a3ba868dd9c65cc9713eedc6b7dcbec..e0ed77f2ddd3a68ee3e1dab2a9fe61030bea3344 100644 (file)
@@ -490,14 +490,10 @@ public:
   /// 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 {
index 93f60fc8742c736d5401e49ff7d702400f39d012..8e068d6ac282a1ffef54fbff5926577afe63733e 100644 (file)
@@ -78,11 +78,6 @@ FullSourceLoc FullSourceLoc::getSpellingLoc() const {
   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);
index 9d91debc43f926c06fabb0875cb8f87ed55a3757..0e1841631469b5b818df764389fc160b439c2ee5 100644 (file)
@@ -474,11 +474,13 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos) const {
 }
 
 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 @@ static void ComputeLineNumbers(ContentCache* FI, llvm::BumpPtrAllocator &Alloc){
 /// 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 SourceManager::getLineNumber(SourceLocation Loc) const {
   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 @@ unsigned SourceManager::getLineNumber(SourceLocation Loc) const {
     = 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 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
   
   // 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 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
   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());
 }
index 79abc340644aa803cb812f5cd09e500e0f7bda18..bf1387a99a1c4c2bc72bf8dc7d5a0c8304d12d48 100644 (file)
@@ -455,7 +455,8 @@ void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) {
   // 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;
 
index 1e1190527f4d1b3be37bc3efea092c17cd03f417..1561fc455d7c70f7036e6d2f8f86fc70e7d37048 100644 (file)
@@ -461,10 +461,10 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
   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;
index cf3733f2e9e45da21e12b6c6d47b0466c18f4dad..39367f0de4be2c911c3d47c031afd8e707d0e733 100644 (file)
@@ -45,11 +45,11 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
   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 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
 
     // 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.