Next: return and throw statements Up: Applying the simplify algorithm Previous: do statements   Contents   Index

### for statements

The for statement is quite complicated. Consider

where is either a single declaration or a (possibly empty) comma-separated list of statement expressions, is an expression, is a (possibly empty) comma-separated list of statement expressions, and is a statement.

Suppose is the local variable declaration:

where definitions are as in the section beginning page . Apply the transformation described in that section to the statement  ;''. If this transformation does not produce any changes, and is not a multiarray type, the transformed version of the for construct is:

where , and will be defined below. Otherwise, if the transformed version of  ;'' is , we may take the transformed version of the for construct to be:

Suppose, alternatively, that is the possibly-empty list of expressions:

where . Again, apply the simplify algorithm to each expression in this list, and assume now that and are the results of applying the algorithm to . If the simplify algorithm doesn't change any of the expressions, and none of the are multiarrays, the transformed version of the for construct is again:

Otherwise, we may take the transformed version of the for construct to be:

Now we need to define , and . We also introduce the symbols and to stand for possibly-empty statements added at the start and end of the loop body.

Apply the simplify algorithm to , and let and be the results. If the algorithm doesn't change , then

and the statement is empty. If the algorithm does change , then

and the statement is:

Assume is the possibly-empty list of expressions:

Apply the simplify algorithm to all these expressions. If the algorithm doesn't change any , and none of the is a multiarray, then

and the statement is empty. If it does change some , or any is a multiarray, then is empty and and we will take the statement to be:

where now and are the results of applying the algorithm to .

Finally, if and are both empty, the value of is just , the pre-translated version of . Otherwise the block has the form

Next: return and throw statements Up: Applying the simplify algorithm Previous: do statements   Contents   Index
Bryan Carpenter 2003-04-15