[cfe-dev] Using Rewriter to remove a function call argument along with preceding comma?

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jun 7 11:19:51 PDT 2013


On Jun 7, 2013, at 5:31 AM, Stephan Bergmann <sbergman at redhat.com> wrote:

> Am new here, hope this isn't too dumb a question.  (And from looking at the archives, fits better here than on cfe-users?)
> 
> Anyway, what I want to do is a rewriting Clang plugin that removes one argument from specific function calls.  But where I'm lost is how to determine the SourceLocation of the comma preceding the given argument, to do something like

You could remove this range:

[loc-for-end-of-token of end location of preceding argument, end location of removed argument]

like in these examples:

foo(4, 5, 6) --> foo(4, 6)
     ^-^

foo(4 , 5 , 6) --> foo(4 , 6)
     ^--^

foo(4, 5, 6) --> foo(4, 5)
        ^-^

foo( 4 , 5 , 6 ) --> foo( 4 , 5 )
          ^--^

> 
>  Rewriter.RemoveText(
>    SourceRange(
>      /*TODO*/,
>      callExpr->getArg(1)->getLocEnd()));
> 
> Thanks,
> Stephan
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130607/2f028525/attachment.html>


More information about the cfe-dev mailing list