Collect template instantiations from clang AST

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Collect template instantiations from clang AST

Richard Pennington via cfe-dev
Hello,

I am trying to collect all template instantiations via traversing AST with RecursiveASTVisitor. I thought I would be able to do it with VisitFunctionDecl from class RecursiveASTVisitor and getTemplateInstantiationPattern from class FunctionDecl. However, as mentioned in the comment to this method, it just returns the function declaration, from wich it could be instantiated. I discovered that this method returns the first acceptable pattern from the context of instantiation. Is there any way to get a real pattern out of a function template instantiation?
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collect template instantiations from clang AST

Richard Pennington via cfe-dev
Hi,

To visit all templates you could write a VisitTemplateDecl, the
instantiations are children of the template declaration.

If you only want function templates, then use VisitFunctionTemplateDecl.
Inside that method, use VisitFunctionTemplateDecl::specialisations() to
access all instantiantiations. I did not test it but it should be that
easy, provided that's what you meant

Johannes


> From cfe-dev at lists.llvm.org  Mon Apr 10 15:37:41 2017
> From: cfe-dev at lists.llvm.org (=?utf-8?B?0K/QutC+0LLQu9C10LIg0JLQu9Cw0LQ=?= via cfe-dev)
> Date: Tue, 11 Apr 2017 01:37:41 +0300
> Subject: [cfe-dev] Collect template instantiations from clang AST
> Message-ID: <[hidden email]>
>
> Hello,
>
> I am trying to collect all template instantiations via traversing AST with RecursiveASTVisitor. I thought I would be able to do it with VisitFunctionDecl from class RecursiveASTVisitor and getTemplateInstantiationPattern from class FunctionDecl. However, as mentioned in the comment to this method, it just returns the function declaration, from wich it could be instantiated. I discovered that this method returns the first acceptable pattern from the context of instantiation. Is there any way to get a real pattern out of a function template instantiation?
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collect template instantiations from clang AST

Richard Pennington via cfe-dev
In reply to this post by Richard Pennington via cfe-dev
On 04/11/2017 12:37 AM, Яковлев Влад via cfe-dev wrote:
> I am trying to collect all template instantiations via traversing AST with RecursiveASTVisitor. I thought I would be able to do it with VisitFunctionDecl from class RecursiveASTVisitor and getTemplateInstantiationPattern from class FunctionDecl. However, as mentioned in the comment to this method, it just returns the function declaration, from wich it could be instantiated. I discovered that this method returns the first acceptable pattern from the context of instantiation. Is there any way to get a real pattern out of a function template instantiation?

There's RecursiveASTVisitor::shouldVisitTemplateInstantiations()
(defaulting to false) which you can "override" in your derivation.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...