[libclang/python] Add __contains__ to SourceRange class.

Patch by Loïc Jaquemet!

llvm-svn: 193725
This commit is contained in:
Argyrios Kyrtzidis 2013-10-31 00:03:33 +00:00
parent 686f3deb44
commit 28d5b6bb11
1 changed files with 23 additions and 0 deletions

View File

@ -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)