The implementation could probably be a bit more robust (looking for
None, comparing types, etc). Do we care?
---
bindings/python/clang/cindex.py | 10 ++++++++++
bindings/python/tests/cindex/test_type.py | 17 +++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index d01d1db..8c69790 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1240,16 +1240,22 @@ class Type(Structure):
return Type_get_array_element(self)
def get_array_size(self):
"""
Retrieve the size of the constant array.
"""
return Type_get_array_size(self)
+ def __eq__(self, other):
+ return Type_equal(self, other)
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
## CIndex Objects ##
# CIndex objects (derived from ClangObject) are essentially lightweight
# wrappers attached to some underlying object, which is exposed via CIndex as
# a void*.
class ClangObject(object):
"""
@@ -1931,16 +1937,20 @@ Type_get_array_element = lib.clang_getArrayElementType
Type_get_array_element.argtypes = [Type]
Type_get_array_element.restype = Type
Type_get_array_element.errcheck = Type.from_result
Type_get_array_size = lib.clang_getArraySize
Type_get_array_size.argtype = [Type]
Type_get_array_size.restype = c_longlong
+Type_equal = lib.clang_equalTypes
+Type_equal.argtypes = [Type, Type]
+Type_equal.restype = bool
+
# Index Functions
Index_create = lib.clang_createIndex
Index_create.argtypes = [c_int, c_int]
Index_create.restype = c_object_p
Index_dispose = lib.clang_disposeIndex
Index_dispose.argtypes = [Index]
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py
index da91a8e..449cf9c 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -105,16 +105,33 @@ def testConstantArray():
assert fields[0].type.get_array_element_type() is not None
assert fields[0].type.get_array_element_type().kind == TypeKind.POINTER
assert fields[0].type.get_array_size() == 2
break
else:
assert False, "Didn't find teststruct??"
+def test_equal():
+ source = 'int a; int b;'
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files = [('t.c', source)])
+ assert tu is not None
+
+ for cursor in tu.cursor.get_children():
+ if cursor.spelling == 'a':
+ a = cursor
+ elif cursor.spelling == 'b':
+ b = cursor
+
+ assert a is not None
+ assert b is not None
+
+ assert a.type == b.type
+
def test_is_pod():
index = Index.create()
tu = index.parse('t.c', unsaved_files=[('t.c', 'int i; void f();')])
assert tu is not None
i, f = None, None
for cursor in tu.cursor.get_children():
if cursor.spelling == 'i':
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits