[cfe-dev] Question about writing a refactoring tool

Yitzhak Mandelbaum via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 21 07:29:01 PST 2020

+1 You can pro-actively run clang-tidy over your code base and apply the
edits to get the result you want. That is, it's not just for giving
diagnostics, suggestions, etc. in an IDE setting.

As for sophistication -- yes, clang-tidy and clang Tooling more generally
have been used for very sophisticated edits.  To get a sense, I'd recommend
looking at the clang-tidy check tests. They are lit tests, so essentially
each test is example code with the expected fixes:

A possibly-relevant example:


and it's corresponding code:


You might also find the Clang Transformer is an easier interface to writing
the refactoring.  You can find that here:


And it ties into clang-tidy here:

For example,

If you find you're interested in clang-transformer, please let me know and
I can send along a tutorial which I'm working on but haven't yet published

On Fri, Dec 18, 2020 at 3:35 AM Miklos Vajna via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi Zachary,
> To get started, you can probably ignore clang-refactor. Internally it
> uses the same/similar API as clang-tidy, but the later has much more
> material available.
> For example, I found https://www.youtube.com/watch?v=1S2A0VWGOws as a
> great overview; after that, you can just use clang-query / API docs to
> figure out the details. That all talks about clang-tidy.
> Regards,
> Miklos
> _______________________________________________
> 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/20201221/76f7266f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4000 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20201221/76f7266f/attachment.bin>

More information about the cfe-dev mailing list