---
 bindings/python/clang/cindex.py           |   18 ++++++++++++++++++
 bindings/python/tests/cindex/test_type.py |   13 +++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 364547b..d4b2712 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1147,16 +1147,29 @@ class Type(Structure):
     @property
     def argument_types(self):
         """A generator of Type instances corresponding to the arguments for
         this function type."""
 
         for i in range(0, self.arguments_count):
             yield self.get_arg_type(i)
 
+    @property
+    def element_type(self):
+        """Retrieve the Type of elements within this type.
+
+        If accessed on a non-array, complex, or vector type, an exception will
+        be raised.
+        """
+        result = Type_get_element_type(self)
+        if result.kind == TypeKind.INVALID:
+            raise Exception('Element type not available on this type.')
+
+        return result
+
     @staticmethod
     def from_result(res, fn, args):
         assert isinstance(res, Type)
         return res
 
     def get_canonical(self):
         """
         Return the canonical type for a Type.
@@ -1928,16 +1941,21 @@ Type_get_num_arg_types = lib.clang_getNumArgTypes
 Type_get_num_arg_types.argtypes = [Type]
 Type_get_num_arg_types.restype = c_uint
 
 Type_get_arg_type = lib.clang_getArgType
 Type_get_arg_type.argtypes = [Type, c_uint]
 Type_get_arg_type.restype = Type
 Type_get_arg_type.errcheck = Type.from_result
 
+Type_get_element_type = lib.clang_getElementType
+Type_get_element_type.argtypes = [Type]
+Type_get_element_type.restype = Type
+Type_get_element_type.errcheck = Type.from_result
+
 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
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py
index c131a4b..9454e32 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -148,8 +148,21 @@ def test_is_pod():
         elif cursor.spelling == 'f':
             f = cursor
 
     assert i is not None
     assert f is not None
 
     assert i.type.is_pod()
     assert not f.type.is_pod()
+
+def test_element_type():
+    index = Index.create()
+    tu = index.parse('t.c', unsaved_files=[('t.c', 'int i[5];')])
+    assert tu is not None
+
+    for cursor in tu.cursor.get_children():
+        if cursor.spelling == 'i':
+            i = cursor
+            break
+
+    assert i.type.kind == TypeKind.CONSTANTARRAY
+    assert i.type.element_type.kind == TypeKind.INT
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to