[cfe-dev] Function pointer in a struct declaration

Henry Jen henryjen at ztune.net
Thu Mar 26 23:20:28 PDT 2015


Hi,

In OpenJDK project panama, we are working on a tool to take in a header
file and spit out Java APIs utilizing libclang. A proof-of-concept can be
found at [1].

I would like to get the function type if a field of struct is a function
pointer, but I am not sure how to do that. I was expecting to get a pointee
type of FunctionProto on that field, but looks like I only get an Unexposed.

Attached are a cursor visitor code I did to dump cursors and their type,
and the result of the dump for following snippet.

typedef struct foo {
    int(*fn)(char* arg1, long arg2);
    struct bar *ptr;
} foo;

I got a FieldDecl for fn, which has a type of Pointer whose pointeeType is
Unexposed. In case of struct, pointee type is also Unexposed, but there is
a TypeRef and StructDecl for bar, so at least I can figureout there is a
Record type, but how figure out the function type for fn?

Are there test cases or document that I can reference to figure out what
kind of cursor or type I can get with various style of code? I am guessing
there are test cases to verify the correct output of visitor, but a quick
glance to the source code didn't reveal them. I hope you experts would give
me some pointers.

Thanks for the good work.

Cheers,
Henry


[1]
http://hg.openjdk.java.net/panama/panama/jdk/file/tip/src/jdk.dev/share/classes/com/sun/tools/jextract
.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150326/78ccf2d0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cursor.c
Type: text/x-csrc
Size: 3634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150326/78ccf2d0/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_struct.output
Type: application/octet-stream
Size: 3518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150326/78ccf2d0/attachment.obj>


More information about the cfe-dev mailing list