summaryrefslogtreecommitdiffstats
path: root/bindings/python/clang
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:40:59 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:40:59 +0000
commit74858335a1a5205b3e1c89ecf9221cea839c0b0b (patch)
treec1c829ea395c5d9fb0d758b79ea0ce5236c7d2a5 /bindings/python/clang
parentb919815a0caf836e28c49d7253d8949d7ceb24ad (diff)
[clang.py] Implement __eq__ and __ne__ on SourceLocation and SourceRange
There is no type checking in __eq__, so ctypes will throw if the wrong Python type is passed in to the C function. Personally, I feel garbage in means garbage out and it isn't worth testing for this explicitly. Contributed by: Gregory Szorc <gregory.szorc@gmail.com> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149824 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/clang')
-rw-r--r--bindings/python/clang/cindex.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 48a107cd33..474740a64d 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -146,6 +146,12 @@ class SourceLocation(Structure):
"""Get the file offset represented by this source location."""
return self._get_instantiation()[3]
+ def __eq__(self, other):
+ return SourceLocation_equalLocations(self, other)
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __repr__(self):
if self.file:
filename = self.file.name
@@ -186,6 +192,12 @@ class SourceRange(Structure):
"""
return SourceRange_end(self)
+ def __eq__(self, other):
+ return SourceRange_equalRanges(self, other)
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
def __repr__(self):
return "<SourceRange start %r, end %r>" % (self.start, self.end)
@@ -1613,6 +1625,10 @@ SourceLocation_getLocation = lib.clang_getLocation
SourceLocation_getLocation.argtypes = [TranslationUnit, File, c_uint, c_uint]
SourceLocation_getLocation.restype = SourceLocation
+SourceLocation_equalLocations = lib.clang_equalLocations
+SourceLocation_equalLocations.argtypes = [SourceLocation, SourceLocation]
+SourceLocation_equalLocations.restype = bool
+
# Source Range Functions
SourceRange_getRange = lib.clang_getRange
SourceRange_getRange.argtypes = [SourceLocation, SourceLocation]
@@ -1626,6 +1642,10 @@ SourceRange_end = lib.clang_getRangeEnd
SourceRange_end.argtypes = [SourceRange]
SourceRange_end.restype = SourceLocation
+SourceRange_equalRanges = lib.clang_equalRanges
+SourceRange_equalRanges.argtypes = [SourceRange, SourceRange]
+SourceRange_equalRanges.restype = bool
+
# CursorKind Functions
CursorKind_is_decl = lib.clang_isDeclaration
CursorKind_is_decl.argtypes = [CursorKind]