LabelNode matchLabel,
LabelNode noMatchLabel,
Collection<ByteCodeNode> testValues,
boolean checkForNulls)
{
Variable caseWasNull = null;
if (checkForNulls) {
caseWasNull = context.createTempVariable(boolean.class);
}
Block caseBlock = new Block(context)
.visitLabel(caseLabel);
if (checkForNulls) {
caseBlock.putVariable(caseWasNull.getLocalVariableDefinition(), false);
}
LabelNode elseLabel = new LabelNode("else");
Block elseBlock = new Block(context)
.visitLabel(elseLabel);
if (checkForNulls) {
elseBlock.getVariable(caseWasNull.getLocalVariableDefinition())
.putVariable("wasNull");
}
elseBlock.gotoLabel(noMatchLabel);
FunctionBinding equalsFunction = generatorContext.getBootstrapBinder().bindOperator(
OperatorType.EQUAL,
generatorContext.generateGetSession(),
ImmutableList.<ByteCodeNode>of(NOP, NOP),
ImmutableList.of(type, type));
ByteCodeNode elseNode = elseBlock;
for (ByteCodeNode testNode : testValues) {
LabelNode testLabel = new LabelNode("test");
IfStatement.IfStatementBuilder test = ifStatementBuilder(context);
Block condition = new Block(context)
.visitLabel(testLabel)
.dup(type.getJavaType())
.append(testNode);
if (checkForNulls) {
condition.getVariable("wasNull")
.putVariable(caseWasNull.getLocalVariableDefinition())
.append(ifWasNullPopAndGoto(context, elseLabel, void.class, type.getJavaType(), type.getJavaType()));
}
condition.invokeDynamic(equalsFunction.getName(), equalsFunction.getCallSite().type(), equalsFunction.getBindingId());
test.condition(condition);