}
public static void createSwitchStatement(
EvaluationContext context, Expr cond, Collection<Statement> statements, InstList l) throws CompilerException {
List<CaseLabel> labels = new ArrayList<CaseLabel>() ;
Mark theEnd = new Mark() ;
EvaluationContext newContext = context.setBreak(theEnd) ;
createConvert(newContext, cond, TypeName.INT,l) ;
boolean deffound = false ;
IdentityHashMap<CaseStatement, Mark> marks = new IdentityHashMap<CaseStatement, Mark>() ;
for(Statement s: statements) {
if (s instanceof CaseStatement) {
Mark mark = new Mark() ;
CaseStatement cs = (CaseStatement)s ;
final Expr e = cs.e;
if (e == null) {
labels.add(new CaseLabel(null,mark)) ;
deffound = true ;
}
else {
ConstObj constobj = newContext.getConst(e) ;
if (constobj == null) {
throw new NonConstCase() ;
}
Integer label = getIntValue(constobj) ;
labels.add(new CaseLabel(label,mark)) ;
}
marks.put(cs,mark) ;
}
}
if (!deffound) {
labels.add(new CaseLabel(null,theEnd)) ;
}
l.add(new LookupSwitch(labels)) ;
for(Statement s: statements) {
if (s instanceof CaseStatement) {
CaseStatement cs = (CaseStatement)s ;
Mark mark = marks.get(cs) ;
l.add(new Nop(mark)) ;
}
else {
newContext.compile(s,l) ;
}