[cfe-commits] r64758 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp

Chris Lattner sabre at nondot.org
Tue Feb 17 00:04:49 PST 2009


Author: lattner
Date: Tue Feb 17 02:04:48 2009
New Revision: 64758

URL: http://llvm.org/viewvc/llvm-project?rev=64758&view=rev
Log:
add an accessor.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=64758&r1=64757&r2=64758&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb 17 02:04:48 2009
@@ -454,6 +454,12 @@
     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

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=64758&r1=64757&r2=64758&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb 17 02:04:48 2009
@@ -597,6 +597,18 @@
   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>





More information about the cfe-commits mailing list