|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface EnhancedForConditionInstruction
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
.
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.TACInstruction |
---|
transfer, transfer |
Method Detail |
---|
ASTNode getNode()
EnhancedForStatement
. Usually,
one instruction exists per AST node, but can be more
when AST nodes are desugared, such as for post-increment.
getNode
in interface TACInstruction
TACInstruction.getNode()
Variable getIteratedOperand()
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()
.
Iterable
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |