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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63698 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 54aed7c..9d91deb 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -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());
 }