[cfe-dev] How to retrieve entire argument name with operators

David Lai via cfe-dev cfe-dev at lists.llvm.org
Sun Apr 8 01:00:30 PDT 2018


Hi,

I am writing a replacement to move arguments from one function to another.

For instance,

foo(arg1) -> foo().bar(arg1)
foo(*arg2) -> foo().bar(*arg2)
foo(…) -> foo().bar(…)

where arg1, arg2, … are resolved to the same type.

I am able to handle the first case doing something like this:

matcher = callExpr(callee(functionDecl(hasName(“foo”)))).bind(call)

replacements.emplace(sourceManager,
                                          call->getArg(0)->getExprLoc(),
                                          Lexer::getLocForEndOfToken(call->getArg(0)->getExprLoc(),
                                                                                                         0,
sourceManager,
context.getLangOpts())),
             “”);

Which is able to change “foo(arg1)” to foo().bar(arg1). However, for cases with UnaryOperators inbetween, the outcome is:
“foo(*arg2)” -> “foo(arg2).bar(*arg2). It only considers the unary operator and does not remove the “arg2” portion of the argument.

I cannot figure out a clean way to do this. What is the suggested way to get that argument regardless of what operators that could be in front of it?
Note: I am trying to remove that argument completely.


Thanks,
David Lai

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180408/145599d8/attachment.html>


More information about the cfe-dev mailing list