]> granicus.if.org Git - clang/commitdiff
add an accessor.
authorChris Lattner <sabre@nondot.org>
Tue, 17 Feb 2009 08:04:48 +0000 (08:04 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Feb 2009 08:04:48 +0000 (08:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64758 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/Basic/SourceManager.cpp

index b29a1acd4a5e05be9f9c091b702697d2f8f419d6..fcdd8345394a92a6cbdd510cb6d6793d20605d17 100644 (file)
@@ -454,6 +454,12 @@ public:
     if (Loc.isFileID()) return Loc;
     return getSpellingLocSlowCase(Loc);
   }
+  
+  /// getImmediateSpellingLoc - Given a SourceLocation object, return the
+  /// spelling location referenced by the ID.  This is the first level down
+  /// towards the place where the characters that make up the lexed token can be
+  /// found.  This should not generally be used by clients.
+  SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const;  
 
   /// getDecomposedLoc - Decompose the specified location into a raw FileID +
   /// Offset pair.  The first element is the FileID, the second is the
index 88980efcdaa07463bcc7b19455195ee39cd2743c..3f652274b80368d341e30c788303b11b1e89ca35 100644 (file)
@@ -597,6 +597,18 @@ SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
   return std::make_pair(FID, Offset);
 }
 
+/// getImmediateSpellingLoc - Given a SourceLocation object, return the
+/// spelling location referenced by the ID.  This is the first level down
+/// towards the place where the characters that make up the lexed token can be
+/// found.  This should not generally be used by clients.
+SourceLocation SourceManager::getImmediateSpellingLoc(SourceLocation Loc) const{
+  if (Loc.isFileID()) return Loc;
+  std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
+  Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc();
+  return Loc.getFileLocWithOffset(LocInfo.second);
+}
+
+
 /// getImmediateInstantiationRange - Loc is required to be an instantiation
 /// location.  Return the start/end of the instantiation information.
 std::pair<SourceLocation,SourceLocation>