<div dir="ltr">Hi David,<div><br></div><div>Typically, when you get a SourceLocation from a AST object, it points at the start of token.  Since you are using the same SourceLocation for the start and end, the replacement only removes the * token.  Also, the function getExprLoc() returns the best location for a diagnostic, and may not be useful elsewhere.</div><div><br></div><div>To get the start and end SourceLocation's, use the functions getLocStart() and getLocEnd().  These are from the class Stmt, which is the parent of Expr.</div><div><br></div><div>Hope that helps.</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Apr 8, 2018 at 4:21 AM David Lai via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-8461025231614755690WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I am writing a replacement to move arguments from one function to another.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">For instance,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">foo(arg1) -> foo().bar(arg1)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">foo(*arg2) -> foo().bar(*arg2)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">foo(…) -> foo().bar(…)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">where arg1, arg2, … are resolved to the same type.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I am able to handle the first case doing something like this:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">matcher = callExpr(callee(functionDecl(hasName(“foo”)))).bind(call)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">replacements.emplace(sourceManager,
<br>
                                          call->getArg(0)->getExprLoc(), <br>
                                          Lexer::getLocForEndOfToken(call->getArg(0)->getExprLoc(),
<br>
                                                                                                         0,
<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:238.5pt"><span style="font-size:11.0pt">sourceManager,
<br>
context.getLangOpts())),<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:1.0in"><span style="font-size:11.0pt">             “”);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Which is able to change “foo(arg1)” to foo().bar(arg1). However, for cases with UnaryOperators inbetween, the outcome is:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">“foo(*arg2)” -> “foo(arg2).bar(*arg2). It only considers the unary operator and does not remove the “arg2” portion of the argument.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">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?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Note: I am trying to remove that argument completely.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">David Lai<br>
<br>
<u></u><u></u></span></p>
</div>
</div>

_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>