<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<p>Yes, Transformer seems to be what you're looking for. I made a
proof-of-concept GUI tool which integrates Transformer which you
can see here:</p>
<p> <a class="moz-txt-link-freetext" href="https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools">https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools</a><br>
</p>
<p>I think a GUI integration makes more sense than clang-query, so
you might find that pursuing a GUI approach would make it easier
to expose Transformer features.</p>
<p>Thanks,</p>
<p>Stephen.<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 25/03/2020 17:47, Alexander Timin
via cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CALHg4nkX-R_YVAyu4H7fAFJ7d-UKUxinvL9RsJpvOQFgERKk4w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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" moz-do-not-send="true">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" moz-do-not-send="true">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" moz-do-not-send="true">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"
moz-do-not-send="true">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" moz-do-not-send="true">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" moz-do-not-send="true">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" moz-do-not-send="true">cfe-dev@lists.llvm.org</a><br>
> <a
href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote>
</div>
</blockquote>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
</body>
</html>