Skip to content
Snippets Groups Projects
Commit 8c099d9b authored by Argyrios Kyrtzidis's avatar Argyrios Kyrtzidis
Browse files

[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
parent cdd7a96a
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment