Link between clang::FunctionType and clang::FunctionDecl

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Link between clang::FunctionType and clang::FunctionDecl

Vassil Vassilev-2
Hi,
   Maybe a silly question, but why I cannot get the FunctionDecl for a
given FunctionType?
Thanks,
Vassil
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link between clang::FunctionType and clang::FunctionDecl

Sebastian Redl

On 02.06.2013, at 13:39, Vassil Vassilev wrote:

> Hi,
>  Maybe a silly question, but why I cannot get the FunctionDecl for a given FunctionType?

Because

void f();
void g();
void h();

all have the same FunctionType. Which decl do you want?


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link between clang::FunctionType and clang::FunctionDecl

Vassil Vassilev-2
On 6/2/13 2:01 PM, Sebastian Redl wrote:

> On 02.06.2013, at 13:39, Vassil Vassilev wrote:
>
>> Hi,
>>   Maybe a silly question, but why I cannot get the FunctionDecl for a given FunctionType?
> Because
>
> void f();
> void g();
> void h();
>
> all have the same FunctionType. Which decl do you want?
>
Arh... I see. Here is what I want to do:

template<typename F, typename... Args, typename... A>
F callF(F (*f)(Args...), A&&... a) {
    return f(a...);
}

int f(int x) {
   printf("This is f(x).\n");
   return x*x;
}

int main () {
   int x = 4;
   callF(f, x); // Here at that point, I want to get the decl of f. That
should be possible, right?
   return 0;
}

Vassil
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link between clang::FunctionType and clang::FunctionDecl

Sebastian Redl

On 02.06.2013, at 14:26, Vassil Vassilev wrote:

> Arh... I see. Here is what I want to do:
>
> template<typename F, typename... Args, typename... A>
> F callF(F (*f)(Args...), A&&... a) {
>   return f(a...);
> }
>
> int f(int x) {
>  printf("This is f(x).\n");
>  return x*x;
> }
>
> int main () {
>  int x = 4;
>  callF(f, x); // Here at that point, I want to get the decl of f. That should be possible, right?
>  return 0;
> }

Yes. The AST should look something like this:

ExprStmt(CallExpr(..., ImplicitCastExpr(DeclRefExpr('f')), ...))

and the DeclRefExpr should have a handle to f.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Link between clang::FunctionType and clang::FunctionDecl

Vassil Vassilev-2
On 6/2/13 3:39 PM, Sebastian Redl wrote:

> On 02.06.2013, at 14:26, Vassil Vassilev wrote:
>
>> Arh... I see. Here is what I want to do:
>>
>> template<typename F, typename... Args, typename... A>
>> F callF(F (*f)(Args...), A&&... a) {
>>    return f(a...);
>> }
>>
>> int f(int x) {
>>   printf("This is f(x).\n");
>>   return x*x;
>> }
>>
>> int main () {
>>   int x = 4;
>>   callF(f, x); // Here at that point, I want to get the decl of f. That should be possible, right?
>>   return 0;
>> }
> Yes. The AST should look something like this:
>
> ExprStmt(CallExpr(..., ImplicitCastExpr(DeclRefExpr('f')), ...))
>
> and the DeclRefExpr should have a handle to f.
Sorry for the noise I was mislead. Thanks for steering me in the right
direction :)
Vassil
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev