String label = getLabel(node);
// get address of each part
int bodyAddress = fInstructions.getEnd();
Instruction body = fInstructions.getInstruction(bodyAddress);
int conditionAddress = bodyAddress - body.getSize();
Instruction condition = fInstructions.getInstruction(conditionAddress);
// add the conditionnalJump
ConditionalJump conditionalJump = new ConditionalJump(false);
fInstructions.insert(conditionalJump, conditionAddress + 1);
// add the jump
Jump jump = new Jump();
fInstructions.add(jump);
// set jump offsets
conditionalJump.setOffset(body.getSize() + 1);
jump.setOffset(-(condition.getSize() + body.getSize() + 2));
// for each pending break or continue instruction which are related to
// this loop, set the offset of the corresponding jump.
for (Iterator<CompleteInstruction> iter = fCompleteInstructions.iterator(); iter.hasNext();) {
CompleteInstruction instruction = iter.next();
Jump jumpInstruction = instruction.fInstruction;
int instructionAddress = fInstructions.indexOf(jumpInstruction);
if (instructionAddress > conditionAddress
&& (instruction.fLabel == null || instruction.fLabel
.equals(label))) {
iter.remove();
if (instruction.fIsBreak) {
// jump to the instruction after the last jump
jumpInstruction
.setOffset((bodyAddress - instructionAddress) + 2);
} else {
// jump to the first instruction of the condition
jumpInstruction.setOffset((conditionAddress - condition
.getSize()) - instructionAddress);
}
}
}