@Override
public HoldingContainer visitIfExpression(IfExpression ifExpr, CodeGenerator<?> generator) throws RuntimeException {
JBlock local = generator.getEvalBlock();
HoldingContainer output = generator.declare(ifExpr.getMajorType());
JConditional jc = null;
JBlock conditionalBlock = new JBlock(false, false);
for (IfCondition c : ifExpr.conditions) {
HoldingContainer HoldingContainer = c.condition.accept(this, generator);
if (jc == null) {
if (HoldingContainer.isOptional()) {
jc = conditionalBlock._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
} else {
jc = conditionalBlock._if(HoldingContainer.getValue());
}
} else {
if (HoldingContainer.isOptional()) {
jc = jc._else()._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
} else {
jc = jc._else()._if(HoldingContainer.getValue());
}
}
HoldingContainer thenExpr = c.expression.accept(this, generator);
if (thenExpr.isOptional()) {
JConditional newCond = jc._then()._if(thenExpr.getIsSet());
JBlock b = newCond._then();
b.assign(output.getValue(), thenExpr.getValue());
b.assign(output.getIsSet(), thenExpr.getIsSet());
} else {
jc._then().assign(output.getValue(), thenExpr.getValue());
}
}
HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
if (elseExpr.isOptional()) {
JConditional newCond = jc._else()._if(elseExpr.getIsSet());
JBlock b = newCond._then();
b.assign(output.getValue(), elseExpr.getValue());
b.assign(output.getIsSet(), elseExpr.getIsSet());
} else {
jc._else().assign(output.getValue(), elseExpr.getValue());
}
local.add(conditionalBlock);
return output;
}