}
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp[] args = call.getArgs();
final List<Calc> calcList = new ArrayList<Calc>();
final Calc valueCalc =
compiler.compileScalar(args[0], true);
calcList.add(valueCalc);
final int matchCount = (args.length - 1) / 2;
final Calc[] matchCalcs = new Calc[matchCount];
final Calc[] exprCalcs = new Calc[matchCount];
for (int i = 0, j = 1; i < exprCalcs.length; i++) {
matchCalcs[i] = compiler.compileScalar(args[j++], true);
calcList.add(matchCalcs[i]);
exprCalcs[i] = compiler.compile(args[j++]);
calcList.add(exprCalcs[i]);
}
final Calc defaultCalc =
args.length % 2 == 0
? compiler.compile(args[args.length - 1])
: ConstantCalc.constantNull(call.getType());
calcList.add(defaultCalc);
final Calc[] calcs = calcList.toArray(new Calc[calcList.size()]);
return new GenericCalc(call) {
public Object evaluate(Evaluator evaluator) {
Object value = valueCalc.evaluate(evaluator);
for (int i = 0; i < matchCalcs.length; i++) {
Object match = matchCalcs[i].evaluate(evaluator);
if (match.equals(value)) {
return exprCalcs[i].evaluate(evaluator);
}
}
return defaultCalc.evaluate(evaluator);
}
public Calc[] getCalcs() {
return calcs;
}