[cfe-dev] Questions about CXXRecordDecl
Alexander MacDonald
alexmac at adobe.com
Sun Mar 13 16:04:33 PDT 2011
On 13 Mar 2011, at 15:06, Johannes Schaub (litb) wrote:
> 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 :)
That did the trick, thanks! Somehow I missed the ClassTemplateSpecializationDecl in all my searches through the code
More information about the cfe-dev
mailing list