From 7da5aea7669e6db3e593162b8a123aef06a04d07 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 4 Feb 2009 00:55:58 +0000 Subject: 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 --- lib/Basic/SourceManager.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib/Basic/SourceManager.cpp') diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 54aed7c9f1..9d91debc43 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -112,9 +112,6 @@ public: }; } // 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 @@ const char *SourceManager::getCharacterData(SourceLocation SL) const { /// 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 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 LocInfo = getDecomposedSpellingLoc(Loc); + return getColumnNumber(LocInfo.first, LocInfo.second); +} + +unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc) const { + std::pair 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 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const { if (Loc.isInvalid()) return PresumedLoc(); // Presumed locations are always for instantiation points. + std::pair LocInfo = getDecomposedInstantiationLoc(Loc); Loc = getInstantiationLoc(Loc); - + // FIXME: Could just decompose Loc once! const SrcMgr::FileInfo &FI = getSLocEntry(getFileID(Loc)).getFile(); @@ -646,7 +649,8 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const { 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()); } -- cgit v1.2.3-18-g5258