[cfe-dev] Function Rewriting

John McCall rjmccall at apple.com
Mon Aug 10 23:20:49 PDT 2009


Makslane Araújo Rodrigues wrote:
> What I do is something like this:
>
> void AddParameter(FunctionDecl *FD) 
> {
>   SourceLocation loc;
> for (FunctionDecl::param_iterator I=FD->param_begin(), 
> E=FD->param_end(); I!=E; ++I)
> {
> loc = (*I)->getLocation();
> }
>
>   Rewrite.InsertTextAfter(loc, ", int y", 7);
> }
>
> The problem is instead I get the void func(int x, int y), I 
> get func(int , int yx)
>
> Can someone tell me what is wrong?

"loc" is the location of the start of the identifier, not the location 
of the end of the parameter declaration;  thus when you insert at that 
point, it inserts before the variable name.  You want to insert after 
the end of the variable declaration;  unfortunately, it looks like that 
location just isn't preserved in the AST.  That's definitely worth 
filing a bug about.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090810/7d91f4f3/attachment.html>


More information about the cfe-dev mailing list