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

Chris Lattner sabre at nondot.org
Tue Feb 17 00:39:06 PST 2009


Author: lattner
Date: Tue Feb 17 02:39:06 2009
New Revision: 64760

URL: http://llvm.org/viewvc/llvm-project?rev=64760&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=64760&r1=64759&r2=64760&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb 17 02:39:06 2009
@@ -533,6 +533,11 @@
   unsigned getInstantiationLineNumber(SourceLocation Loc) const;
   unsigned getSpellingLineNumber(SourceLocation Loc) const;
   
+  /// Return the filename or buffer identifier of the buffer the location is in.
+  /// Note that this name does not respect #line directives.  Use getPresumedLoc
+  /// for normal clients.
+  const char *getBufferName(SourceLocation Loc) const;
+  
   /// getFileCharacteristic - return the file characteristic of the specified
   /// source location, indicating whether this is a normal file, a system 
   /// header, or an "implicit extern C" system header.
@@ -552,8 +557,6 @@
   /// of an instantiation location, not at the spelling location.
   PresumedLoc getPresumedLoc(SourceLocation Loc) const;
   
-  
-  
   /// isFromSameFile - Returns true if both SourceLocations correspond to
   ///  the same file.
   bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const {

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

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb 17 02:39:06 2009
@@ -857,6 +857,15 @@
   return Entry->FileKind;
 }
 
+/// Return the filename or buffer identifier of the buffer the location is in.
+/// Note that this name does not respect #line directives.  Use getPresumedLoc
+/// for normal clients.
+const char *SourceManager::getBufferName(SourceLocation Loc) const {
+  if (Loc.isInvalid()) return "<invalid loc>";
+  
+  return getBuffer(getFileID(Loc))->getBufferIdentifier();
+}
+
 
 /// getPresumedLoc - This method returns the "presumed" location of a
 /// SourceLocation specifies.  A "presumed location" can be modified by #line





More information about the cfe-commits mailing list