[cfe-commits] r150969 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_type.py

Gregory Szorc gregory.szorc at gmail.com
Mon Feb 20 09:44:49 PST 2012


Author: gps
Date: Mon Feb 20 11:44:49 2012
New Revision: 150969

URL: http://llvm.org/viewvc/llvm-project?rev=150969&view=rev
Log:
[clang.py] Implement Type.__eq__ and Type.__ne__

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_type.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=150969&r1=150968&r2=150969&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Mon Feb 20 11:44:49 2012
@@ -1245,6 +1245,15 @@
         """
         return Type_get_array_size(self)
 
+    def __eq__(self, other):
+        if type(other) != type(self):
+            return False
+
+        return Type_equal(self, other)
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 ## CIndex Objects ##
 
 # CIndex objects (derived from ClangObject) are essentially lightweight
@@ -1936,6 +1945,10 @@
 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]

Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=150969&r1=150968&r2=150969&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Mon Feb 20 11:44:49 2012
@@ -109,6 +109,31 @@
     else:
         assert False, "Didn't find teststruct??"
 
+def test_equal():
+    """Ensure equivalence operators work on Type."""
+    source = 'int a; int b; void *v;'
+    tu = get_tu(source)
+
+    a, b, v = None, None, None
+
+    for cursor in tu.cursor.get_children():
+        if cursor.spelling == 'a':
+            a = cursor
+        elif cursor.spelling == 'b':
+            b = cursor
+        elif cursor.spelling == 'v':
+            v = cursor
+
+    assert a is not None
+    assert b is not None
+    assert v is not None
+
+    assert a.type == b.type
+    assert a.type != v.type
+
+    assert a.type != None
+    assert a.type != 'foo'
+
 def test_is_pod():
     tu = get_tu('int i; void f();')
     i, f = None, None





More information about the cfe-commits mailing list