[cfe-dev] Questions about CXXRecordDecl
Johannes Schaub (litb)
schaub.johannes at googlemail.com
Sun Mar 13 15:06:05 PDT 2011
Alexander MacDonald wrote:
> Hi, I'm writing a small clang plugin to inspect a codebase I work on and
> perform various custom semantic analyses. I've figured out most of what I
> need but I've run into a couple of small problems:
>
> Given a CXXRecordDecl which represents an implicitly instantiated template
> class (mydecl->getTemplateSpecializationKind() ==
> TSK_ImplicitInstantiation). I want to find the original unspecialized
> CXXRecordDecl / QualType. mydecl->getDescribedClassTemplate() is returning
> null, perhaps there's some functionality in Sema I should be using
> instead?
>
It sounds like you want
mydecl->getInstantiatedFrom()
(cast it to ClassTemplateSpecializationDecl first). If it was implicitly
instantiated from a primary class template (instead of a partial
specialization), you may need to call getTemplatedDecl() on the resulting
pointer to get the CXXRecordDecl of the template.
Assuming mydecl is a "A<int>", mydecl->getDescribedClassTemplate() would
return true for the CXXRecordDecl of "A<T>". The class A<int> is not
templated, so has no class template is describes.
This is just the result of my doxygen checkup. I've no experience with clang
code, but it makes sense :)
More information about the cfe-dev
mailing list