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

Manasij Mukherjee manasij7479 at gmail.com
Sun Jun 8 21:31:47 PDT 2014


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"





On Thu, Jun 5, 2014 at 2:19 PM, Manasij Mukherjee <manasij7479 at gmail.com>
wrote:

> Hi,
> I am writing a tool that has to generate forward declarations of the
> classes, functions and templates.
> So, if it encounters,
> class Foo {
> };
> The output should be:
> class Foo;
>
> I am just trying to consider a specific case first by overriding
> VisitCXXRecordDecl .
>
> The print method of the declaration seems to print the whole definition.
>
> Declaration->print(llvm::outs(),clang::PrintingPolicy(clang::LangOptions()));
>
>
> Is there a general way of doing this?
> Or should I try to generate declaration in an adhoc way?
> Something like...
> llvm::outs()<< `GET TYPE` << `GET NAME` << `ATTRIBUTES` ;
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140609/b9f4afc7/attachment.html>


More information about the cfe-dev mailing list