[cfe-dev] C++11 migration tools

Sam Panzer panzer at google.com
Thu Jun 28 19:06:52 PDT 2012

In case anyone wanted to take a look, the attached patch includes the tool
I've been working on. I create a new binary, c++migrate, which attempts to
convert for loops in the source files given to it. Most of my focus has
been on the FrontedAction, so I skirted all of the issues mentioned above
by keeping the frontend interaction minimal (i.e. I just call
Tooling::ClangTool::run), and the changes are just reported on standard
output, if there are any to be made.

The tool can currently convert for loops that range over (1) statically
allocated arrays, and (2) Clang-style iterator-based loops (with begin and
end iterators defined). All loop variables need to be declared within the
loop's initialization step in order for it to be converted, though this
requirement can potentially be eliminated. I'm working on converting
iterator-based loops that call someContainer.end() on each iteration, since
they're probably the common case in many codebases.

Just for fun, I ran the tool over the 41 .cpp files in lib/Sema, and my
tool found 71 convertible loops in 17 files. There is plenty more work to
go, because it clearly missed some easy ones.

Any input or feedback is welcome!


On Thu, Jun 28, 2012 at 10:50 AM, Sam Panzer <panzer at google.com> wrote:

> I'm that intern :)
> -Sam
> On Wed, Jun 27, 2012 at 9:48 PM, John Wiegley <johnw at boostpro.com> wrote:
>> >>>>> Sam Panzer <panzer at google.com> writes:
>> > In particular, I am working on a tool to convert existing C++ for loops
>> to
>> > take advantage of the new C++11 range-based syntax. I can imagine
>> similar
>> > tools to replace const with constexpr, macro hacks with static_assert,
>> and
>> > potentially other common refactorings.
>> > Thoughts? Suggestions?
>> You really must watch this presentation, if you haven't already:
>>     http://www.youtube.com/watch?v=yuIOGfcOH0k
>> --
>> John Wiegley
>> BoostPro Computing
>> http://www.boostpro.com
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120628/7f5cf13b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: for-migration.patch
Type: application/octet-stream
Size: 50031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120628/7f5cf13b/attachment.obj>

More information about the cfe-dev mailing list