[cfe-dev] Type exploration in clang AST
John McCall
rjmccall at apple.com
Mon Dec 13 08:36:28 PST 2010
On Dec 13, 2010, at 4:03 AM, Olivier wrote:
> Hi,
>
> I'm trying to figure out how to extract information from the Type classes
> hierarchy but I'm bumping into a few problems.
>
> Given a template instantiation TI - that would be represented by a
> clang::TemplateSpecializationType node - I'm trying to determine if any of the
> template arguments of TI are used as a member or a base class of TI.
>
> But I can't seem to figure out how to get that information from a
> clang::TemplateSpecializationType.
>
>
> void process( clang::TemplateSpecializationType const *pType )
> {
> // Get the associated template declaration.
> clang::TemplateDecl const *pDecl
> = pType->getTemplateName().getAsTemplateDecl();
>
> if(pDecl)
> {
> // Get the templated record associated to the template specialization.
> clang::CXXRecordDecl const *pRecD
> = cast<clang::CXXRecordDecl>(pDecl->getTemplatedDecl());
>
> // Get a pointer to the instantiation arguments array.
> clang::TemplateArgument const *pArgs = pType->getArgs();
>
> // Get the size of the instantiation arguments array.
> unsigned nbArgs = pType->getNumArgs();
> }
> }
>
> How with this information can I now get the complete types of all base classes
> and members of the type represented by 'pType' ?
TST->getAsCXXRecordDecl(). If that's null, the type refers to an unknown
specialization; otherwise, you can ask the decl if it's complete, and if it is
then you can walk over the members and base types. Be aware that a type
can be a known specialization and still be dependent, so the direct (and
indirect) base classes may still be dependent, unresolved types.
John.
More information about the cfe-dev
mailing list