[cfe-dev] Proposal: add "replace" functionality to clang-query

Yitzhak Mandelbaum via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 25 10:05:11 PDT 2020


Aaron, thanks for mentioning Clang Transformer. Alexander, you can find the
original doc here
<https://docs.google.com/document/d/1ppw0RhjwsrbBcHYhI85pe6ISDbA6r5d00ot3N8cQWeQ/edit#heading=h.qjjywl5dhpsb>.
The code is under Tooling:
https://github.com/llvm/llvm-project/tree/master/clang/include/clang/Tooling/Transformer

On Wed, Mar 25, 2020 at 12:52 PM Aaron Ballman <aaron at aaronballman.com>
wrote:

> On Tue, Mar 24, 2020 at 4:22 PM Alexander Timin via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
> >
> > Hey!
> >
> > 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.
> >
> > 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:
> >
> > replace MATCHER NODE PATTERN
> >
> > for example,
> >
> > let f = cxxMethodDecl(hasName("Foo"))
> > let arg1 = hasArgument(0, expr().bind("arg1"))
> > let arg2 = hasArgument(1, expr().bind("arg2"))
> > let m = callExpr(on(f), arg1, arg2)
> > replace m root Foo(${arg2}, ${arg1})
> >
> > A more detailed design doc is available here.
> >
> > An early prototype patch is available here.
> > A real-life example: the query is here, the output in the form of a
> Chromium patch is here.
> >
> > WDYT?
>
> Thank you for bringing up this idea, I've wanted something that can do
> this for a while. I think the idea has a lot of merit, but I'm
> wondering whether we want to focus on code transformations within
> clang-query like this as opposed to putting that effort into the
> in-progress Transformer work
> (http://lists.llvm.org/pipermail/cfe-dev/2019-January/060950.html).
> Are you aware of those efforts? If so, how do you see this proposal
> coexisting with that functionality?
>
> ~Aaron
>
>
> > Alexander
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200325/67cbeb1f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3854 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200325/67cbeb1f/attachment.bin>


More information about the cfe-dev mailing list