// the CASE instruction
Label endLabel = m.getNewLabel();
boolean hasElse = (caseNode.getElseNode() != null);
Label elseLabel = hasElse ? m.getNewLabel() : null;
Variable result = m.getNewTemporaryVariable();
CaseInstr caseInstr = new CaseInstr(result, value, endLabel);
m.addInstr(caseInstr);
// lists to aggregate variables and bodies for whens
List<Operand> variables = new ArrayList<Operand>();
List<Label> labels = new ArrayList<Label>();
Map<Label, Node> bodies = new HashMap<Label, Node>();
// build each "when"
for (Node aCase : caseNode.getCases().childNodes()) {
WhenNode whenNode = (WhenNode)aCase;
Label bodyLabel = m.getNewLabel();
if (whenNode.getExpressionNodes() instanceof ListNode) {
// multiple conditions for when
for (Node expression : ((ListNode)whenNode.getExpressionNodes()).childNodes()) {
Variable eqqResult = m.getNewTemporaryVariable();
variables.add(eqqResult);
labels.add(bodyLabel);
m.addInstr(new EQQInstr(eqqResult, build(expression, m), value));
m.addInstr(new BEQInstr(eqqResult, BooleanLiteral.TRUE, bodyLabel));
}
} else {
Variable eqqResult = m.getNewTemporaryVariable();
variables.add(eqqResult);
labels.add(bodyLabel);
m.addInstr(new EQQInstr(eqqResult, build(whenNode.getExpressionNodes(), m), value));