r193725 - [libclang/python] Add __contains__ to SourceRange class.

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Oct 30 17:03:33 PDT 2013


Author: akirtzidis
Date: Wed Oct 30 19:03:33 2013
New Revision: 193725

URL: http://llvm.org/viewvc/llvm-project?rev=193725&view=rev
Log:
[libclang/python] Add __contains__ to SourceRange class.

Patch by Loïc Jaquemet!

Modified:
    cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=193725&r1=193724&r2=193725&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Wed Oct 30 19:03:33 2013
@@ -266,6 +266,29 @@ class SourceRange(Structure):
     def __ne__(self, other):
         return not self.__eq__(other)
 
+    def __contains__(self, other):
+        """Useful to detect the Token/Lexer bug"""
+        if not isinstance(other, SourceLocation):
+            return False
+        if other.file is None and self.start.file is None:
+            pass
+        elif ( self.start.file.name != other.file.name or 
+               other.file.name != self.end.file.name):
+            # same file name
+            return False
+        # same file, in between lines
+        if self.start.line < other.line < self.end.line:
+            return True
+        elif self.start.line == other.line:
+            # same file first line
+            if self.start.column <= other.column:
+                return True
+        elif other.line == self.end.line:
+            # same file last line
+            if other.column <= self.end.column:
+                return True
+        return False
+
     def __repr__(self):
         return "<SourceRange start %r, end %r>" % (self.start, self.end)
 





More information about the cfe-commits mailing list