diff options
-rw-r--r-- | include/clang/Basic/SourceManager.h | 19 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 21 |
2 files changed, 30 insertions, 10 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 41c2defacd..84aabe1f31 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -415,24 +415,20 @@ public: /// Given a SourceLocation object, return the instantiation location /// referenced by the ID. SourceLocation getInstantiationLoc(SourceLocation Loc) const { - // File locations work! + // Handle the non-mapped case inline, defer to out of line code to handle + // instantiations. if (Loc.isFileID()) return Loc; - - std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); - Loc = getSLocEntry(LocInfo.first).getInstantiation().getInstantiationLoc(); - return Loc.getFileLocWithOffset(LocInfo.second); + return getInstantiationLocSlowCase(Loc); } /// getSpellingLoc - Given a SourceLocation object, return the spelling /// location referenced by the ID. This is the place where the characters /// that make up the lexed token can be found. SourceLocation getSpellingLoc(SourceLocation Loc) const { - // File locations work! + // Handle the non-mapped case inline, defer to out of line code to handle + // instantiations. if (Loc.isFileID()) return Loc; - - std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); - Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc(); - return Loc.getFileLocWithOffset(LocInfo.second); + return getSpellingLocSlowCase(Loc); } /// getDecomposedLoc - Decompose the specified location into a raw FileID + @@ -614,6 +610,9 @@ private: FileID getFileIDSlow(unsigned SLocOffset) const; + SourceLocation getInstantiationLocSlowCase(SourceLocation Loc) const; + SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; + std::pair<FileID, unsigned> getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E, unsigned Offset) const; diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 031bf4dcbc..f9f51afef8 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -328,6 +328,27 @@ FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { } } +SourceLocation SourceManager:: +getInstantiationLocSlowCase(SourceLocation Loc) const { + do { + std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); + Loc =getSLocEntry(LocInfo.first).getInstantiation().getInstantiationLoc(); + Loc = Loc.getFileLocWithOffset(LocInfo.second); + } while (!Loc.isFileID()); + + return Loc; +} + +SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const { + do { + std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); + Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc(); + Loc = Loc.getFileLocWithOffset(LocInfo.second); + } while (!Loc.isFileID()); + return Loc; +} + + std::pair<FileID, unsigned> SourceManager::getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E, unsigned Offset) const { |