[cfe-dev] SourceLocation information from TemplateArgument

Stephen Kelly via cfe-dev cfe-dev at lists.llvm.org
Sun Jan 27 05:39:28 PST 2019


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.



More information about the cfe-dev mailing list