<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Mar 28, 2018 at 7:32 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_-8806119161685434701WordSection1">
<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 quite new to clang AST matchers and wondering if you could help me with a match. I am writing a matcher to generate replacements.
<br>
<br>
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Consider this,<br>
<br>
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">SomeClientBuilder SCB(Foo& f) {<br>
return SomeClientBuilder.setFoo(f);<br>
}<br>
<br>
class SomeClientBuilder {<br>
Fruit apple(…);<br>
Fruit pear(…);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">};<br>
<br>
I would like to change <br>
“return SCB(foo).apple(req).get(…)”<br>
to<br>
“return SCB().pear(req).via(foo).get(…)”<br>
<br>
I would like to create a matcher that:<br>
- matches SCB so it has 1 argument of type Foo<br>
- matches method named apple() and is a method in SomeClientBuilder<br>
<br>
After many attempts, I came up with two matchers.<br>
<br>
1. cxxMemberCallExpr(callee(cxxMethodDecl(hasName("apple"), ofClass(cxxRecordDecl(hasName("SomeClientBuilder "))))))<br>
- this matcher does not restrict SCB to have 1 argument of type Foo<br></span></p></div></div></blockquote><div><br></div><div>You should be able to compine this with the "on" matcher for cxxMemberCallExpr.</div><div>See <a href="http://clang.llvm.org/docs/LibASTMatchersReference.html">http://clang.llvm.org/docs/LibASTMatchersReference.html</a></div><div><br></div><div>on() takes an expr matcher as argument, with which you can match the nested call expr.</div><div> </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_-8806119161685434701WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt">
<br>
2. callExpr(callee(functionDecl(hasName("SCB"))), argumentCountIs(1), hasArgument(0, hasType(cxxRecordDecl(hasName("Foo")))))<br>
- this matcher does not match the “apple()” methods<br>
<br>
I have tried combining the matchers together with no success. What do you think would be the best way to accomplish what I want to do?<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<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"><br>
<br>
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><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></div>