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

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

index fcdd8345394a92a6cbdd510cb6d6793d20605d17..269d7cd5a04b6a33f7da6c300c83e2a1e07be2eb 100644 (file)
@@ -533,6 +533,11 @@ public:
   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 @@ public:
   /// 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 {
index 3f652274b80368d341e30c788303b11b1e89ca35..2b581bb1ed32f8aa8334be1b506136a241f5e42b 100644 (file)
@@ -857,6 +857,15 @@ SourceManager::getFileCharacteristic(SourceLocation Loc) const {
   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