[cfe-commits] r44942 - /cfe/trunk/include/clang/Basic/SourceLocation.h

Ted Kremenek kremenek at apple.com
Wed Dec 12 10:16:46 PST 2007


Author: kremenek
Date: Wed Dec 12 12:16:46 2007
New Revision: 44942

URL: http://llvm.org/viewvc/llvm-project?rev=44942&view=rev
Log:
Added class FullContextSourceLocation: a tuple class that
contains both a SourceLocation and its associated
SourceManager. This class is useful for argument passing to
functions that expect both objects.

Modified:
    cfe/trunk/include/clang/Basic/SourceLocation.h

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Wed Dec 12 12:16:46 2007
@@ -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 @@
   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





More information about the cfe-commits mailing list