[PATCH] For loop migration tool (round 1)

Here are three patches which constitute most of the work needed for the for-loop migration tool. The first contains the contents of the tutorial from earlier this week, with extra comments and rebased into clang/tools/extra/. The second patch fixes most of the correctness assumptions that the naive tool makes (e.g. conflicting edits, name conflicts), and the third adds some command-line flags along with a trick for eliding a variable declared as a reference to the array access.

Together, they provide a nearly complete converter for array-based loops - the three optional features I didn’t rebase into the patches involve using an explicit type rather than auto, adding const when possible, and making the loop variable a non-reference type for non-aggregate types if possible.

There is one potentially problematic assumption that I haven’t fixed yet: the array expression is assumed not to change, as this becomes difficult to verify when the code iterates over a compound expression such as graph.nodes->getInputs(). In most cases, the loop will probably be convertible if it passes all other checks, so I intend to offer a flag that tells the loop converter whether or not to make these usually-okay changes.

I also have two more patches in the works for next week, which add support for iterator-based loops and loops over array-like containers.



loop-converter.patch (17.3 KB)

loop-converter-2.patch (30.8 KB)

loop-converter-3.patch (12.7 KB)