Expression trueAlt = null;
Expression falseAlt = null;
Expression defaultAlt = null;
for (int i = 0; i < alts.length; ++i) {
SwitchAlt switchAlt = alts[i];
if (switchAlt.isDefaultAlt()) {
defaultAlt = switchAlt.getAltExpr();
} else {
if (switchAlt.getAltTags().size() > 1) {
// (True | False) - ie. always.
return genS_R(switchAlt.getAltExpr(), variableContext);
}
Object altTag = switchAlt.getFirstAltTag();
if (altTag instanceof DataConstructor) {
// This is either Prelude.True or Prelude.False
DataConstructor dc = (DataConstructor)altTag;
if (dc.getName().equals(CAL_Prelude.DataConstructors.True)) {
altTag = Boolean.TRUE;
} else
if (dc.getName().equals(CAL_Prelude.DataConstructors.False)) {
altTag = Boolean.FALSE;
} else {
// We should never get here.
throw new CodeGenerationException ("Trying to generate if-then-else from data constructor: " + dc.getName().getQualifiedName());
}
}
// Tag is a boolean.
if (((Boolean)altTag).booleanValue()) {
trueAlt = switchAlt.getAltExpr();
} else {
falseAlt = switchAlt.getAltExpr();
}
}
}
if (trueAlt == null) {