[cfe-dev] Getting the fully scoped type of a function parameter

Manuel Klimek klimek at google.com
Tue Nov 20 02:38:30 PST 2012


You'll want something like:
pdecl->getType()->getAsCXXRecordDecl() (if it's not a pointer) or
pdecl->getType()->getPointeeCXXRecordDecl() if it's a pointer.

Cheers,
/Manuel


On Sat, Nov 17, 2012 at 5:56 PM, Pascal Ognibene <pognibene at gmail.com>wrote:

>
>
>
>> On Wed, Nov 14, 2012 at 3:13 AM, Pascal Ognibene <pognibene at gmail.com>wrote:
>>
>>> Hi all,
>>>
>>> I have a clang::ParmVarDecl argument of a C++ function/method.
>>> I need to retrieve the fully scoped type of this argument. For example:
>>>
>>> namespace foo
>>> {
>>>    typedef struct
>>>    {
>>>       int bla;
>>>    } oneStruct;
>>> }
>>>
>>> ...
>>>
>>> namespace foo
>>> {
>>>     int one_function(oneStruct *arg);
>>> };
>>>
>>> When I get the clang::FunctionDecl * for one_function, I then get a
>>> ParmVarDecl * for arg.
>>> To get the type I can use one of the QualType type =
>>> ParmVarDecl::get*Type() functions.
>>> However, when I get the type as a string, it's oneStruct * and not
>>> foo:oneStruct *
>>>
>>> How can I get the fully scoped name of this parameter? (using clang 3.1)
>>>
>>
>
>
> 2012/11/14 Manuel Klimek <klimek at google.com>
> NamedDecl has getQualifiedNameAsString(). If you drill through to the decl
> from the type (in your case getPointeeCXXRecordDecl should do)  you can use
> it to get the fully qualified name. (There might be easier ways I'm not
> aware of :)
>
>
> Hi Manuel,
>
> When reading your answer I realized that there was a typo in my question:
> I'm actually looking for the fully scoped type of the parameter.
> I still can't get what I want:
>
> clang::ParmVarDecl *pdecl;
> clang::QualType retType1 = pdecl->getOriginalType();
> const clang::Type * ttype = retType1.getTypePtrOrNull ( );
> const clang::CXXRecordDecl * rdecl =
> ttype->getCXXRecordDeclForPointerType();
>
> Will give me the scope for a struct or class pointer parameter. However it
> does not work if I have a struct parameter (without a pointer)
> or any other type (scoped typedefs for example).
>
> I can re-formulate my question as: from a ParmVarDecl *, how can I
> retrieve a pointer to the declaration of the parameter type?
>
> Thank you for your help,
>
> Pascal
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121120/da91dedd/attachment.html>


More information about the cfe-dev mailing list