diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-10-31 00:03:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-10-31 00:03:33 +0000 |
commit | 8c099d9b04f0b3025e713f76b42a50f3a67d404f (patch) | |
tree | 94b63c2174b5e4fbf85e2335138c3954f90d4c42 /bindings | |
parent | cdd7a96a8ee9664873492daf05e1db5e42dcf976 (diff) |
[libclang/python] Add __contains__ to SourceRange class.
Patch by Loïc Jaquemet!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193725 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/clang/cindex.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index cbce1a2d3f..c103c70780 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -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) |