<div dir="ltr"><div><div><div>Thanks, that was it.<br></div>The code is hairy though.<br></div>I'd be helpful if there was some function for this.<br><br> bool VisitClassTemplateDecl(clang::ClassTemplateDecl* Declaration) {<br>
<br> if(Declaration->getName().startswith("_")<br> || Declaration->getName().size()==0)<br> return true;<br><br> std::vector<NamespacePrinterRAII> scope;<br> clang::DeclContext* c=Declaration->getTemplatedDecl()->getEnclosingNamespaceContext();<br>
while(c->isNamespace()) {<br> clang::NamespaceDecl* n=llvm::cast<clang::NamespaceDecl>(c);<br> scope.emplace_back(n->getNameAsString());<br> c=c->getParent();<br> }<br><br> llvm::outs()<<"template <";<br>
clang::TemplateParameterList* tl=Declaration->getTemplateParameters();<br> for(auto it=tl->begin();it!=tl->end();++it) {<br> if(llvm::isa<clang::NonTypeTemplateParmDecl>(*it)) {<br> clang::NonTypeTemplateParmDecl* td=llvm::cast<clang::NonTypeTemplateParmDecl>(*it);<br>
llvm::outs()<<td->getType().getAsString();<br> }<br> else llvm::outs()<<"typename";<br> llvm::outs()<<" "<<(*it)->getName();<br> if((it+1)!=tl->end())<br>
llvm::outs()<<", ";<br> }<br> llvm::outs()<<"> class "<br> << Declaration->getName() << ";\n";<br><br> return false;<br> }<br><br>
</div>Using dump or print prints the whole body, but I have to display only what is necessary for a forward declaration.<br><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 9, 2014 at 11:22 AM, James Dennett <span dir="ltr"><<a href="mailto:james.dennett@gmail.com" target="_blank">james.dennett@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Sun, Jun 8, 2014 at 9:31 PM, Manasij Mukherjee <<a href="mailto:manasij7479@gmail.com">manasij7479@gmail.com</a>> wrote:<br>
> As a follow up to this question, I am now generating the<br>
> (forward)declarations manually, not having found anything in the API to do<br>
> it.<br>
> The only thing that I can't get working is the way to get the type name of a<br>
> non-type template parameter.<br>
> If I have:<br>
> template<typename T, typename U, int V> class foo<br>
> {};<br>
> From where do I get the string "int" when overriding VisitClassTemplateDecl<br>
> ?<br>
><br>
> I can get the names of the identifiers T, U, V as:<br>
><br>
> clang::TemplateParameterList* tl=Declaration->getTemplateParameters();<br>
> for(auto it=tl->begin();it!=tl->end();++it) {<br>
> p->getName();<br>
> }<br>
><br>
> But I can't find any obvious way to get its type as a string.<br>
> p->getDeclKindName() only returns "TemplateTypeParm" or<br>
> "NonTypeTemplateParm"<br>
<br>
</div>If the NamedDecl* is a NonTypeTemplateParmDecl* then it has a<br>
getType() member function (inherited from ValueDecl) returning a<br>
QualType. You might need to be careful in case<br>
NonTypeTemplateParmDecl::isParameterPack() is true; I don't know what<br>
getType() returns for a parameter pack (though it clearly wouldn't be<br>
hard to check).<br>
<span class="HOEnZb"><font color="#888888"><br>
-- James<br>
</font></span></blockquote></div><br></div>