revert my patches, which are causing problems.
authorChris Lattner <sabre@nondot.org>
Sat, 5 May 2012 22:11:04 +0000 (22:11 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 5 May 2012 22:11:04 +0000 (22:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156245 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/SourceMgr.h
lib/Support/SourceMgr.cpp

index f108f732b854e62373ae777484e040e0807c7565..76967dbf78aa8d61ecd17cb5427e0248688f44c3 100644 (file)
@@ -123,14 +123,7 @@ public:
 
   /// FindLineNumber - Find the line number for the specified location in the
   /// specified file.  This is not a fast method.
-  unsigned FindLineNumber(SMLoc Loc, int BufferID = -1) const {
-    return getLineAndColumn(Loc, BufferID).first;
-  }
-
-  /// getLineAndColumn - Find the line and column number for the specified
-  /// location in the specified file.  This is not a fast method.
-  std::pair<unsigned, unsigned>
-    getLineAndColumn(SMLoc Loc, int BufferID = -1) const;
+  unsigned FindLineNumber(SMLoc Loc, int BufferID = -1) const;
 
   /// PrintMessage - Emit a message about the specified location with the
   /// specified string.
index 15ae8a4a63ac86bbca424b27d31688820d40f1ab..15278c598e52caf5db45a394445d501525a2cae1 100644 (file)
@@ -79,10 +79,9 @@ int SourceMgr::FindBufferContainingLoc(SMLoc Loc) const {
   return -1;
 }
 
-/// getLineAndColumn - Find the line and column number for the specified
-/// location in the specified file.  This is not a fast method.
-std::pair<unsigned, unsigned>
-SourceMgr::getLineAndColumn(SMLoc Loc, int BufferID) const {
+/// FindLineNumber - Find the line number for the specified location in the
+/// specified file.  This is not a fast method.
+unsigned SourceMgr::FindLineNumber(SMLoc Loc, int BufferID) const {
   if (BufferID == -1) BufferID = FindBufferContainingLoc(Loc);
   assert(BufferID != -1 && "Invalid Location!");
 
@@ -92,8 +91,7 @@ SourceMgr::getLineAndColumn(SMLoc Loc, int BufferID) const {
   // location.
   unsigned LineNo = 1;
 
-  const char *BufStart = Buff->getBufferStart();
-  const char *Ptr = BufStart;
+  const char *Ptr = Buff->getBufferStart();
 
   // If we have a line number cache, and if the query is to a later point in the
   // same file, start searching from the last query location.  This optimizes
@@ -110,6 +108,7 @@ SourceMgr::getLineAndColumn(SMLoc Loc, int BufferID) const {
   for (; SMLoc::getFromPointer(Ptr) != Loc; ++Ptr)
     if (*Ptr == '\n') ++LineNo;
 
+
   // Allocate the line number cache if it doesn't exist.
   if (LineNoCache == 0)
     LineNoCache = new LineNoCacheTy();
@@ -119,10 +118,7 @@ SourceMgr::getLineAndColumn(SMLoc Loc, int BufferID) const {
   Cache.LastQueryBufferID = BufferID;
   Cache.LastQuery = Ptr;
   Cache.LineNoOfQuery = LineNo;
-  
-  size_t NewlineOffs = StringRef(BufStart, Ptr-BufStart).find_last_of("\n\r");
-  if (NewlineOffs == StringRef::npos) NewlineOffs = ~0ULL;
-  return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
+  return LineNo;
 }
 
 void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
@@ -157,15 +153,14 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
 
   // Scan backward to find the start of the line.
   const char *LineStart = Loc.getPointer();
-  const char *BufStart = CurMB->getBufferStart();
-  while (LineStart != BufStart && LineStart[-1] != '\n' &&
-         LineStart[-1] != '\r')
+  while (LineStart != CurMB->getBufferStart() &&
+         LineStart[-1] != '\n' && LineStart[-1] != '\r')
     --LineStart;
 
   // Get the end of the line.
   const char *LineEnd = Loc.getPointer();
-  const char *BufEnd = CurMB->getBufferEnd();
-  while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
+  while (LineEnd != CurMB->getBufferEnd() &&
+         LineEnd[0] != '\n' && LineEnd[0] != '\r')
     ++LineEnd;
   std::string LineStr(LineStart, LineEnd);
 
@@ -191,10 +186,9 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
                                        R.End.getPointer()-LineStart));
   }
   
-  std::pair<unsigned, unsigned> LineAndCol = getLineAndColumn(Loc, CurBuf);
   return SMDiagnostic(*this, Loc,
-                      CurMB->getBufferIdentifier(), LineAndCol.first,
-                      LineAndCol.second, Kind, Msg.str(),
+                      CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
+                      Loc.getPointer()-LineStart, Kind, Msg.str(),
                       LineStr, ColRanges);
 }