SourceLocation information from TemplateArgument

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SourceLocation information from TemplateArgument

David Blaikie via cfe-dev
Hi,
I'm trying to write a tool that recurses into TemplateArguments and rewrites specific arguments.  However, I'm having trouble getting SourceLocation information out of the TemplateArgument objects.

Once I have a TemplateArgument, if the TemplateArgument::getKind() returns TemplateArgument::Type, I can get a Type * for the argument, but from there I'm having trouble getting the SourceLocation information.  It seems that generally you need a Decl object to get SourceLocations.

Any tips or strategies would be appreciated.  Thanks!

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SourceLocation information from TemplateArgument

David Blaikie via cfe-dev
On 25/01/2019 16:25, John Smith via cfe-dev wrote:

> Hi,
> I'm trying to write a tool that recurses into TemplateArguments and
> rewrites specific arguments.  However, I'm having trouble getting
> SourceLocation information out of the TemplateArgument objects.
>
> Once I have a TemplateArgument, if the TemplateArgument::getKind()
> returns TemplateArgument::Type, I can get a Type * for the argument, but
> from there I'm having trouble getting the SourceLocation information.  
> It seems that generally you need a Decl object to get SourceLocations.
>
> Any tips or strategies would be appreciated.  Thanks!


Yes, if you had a Decl and now only have a Type, then you have discarded
source location information.

Similarly, if you had a FunctionTemplateDecl for example and now only
have a TemplateArgument, you have discarded source location information.

You probably need to use the TypeLoc information to process the template
arguments if there is any complexity to them.

If you are using AST Matchers, then you will find this useful:

http://ec2-18-191-7-3.us-east-2.compute.amazonaws.com:10240/z/CoEAk-

Even if you are not using AST Matchers, it helps you to explore the AST
and see what source locations can be retrieved.

Thanks,

Stephen.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev