switch (args[i]) { case Literal(Object val): if ((maxTypeIdx <= intTypeIdx) && ((Number)val).intValue() == 0) { isIntZero = true; if (i == 0) prim = prim.swap();
if (maxTypeIdx <= intTypeIdx) { switch (args[i]) { case Literal(Object val): int intVal; if (val instanceof Number) intVal = ((Number)val).intValue(); else if (val instanceof Character) intVal = ((Character)val).charValue(); else throw Debug.abort("unknown literal", val); if (intVal == 0) { isIntZero = true; if (i == 0) prim = prim.swap(); }
    protected void genCompPrim(Primitive prim,                               Tree[] args,                               byte resType,                               byte expectedType,                               InstructionHandle target,                               boolean when) {        byte maxType = getMaxType(args);        int maxTypeIdx = getTypeIndex(maxType);        int intTypeIdx = getTypeIndex(Type.INT);        boolean intCompareWithZero = false;        for (int i = 0; i < args.length; ++i) {            boolean isIntZero = false;            switch (args[i]) {            case Literal(Object val):                if ((maxTypeIdx <= intTypeIdx) && ((Number)val).intValue() == 0) {                    isIntZero = true;                    if (i == 0) prim = prim.swap();                }            }            if (intCompareWithZero || !isIntZero)                gen(args[i], maxType);            intCompareWithZero |= isIntZero;        }        if (maxType == cst.T_OBJECT) {            assert prim == Primitive.EQ || prim == Primitive.NE;            LocalVariableGen lGen =                currMethod.addLocalVariable("temp" + tempCounter++,                                            Type.OBJECT,                                            currIL.getEnd(),                                            null);            currIL.append(new ASTORE(lGen.getIndex()));            currIL.append(ic.DUP);            BranchInstruction ifNonNull = new IFNONNULL(null);            currIL.append(ifNonNull);            currIL.append(ic.POP);            currIL.append(new ALOAD(lGen.getIndex()));            if (when ^ (prim != Primitive.EQ))                currIL.append(new IFNULL(target));            else                currIL.append(new IFNONNULL(target));            BranchInstruction gotoAfter = new GOTO(null);            currIL.append(gotoAfter);            InstructionHandle nonNullHandle =                currIL.append(new ALOAD(lGen.getIndex()));            ifNonNull.setTarget(nonNullHandle);            lGen.setEnd(nonNullHandle);            String equalsSig =                Type.getMethodSignature(Type.BOOLEAN,                                        new Type[] { Type.OBJECT });            int equalsIndex =                currPool.addMethodref(JAVA_LANG_OBJECT, "equals", equalsSig);            currIL.append(new INVOKEVIRTUAL(equalsIndex));            if (when ^ (prim != Primitive.EQ))                currIL.append(new IFNE(target));            else                currIL.append(new IFEQ(target));            gotoAfter.setTarget(currIL.append(ic.NOP));        } else if (maxTypeIdx <= intTypeIdx && !intCompareWithZero) {            switch (maybeNegatedPrim(prim, !when)) {            case LT: currIL.append(new IF_ICMPLT(target)); break;            case LE: currIL.append(new IF_ICMPLE(target)); break;            case EQ: currIL.append(new IF_ICMPEQ(target)); break;            case NE: currIL.append(new IF_ICMPNE(target)); break;            case GE: currIL.append(new IF_ICMPGE(target)); break;            case GT: currIL.append(new IF_ICMPGT(target)); break;            default: throw global.fail("unknown primitive " + prim);            }        } else {            switch (maxType) {            case cst.T_LONG:   currIL.append(ic.LCMP);  break;            case cst.T_FLOAT:  currIL.append(ic.FCMPG); break;            case cst.T_DOUBLE: currIL.append(ic.DCMPG); break;            default:                ;               // do nothing (int comparison with 0)            }            switch (maybeNegatedPrim(prim, !when)) {            case LT: currIL.append(new IFLT(target)); break;            case LE: currIL.append(new IFLE(target)); break;            case EQ: currIL.append(new IFEQ(target)); break;            case NE: currIL.append(new IFNE(target)); break;            case GE: currIL.append(new IFGE(target)); break;            case GT: currIL.append(new IFGT(target)); break;            default: throw global.fail("unknown primitive " + prim);            }        }    }