extract argument & return types from C function pointer with libclang

Viewed 865

I'm using libclang (API version 0.43) to parse a C header file. Is there a way to extract the argument & return type(s) from a function pointer definition, e.g.

int (*my_add_fn)(int, int);

I can get a cursor to my_add_fn, and can see some info (output from print statements on the right:

print(cursor.spelling)                    # my_add_fn
print(cursor.type.kind)                   # TypeKind.POINTER
print(cursor.type.get_pointee().kind)     # TypeKind.UNEXPOSED
print(cursor.type.get_pointee().spelling) # int (int, int)

But I can't get an iterator for the args (like I can for a regular function prototype), and I'd rather not resort to string-mangling the spelling property.

Any ideas?

1 Answers
cursor.type.get_pointee().get_result()
cursor.type.get_pointee().get_canonical().argument_types()
Related