<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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Jacob Carlborg <<a href="mailto:doob@me.com">doob@me.com</a>><br>
To: <a href="mailto:cfe-dev@cs.uiuc.edu">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">1@ger.gmane.org</a>><br>
Content-Type: text/plain; charset=windows-1252; format=flowed<br>
<br>
On 2015-03-27 07:20, Henry Jen wrote:<br>
> Hi,<br>
><br>
> 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></blockquote></div><br></div></div></div></div></div></div>