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.<div>
<br></div><div>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. <div>
<br></div><div><div>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.</div>
<div><br></div><div>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.<br></div><div><br></div><div>Thoughts?</div><div><br></div><div>
-Sam</div><div><br></div></div></div>