---
bindings/python/clang/cindex.py | 10 ++++++++++
bindings/python/tests/cindex/test_type.py | 13 +++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index c5897f0..efc2f52 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1133,16 +1133,22 @@ class Type(Structure):
"""
_fields_ = [("_kind_id", c_int), ("data", c_void_p * 2)]
@property
def kind(self):
"""Return the kind of this type."""
return TypeKind.from_id(self._kind_id)
+ @property
+ def arguments_count(self):
+ """Retrieve the number of non-variadic arguments for this function type."""
+ assert self.kind == TypeKind.FUNCTIONPROTO
+ return Type_get_num_arg_types(self)
+
@staticmethod
def from_result(res, fn, args):
assert isinstance(res, Type)
return res
def get_canonical(self):
"""
Return the canonical type for a Type.
@@ -1872,16 +1878,20 @@ Type_get_declaration.argtypes = [Type]
Type_get_declaration.restype = Cursor
Type_get_declaration.errcheck = Cursor.from_result
Type_get_result = lib.clang_getResultType
Type_get_result.argtypes = [Type]
Type_get_result.restype = Type
Type_get_result.errcheck = Type.from_result
+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_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 fde8ac8..39f88a2 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -110,8 +110,21 @@ def test_equal():
elif cursor.spelling == 'b':
b = cursor
assert a is not None
assert b is not None
assert a.type == b.type
+def test_num_function_arguments():
+ source = 'void f(int, int);'
+ 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 == 'f':
+ f = cursor
+ break
+
+ assert f is not None
+ assert f.type.arguments_count == 2
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits