]> granicus.if.org Git - clang/commitdiff
Added class FullContextSourceLocation: a tuple class that
authorTed Kremenek <kremenek@apple.com>
Wed, 12 Dec 2007 18:16:46 +0000 (18:16 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 12 Dec 2007 18:16:46 +0000 (18:16 +0000)
contains both a SourceLocation and its associated
SourceManager. This class is useful for argument passing to
functions that expect both objects.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44942 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceLocation.h

index c25528b7e993ddf1a65bc28e58eb53def4c7b710..145d590046502480a5203c6ed545d63b8046ddbe 100644 (file)
@@ -18,6 +18,8 @@
 #include "llvm/Bitcode/SerializationFwd.h"
 
 namespace clang {
+  
+class SourceManager;
     
 /// SourceLocation - This is a carefully crafted 32-bit identifier that encodes
 /// a full include stack, line and column number information for a position in
@@ -199,6 +201,35 @@ public:
   static SourceRange ReadVal(llvm::Deserializer& D);
 };
   
+/// FullContextSourceLocation - A tuple containing both a SourceLocation
+///  and its associated SourceManager.  Useful for argument passing to functions
+///  that expect both objects.
+class FullContextSourceLocation {
+  SourceLocation Loc;
+  SourceManager* SrcMgr;
+public:
+  explicit FullContextSourceLocation(SourceLocation loc)
+    : Loc(loc), SrcMgr(NULL) {}
+
+  explicit FullContextSourceLocation(SourceLocation loc, SourceManager& smgr) 
+    : Loc(loc), SrcMgr(&smgr) {}
+  
+  bool isValid() { return Loc.isValid(); }
+  
+  SourceLocation getSourceLocation() const { return Loc; }
+  operator SourceLocation() const { return Loc; }
+  
+  SourceManager& getSourceManager() {
+    assert (SrcMgr && "SourceManager is NULL.");
+    return *SrcMgr;
+  }
+  
+  const SourceManager& getSourceManager() const {
+    assert (SrcMgr && "SourceManager is NULL.");
+    return *SrcMgr;
+  }
+};
+
 }  // end namespace clang
 
 #endif