edu.cmu.cs.crystal.tac.model
Interface EnhancedForConditionInstruction

All Superinterfaces:
TACInstruction

public interface EnhancedForConditionInstruction
extends TACInstruction

Instruction representing the "has next" test at the top of a Java 5 enhanced for loop.

List strings = ...; for(String s : strings) ...;

Every iteration of an extended for loop such as the one above begins with an implicit test whether the iterated-over Iterable has another element. This implicit test is represented with this instruction.

Notice that the expression that evaluates to the iterated-over is not represented here and instead is represented with separate instructions. However, getIteratedOperand() returns the variable representing the result of that evaluation. (This arrangement models that the evaluation of the iterated-over Iterable is not part of the loop.)

The local variable being declared as also not represented with this instruction and instead is represented with a separate SourceVariableDeclaration. (This latter choice models that the declared variable is only available inside the loop.)

We chose to preserve enhanced for loops with this instruction instead of desugaring it into a regular for loop over a Iterator for practical reasons (the Eclipse AST does not do this) and to allow analyses to benefit from the stylized iteration that encoded with enhanced for that, e.g., does not permit modifications to the iterated-over Iterable.

Since:
5/27/2008
Author:
Kevin Bierhoff
See Also:
Iterator.hasNext(), EnhancedForStatement

Method Summary
 Variable getIteratedOperand()
          Returns the variable of the iterated-over Iterable.
 ASTNode getNode()
          Returns the node this instruction is for.
 
Methods inherited from interface edu.cmu.cs.crystal.tac.model.TACInstruction
transfer, transfer
 

Method Detail

getNode

ASTNode getNode()
Returns the node this instruction is for. Should be of type EnhancedForStatement. Usually, one instruction exists per AST node, but can be more when AST nodes are desugared, such as for post-increment.

Specified by:
getNode in interface TACInstruction
Returns:
the node this instruction is for.
See Also:
TACInstruction.getNode()

getIteratedOperand

Variable getIteratedOperand()
Returns the variable of the iterated-over Iterable. Notice that an enhanced for loop does not actually call a method on that Iterable and instead creates a Iterator on which it calls Iterator.hasNext().

Returns:
The variable of the iterated-over Iterable.