InstructionList il = methodGen.getInstructionList();
// next element will hold a handle to the beginning of next
// When/Otherwise if test on current When fails
BranchHandle nextElement = null;
Vector exitHandles = new Vector();
InstructionHandle exit = null;
Enumeration whens = whenElements.elements();
while (whens.hasMoreElements()) {
final When when = (When)whens.nextElement();
final Expression test = when.getTest();
InstructionHandle truec = il.getEnd();
if (nextElement != null)
nextElement.setTarget(il.append(NOP));
test.translateDesynthesized(classGen, methodGen);
if (test instanceof FunctionCall) {
FunctionCall call = (FunctionCall)test;
try {
Type type = call.typeCheck(getParser().getSymbolTable());
if (type != Type.Boolean) {
test._falseList.add(il.append(new IFEQ(null)));
}
}
catch (TypeCheckError e) {
// handled later!
}
}
// remember end of condition
truec = il.getEnd();
// The When object should be ignored completely in case it tests
// for the support of a non-available element
if (!when.ignore()) when.translateContents(classGen, methodGen);
// goto exit after executing the body of when
exitHandles.addElement(il.append(new GOTO(null)));
if (whens.hasMoreElements() || otherwise != null) {
nextElement = il.append(new GOTO(null));
test.backPatchFalseList(nextElement);
}
else
test.backPatchFalseList(exit = il.append(NOP));
test.backPatchTrueList(truec.getNext());
}
// Translate any <xsl:otherwise> element
if (otherwise != null) {
nextElement.setTarget(il.append(NOP));
otherwise.translateContents(classGen, methodGen);
exit = il.append(NOP);
}
// now that end is known set targets of exit gotos
Enumeration exitGotos = exitHandles.elements();
while (exitGotos.hasMoreElements()) {
BranchHandle gotoExit = (BranchHandle)exitGotos.nextElement();
gotoExit.setTarget(exit);
}
}