<div dir="ltr"><div>This may help you, it's similar to your project description in that it generates C# extern definitions (C# equivalent of JNI, I suppose):</div><div><br></div><div><a href="https://github.com/mjsabby/ClangSharp/blob/master/ClangSharpPInvokeGenerator/TypeDefVisitor.cs#L27,#L75">https://github.com/mjsabby/ClangSharp/blob/master/ClangSharpPInvokeGenerator/TypeDefVisitor.cs#L27,#L75</a></div><div><br></div><div>The highlighted part is the relevant Function Pointer case where it checks that is a pointer type and then its canonical pointee type which should be a CXType_FunctionProto.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 27, 2015 at 2:28 PM, Henry Jen <span dir="ltr"><<a href="mailto:henryjen@ztune.net" target="_blank">henryjen@ztune.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Calling clang_getCanonicalType on Unexposed works well, thanks for the tip.<br><br></div><div>It would be nice to know what function can be used on what type with confidence without checking for invalid type all the time, so again, perhaps there are test cases or references in the code that can shed some light?<br></div><div><br></div>Cheers,<br></div>Henry<br><br><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">Date: Fri, 27 Mar 2015 14:08:01 +0100<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">
From: Jacob Carlborg <<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>><br>
To: <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
Subject: Re: [cfe-dev] Function pointer in a struct declaration<br>
Message-ID: <mf3knh$3od$<a href="mailto:1@ger.gmane.org" target="_blank">1@ger.gmane.org</a>><br>
Content-Type: text/plain; charset=windows-1252; format=flowed<span><br>
<br>
On 2015-03-27 07:20, Henry Jen wrote:<br>
> Hi,<br>
><br></span><div><div class="h5">
> I would like to get the function type if a field of struct is a function<br>
> pointer, but I am not sure how to do that. I was expecting to get a<br>
> pointee type of FunctionProto on that field, but looks like I only get<br>
> an Unexposed.<br>
><br>
> Attached are a cursor visitor code I did to dump cursors and their type,<br>
> and the result of the dump for following snippet.<br>
><br>
> typedef struct foo {<br>
>      int(*fn)(char* arg1, long arg2);<br>
>      struct bar *ptr;<br>
> } foo;<br>
><br>
> I got a FieldDecl for fn, which has a type of Pointer whose pointeeType<br>
> is Unexposed. In case of struct, pointee type is also Unexposed, but<br>
> there is a TypeRef and StructDecl for bar, so at least I can figureout<br>
> there is a Record type, but how figure out the function type for fn?<br>
<br>
This is the way I identify a function pointer in my code [1]:<br>
<br>
1. If the cursor is a pointer<br>
2. And if the result type [2] of the ponitee type is valid, assume it's<br>
a function pointer<br>
<br>
"is valid" in this context would mean that the type kind is not<br>
CXType_Invalid.<br>
<br>
It's a workaround that has so far not caused any problems for me. I'm<br>
not sure if there's a better way to do this.<br>
<br>
Actually, I just noticed that the canonical type kind of the pointee<br>
type is CXType_FunctionProto. That looks like a better approach.<br>
<br>
[1] <a href="https://github.com/jacob-carlborg/dstep/blob/master/clang/Type.d#L52-L65" target="_blank">https://github.com/jacob-carlborg/dstep/blob/master/clang/Type.d#L52-L65</a><br>
[2] clang_getResultType<br>
<br>
--<br>
/Jacob Carlborg<br>
<br>
<br></div></div></blockquote></div><br></div></div></div></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>