[cfe-dev] [RFC] Easier source-to-source transformations with clang tooling

Jonas Toth via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 25 02:12:57 PST 2019


Thanks for clarification. Having it directly in clang-tidy would be nice
though :)

Am 24.01.19 um 12:17 schrieb Manuel Klimek:
> On Thu, Jan 24, 2019 at 11:56 AM Jonas Toth <development at jonas-toth.eu
> <mailto:development at jonas-toth.eu>> wrote:
>
>     Hi,
>
>     one question that came to my mind because of Joel's Mail:
>
>     Is it possible to run in multiple passes?
>     My use-case is adding `const` to variables that could be 'const'
>     but aren't. If you declare multiple variables like `int not_const,
>     const_variable;`
>     the transformation requires splitting these up, first -> `int
>     not_const; int const_variable;` and then do the `const`
>     transformation -> `int not_const; const int const_variable;`.
>
>     I have implemented both transformations in clang-tidy (only
>     partially landed yet) but there is no easy way I can run them in
>     one check. The current workflow
>     pretty much forces us to run clang-tidy multiple times and
>     converge to the final solution.
>
>     If your framework could give an improvement in this place, would
>     be awesome! And I think worth to consider anyway If we change the way
>     we do transformations.
>
>
> Generally, you can already do this, but it'd be outside clang-tidy.
> You can write a clang tool that
> a) runs over the codebase and stores the "const graph"
> b) load the "const graph" into memory and generate all the
> replacements (there's a way to create yaml replacements)
> c) apply all the replacements
>
>  
>
>     Best, Jonas
>
>     Am 16.11.18 um 16:22 schrieb Yitzhak Mandelbaum via cfe-dev:
>>     Hi all,
>>
>>     I have a proposal for a framework that makes it easier to write
>>     source to source transformations with the clang::Tooling
>>     libraries, including clang-tidy checks.
>>
>>     The full proposal is in this doc:
>>
>>     https://docs.google.com/document/d/1ppw0RhjwsrbBcHYhI85pe6ISDbA6r5d00ot3N8cQWeQ/edit?usp=sharing
>>
>>     From the doc:
>>     Transformer is a framework that aims to simplify development of
>>     clang-based source-to-source transformations.  It focuses on the
>>     particular class of transformations that act only locally — that
>>     is, use local information about the code and make local changes 
>>     (like a syntax-aware “find-and-replace”); and at scale — that is,
>>     will be carried out on many source files.  The target audience is
>>     users that are comfortable with, or willing to become comfortable
>>     with, the clang AST matchers library.
>>
>>     I have a working prototype of this library which I've used on
>>     small examples inside Google.  I plan to put together a patch for
>>     reference next week, although the doc should stand on its own.
>>
>>     Thanks!
>>     Yitzhak Mandelbaum
>>
>>     _______________________________________________
>>     cfe-dev mailing list
>>     cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>     http://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/20190125/3f77fea6/attachment.html>


More information about the cfe-dev mailing list