Querying C++ function declarations

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

Querying C++ function declarations

Oksana Tkachuk
Hello,
I am new to Clang and I would like to use it (as a library, not a
command-line tool) to perform some basic structural analysis of C++
functions.
Given a "FunctionDecl" object, I would like to find out the function's
declaring (enclosing) class and the function's access level
(public/private).
Which Clang APIs could be used to find this info? Code samples would be
very helpful.

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

Re: Querying C++ function declarations

Ted Kremenek
Hi Oksana,

If the FunctionDecl represents a C++ method, it actually will be an instance of CXXMethodDecl.  Try doing:

  FunctionDecl *FD = ...
  ...
  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {


  }

Once you have a CXXMethodDecl*, you should be able to directly do most of the things you are asking for, including finding the enclosing class (via getParent()).  I don't know off the top of my head, however, how to get the access control (as it was declared) for the method.

On Sep 20, 2010, at 5:13 PM, Oksana Tkachuk wrote:

> Hello,
> I am new to Clang and I would like to use it (as a library, not a
> command-line tool) to perform some basic structural analysis of C++
> functions.
> Given a "FunctionDecl" object, I would like to find out the function's
> declaring (enclosing) class and the function's access level
> (public/private).
> Which Clang APIs could be used to find this info? Code samples would be
> very helpful.
>
> Thank you,
> Oksana.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


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

Re: Querying C++ function declarations

Oksana Tkachuk
Hi Ted,

>
> If the FunctionDecl represents a C++ method, it actually will be an instance of CXXMethodDecl.  Try doing:
>
>   FunctionDecl *FD = ...
>   ...
>   if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
>
>
>   }
>
> Once you have a CXXMethodDecl*, you should be able to directly do most of the things you are asking for, including finding the enclosing class (via getParent()).  I don't know off the top of my head, however, how to get the access control (as it was declared) for the method.
>
Thank you for the detailed answer. For finding the enclosing class,
MD->getParent() works nicely.
For the access control, it's MD->getAccess().

Thanks,
Oksana.

> On Sep 20, 2010, at 5:13 PM, Oksana Tkachuk wrote:
>
>
>> Hello,
>> I am new to Clang and I would like to use it (as a library, not a
>> command-line tool) to perform some basic structural analysis of C++
>> functions.
>> Given a "FunctionDecl" object, I would like to find out the function's
>> declaring (enclosing) class and the function's access level
>> (public/private).
>> Which Clang APIs could be used to find this info? Code samples would be
>> very helpful.
>>
>> Thank you,
>> Oksana.
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev