<div dir="ltr"><div dir="ltr"><div dir="ltr">Thanks Yitzhak and Aaron!</div><div dir="ltr"><br></div><div>As an outsider to the clang land, I wasn't aware of the Transformer — thanks for pointing me to it, it looks really exciting.</div><div><br></div><div>I think that my proposal can be broken down into two parts:</div><div>a) Adding an option to generate replacements without having to build a C++ tool. </div><div>b) Particular syntax to generate these replacements.</div><div><br></div><div>I think that Transformer effort covers only the b) part — please correct me if I'm wrong.</div><div><br></div><div>And out of these two, I (looking at the things from the user perspective) think that a) is the most important one, as having to write </div><div>and link C++ code adds a lot of friction to the process (so sed + manual edits are still faster). So I think that there is a nice synergy</div><div>potential in the long term — I think that the ideal end state would be having the ability to write Transformer-based queries dynamically in</div><div>clang-query, something like that:</div><div><br></div><div>$ clang-query</div><div>> transform matcher makeStencil(ifBound("value", true, false))</div><div><br></div><div>However (as building the dynamic Stencils sounds non-trivial), I think that there is no particular harm in having both options available in clang-query, one being easier to write and one being more flexible:</div><div><br></div><div>> replace matcher foo = ${foo}</div><div>> transform matcher complexStencil(...)</div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Mar 2020 at 17:05, Yitzhak Mandelbaum <<a href="mailto:yitzhakm@google.com" target="_blank">yitzhakm@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Aaron, thanks for mentioning Clang Transformer. Alexander, you can find the original doc <a href="https://docs.google.com/document/d/1ppw0RhjwsrbBcHYhI85pe6ISDbA6r5d00ot3N8cQWeQ/edit#heading=h.qjjywl5dhpsb" target="_blank">here</a>.  The code is under Tooling: <a href="https://github.com/llvm/llvm-project/tree/master/clang/include/clang/Tooling/Transformer" style="font-family:Arial,Helvetica,sans-serif" target="_blank">https://github.com/llvm/llvm-project/tree/master/clang/include/clang/Tooling/Transformer</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 25, 2020 at 12:52 PM Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Mar 24, 2020 at 4:22 PM Alexander Timin via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hey!<br>
><br>
> I think that medium-scale medium-complexity C++ refactorings (like replacing the order of the two arguments of a function across a large codebase) are much harder that they should be: clang-refactor and clang-rename do not cover them and writing a full libTooling tool is not the most time-efficient solution.<br>
><br>
> I propose extending the functionality of clang-query to cover this use case and allow generating replacements (which can be then applied by clang-apply-replacements) from matches:<br>
><br>
> replace MATCHER NODE PATTERN<br>
><br>
> for example,<br>
><br>
> let f = cxxMethodDecl(hasName("Foo"))<br>
> let arg1 = hasArgument(0, expr().bind("arg1"))<br>
> let arg2 = hasArgument(1, expr().bind("arg2"))<br>
> let m = callExpr(on(f), arg1, arg2)<br>
> replace m root Foo(${arg2}, ${arg1})<br>
><br>
> A more detailed design doc is available here.<br>
><br>
> An early prototype patch is available here.<br>
> A real-life example: the query is here, the output in the form of a Chromium patch is here.<br>
><br>
> WDYT?<br>
<br>
Thank you for bringing up this idea, I've wanted something that can do<br>
this for a while. I think the idea has a lot of merit, but I'm<br>
wondering whether we want to focus on code transformations within<br>
clang-query like this as opposed to putting that effort into the<br>
in-progress Transformer work<br>
(<a href="http://lists.llvm.org/pipermail/cfe-dev/2019-January/060950.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/cfe-dev/2019-January/060950.html</a>).<br>
Are you aware of those efforts? If so, how do you see this proposal<br>
coexisting with that functionality?<br>
<br>
~Aaron<br>
<br>
<br>
> Alexander<br>
> _______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div>