---
bindings/python/clang/cindex.py | 20 ++++++++++++++++++++
bindings/python/tests/cindex/test_type.py | 7 ++++++-
2 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index efc2f52..4b25b03 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1192,16 +1192,31 @@ class Type(Structure):
return Type_get_pointee(self)
def get_declaration(self):
"""
Return the cursor for the declaration of the given type.
"""
return Type_get_declaration(self)
+ def get_arg_type(self, index):
+ """Return the Type of a specific argument.
+
+ The first argument is the index of the argument whose type to retrieve.
+ Pass 0 for the first argument. Values can be up to .arguments_count - 1.
+ """
+ assert isinstance(index, int)
+ assert self.kind == TypeKind.FUNCTIONPROTO
+
+ result = Type_get_arg_type(self, index)
+ if result.kind == TypeKind.INVALID:
+ raise Exception('Invalid index provided.')
+
+ return result
+
def get_result(self):
"""
Retrieve the result type associated with a function type.
"""
return Type_get_result(self)
def get_array_element_type(self):
"""
@@ -1882,16 +1897,21 @@ 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_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_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 39f88a2..d4687a9 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -110,21 +110,26 @@ 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():
+def test_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
+
+ t0 = f.type.get_arg_type(0)
+ assert t0.kind == TypeKind.INT
+ t1 = f.type.get_arg_type(1)
+ assert t1.kind == TypeKind.INT
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits