Example usage for org.objectweb.asm Opcodes LSUB

List of usage examples for org.objectweb.asm Opcodes LSUB

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes LSUB.

Prototype

int LSUB

To view the source code for org.objectweb.asm Opcodes LSUB.

Click Source Link

Usage

From source file:org.jboss.byteman.rule.expression.ArithmeticExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    int currentStack = compileContext.getStackCount();
    int expectedStack = 0;
    Expression operand0 = getOperand(0);
    Expression operand1 = getOperand(1);
    Type type0 = operand0.getType();
    Type type1 = operand1.getType();
    // compile lhs -- it adds 1 or 2 to the stack height
    operand0.compile(mv, compileContext);
    // do any required type conversion
    compileTypeConversion(type0, type, mv, compileContext);
    // compile rhs -- it adds 1 or 2 to the stack height
    operand1.compile(mv, compileContext);
    // do any required type conversion
    compileTypeConversion(type1, type, mv, compileContext);

    try {//from  w ww . j  ava 2s .  c o m
        // n.b. be careful with characters here
        if (type == type.B || type == type.S || type == type.C || type == type.I) {
            // TODO we should probably only respect the byte, short and char types for + and -
            // TODO also need to decide how to handle divide by zero

            expectedStack = 1;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.IMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.IDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.IADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.ISUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.IREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // now coerce back to appropriate type
            if (type == type.B) {
                mv.visitInsn(Opcodes.I2B);
            } else if (type == type.S) {
                mv.visitInsn(Opcodes.I2S);
            } else if (type == type.C) {
                mv.visitInsn(Opcodes.I2C);
            } // else if (type == type.I) { do nothing }
              // ok, we popped two bytes but added one
            compileContext.addStackCount(-1);
        } else if (type == type.J) {

            expectedStack = 2;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.LMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.LDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.LADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.LSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.LREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped four bytes but added two
            compileContext.addStackCount(-2);
        } else if (type == type.F) {

            expectedStack = 1;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.FMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.FDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.FADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.FSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.FREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped two bytes but added one
            compileContext.addStackCount(-1);
        } else if (type == type.D) {

            expectedStack = 2;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.DMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.DDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.DADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.DSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.DREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped four bytes but added two
            compileContext.addStackCount(-2);
        } else {
            throw new CompileException(
                    "ArithmeticExpression.compile : unexpected result type " + type.getName());
        }
    } catch (CompileException e) {
        throw e;
    } catch (Exception e) {
        throw new CompileException("ArithmeticExpression.compile : unexpected exception for operation " + token
                + getPos() + " in rule " + rule.getName(), e);
    }

    // check stack heights
    if (compileContext.getStackCount() != currentStack + expectedStack) {
        throw new CompileException("ArithmeticExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + (currentStack + expectedStack));
    }
}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

private static final int getBinaryLongOpCode(String op) {
    switch (op.charAt(0)) {
    case '-':
        return Opcodes.LSUB;
    case '+':
        return Opcodes.LADD;
    case '%':
        return Opcodes.LREM;
    case '*':
        return Opcodes.LMUL;
    case '/':
        return Opcodes.LDIV;
    case '&':
        return Opcodes.LAND;
    case '|':
        return Opcodes.LOR;
    case '^':
        return Opcodes.LXOR;
    case '<':
        return Opcodes.LSHL;
    case '>':
        return op.equals(">>>") ? Opcodes.LUSHR : Opcodes.LSHR;
    default://from  w  w w . jav  a2  s  .  co m
        throw new IllegalArgumentException("Invalid operand " + op);
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.AODMutator1.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:

    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            mv.visitInsn(Opcodes.POP);/*from   w  w w .  ja va2s  . co  m*/
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:

    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            mv.visitInsn(Opcodes.POP2);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.AODMutator2.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.INT_TYPE);
            mv.visitVarInsn(Opcodes.ISTORE, storage);
            mv.visitInsn(Opcodes.POP);//  w  w w.j av  a 2  s . com
            mv.visitVarInsn(Opcodes.ILOAD, storage);
            /*
             * Alternative : mv.visitInsn(Opcodes.SWAP);
             * mv.visitInsn(Opcodes.POP);
             * mv.visitVarInsn(Opcodes.ILOAD,storage);
             */
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.FLOAT_TYPE);
            mv.visitVarInsn(Opcodes.FSTORE, storage);
            mv.visitInsn(Opcodes.POP);
            mv.visitVarInsn(Opcodes.FLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.LONG_TYPE);
            mv.visitVarInsn(Opcodes.LSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.LLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.DOUBLE_TYPE);
            mv.visitVarInsn(Opcodes.DSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.DLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    mv.visitVarInsn(opcode, var);
    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Decremented (a--) integer local variable number " + var)) {
            mv.visitIincInsn(var, -1);
        }/*  w w  w  .  jav a 2 s.  c  o m*/
        break;
    case Opcodes.FLOAD:
        if (this.shouldMutate("Decremented (a--) float local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        break;
    case Opcodes.LLOAD:
        if (this.shouldMutate("Decremented (a--) long local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        break;
    case Opcodes.DLOAD:
        if (this.shouldMutate("Decremented (a--) double local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        break;
    default:
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Decremented (a--) integer array field")) {
            // stack = [array] [index] , wanted to perform an IALOAD
            mv.visitInsn(Opcodes.DUP2); // stack = [array] [index] [array] [index]
            mv.visitInsn(opcode); // stack = [array] [index] [array(index)]
            mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)] [array] [index] [array(index)]
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB); // stack = [array(index)] [array] [index] [array(index)-1]
            mv.visitInsn(Opcodes.IASTORE);
        } else {//from w  ww  . ja  v  a2 s . c  o m
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FALOAD:
        if (this.shouldMutate("Decremented (a--) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Decremented (a--) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Decremented (a--) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.BALOAD:
        if (this.shouldMutate("Decremented (a--) byte array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.BASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.SALOAD:
        if (this.shouldMutate("Decremented (a--) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2S);
            mv.visitInsn(Opcodes.SASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) integer field " + name)) {
                // stack  = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field] [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//from   w  ww  .  j ava2 s .c o  m
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this.sfield]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this.sfield] [this.sfield]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                // stack = [this.sfield] [this.sfield -1]

                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Decremented (--a) integer local variable number " + var)) {
            mv.visitIincInsn(var, -1);
        }//from  ww w  . ja  v a 2  s .  co m
        mv.visitVarInsn(opcode, var);

        break;

    case Opcodes.FLOAD:
        if (this.shouldMutate("Decremented (--a) float local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        mv.visitVarInsn(opcode, var);

        break;

    case Opcodes.LLOAD:
        if (this.shouldMutate("Decremented (--a) long local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        mv.visitVarInsn(opcode, var);
        break;

    case Opcodes.DLOAD:
        if (this.shouldMutate("Decremented (--a) double local variable number " + var)) {
            mv.visitVarInsn(opcode, var);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        mv.visitVarInsn(opcode, var);
        break;

    default:
        mv.visitVarInsn(opcode, var);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.java

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Decremented (--a) integer array field")) {
            // stack = [array] [index] 

            mv.visitInsn(Opcodes.DUP2);/*from www  .  j  a  v a  2s . c  o  m*/
            // stack = [array] [index] [array] [index]

            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            // stack = [array] [index] [array(index)-1]

            mv.visitInsn(Opcodes.DUP_X2);
            // stack = [array(index)-1] [array] [index] [array(index)-1]

            mv.visitInsn(Opcodes.IASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.FALOAD:
        if (this.shouldMutate("Decremented (--a) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.LALOAD:
        if (this.shouldMutate("Decremented (--a) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.DALOAD:
        if (this.shouldMutate("Decremented (--a) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.BALOAD:
        if (this.shouldMutate("Decremented (--a) byte array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2B);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.BASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    case Opcodes.SALOAD:
        if (this.shouldMutate("Decremented (--a) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.ISUB);
            mv.visitInsn(Opcodes.I2S);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.SASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

    default:
        mv.visitInsn(opcode);
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {

    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (--a) integer field")) {
                // stack = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                // stack = [this] [this.field -1]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field -1] [this] [this.field -1]

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//from  ww  w .j  a v  a  2s  .co m
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) float field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) long field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) short field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (--a) static integer field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) static float field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) static long field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) static double field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) static byte field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) static short field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}