[cfe-dev] How to print the forward declaration of an object visited through RecursiveASTVisitor ?

James Dennett james.dennett at gmail.com
Sun Jun 8 22:52:54 PDT 2014


On Sun, Jun 8, 2014 at 9:31 PM, Manasij Mukherjee <manasij7479 at gmail.com> wrote:
> As a follow up to this question, I am now generating the
> (forward)declarations manually, not having found anything in the API to do
> it.
> The only thing that I can't get working is the way to get the type name of a
> non-type template parameter.
> If I have:
> template<typename T, typename U, int V> class foo
> {};
> From where do I get the string "int" when overriding VisitClassTemplateDecl
> ?
>
> I can get the names of the identifiers T, U, V as:
>
>     clang::TemplateParameterList* tl=Declaration->getTemplateParameters();
>     for(auto it=tl->begin();it!=tl->end();++it) {
>         p->getName();
>     }
>
> But I can't find any obvious way to get its type as a string.
> p->getDeclKindName() only returns "TemplateTypeParm" or
> "NonTypeTemplateParm"

If the NamedDecl* is a NonTypeTemplateParmDecl* then it has a
getType() member function (inherited from ValueDecl) returning a
QualType.  You might need to be careful in case
NonTypeTemplateParmDecl::isParameterPack() is true; I don't know what
getType() returns for a parameter pack (though it clearly wouldn't be
hard to check).

-- James



More information about the cfe-dev mailing list