Example usage for org.objectweb.asm Opcodes I2S

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

Introduction

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

Prototype

int I2S

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

Click Source Link

Usage

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

License:Open Source License

/**
 * Create the Java code for a given cast expression. This will cause the resulting casted object reference to
 * be pushed onto the operand stack.//from   www .  ja  v  a  2 s  .c  o  m
 *  
 * @param castExpression the cast expression
 * @param context  
 * @return JavaTypeName the type of the result on the operand stack.        
 * @throws JavaGenerationException
 */
private static JavaTypeName encodeCastExpr(JavaExpression.CastExpression castExpression,
        GenerationContext context) throws JavaGenerationException {

    MethodVisitor mv = context.getMethodVisitor();

    final JavaTypeName expressionToCastType = encodeExpr(castExpression.getExpressionToCast(), context);
    final JavaTypeName castType = castExpression.getCastType();

    if (expressionToCastType.equals(castType)) {
        //no operation needed if the types are the same.
        return castType;
    }

    if (castType instanceof JavaTypeName.Reference) {
        //when the cast type is a object or array type, use the CHECKCAST instruction. This will fail bytecode verification if 
        //the expressionToCast type is a primitive type

        mv.visitTypeInsn(Opcodes.CHECKCAST, castType.getJVMInternalName());
        return castType;
    }

    //casting between primitive types.
    //There are 15 supported primitive conversions: I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S
    //Depending upon the expressionToCastType and castType, choose the appropriate instruction.

    final int conversionOpCode;
    switch (expressionToCastType.getTag()) {

    case JavaTypeName.VOID_TAG:
    case JavaTypeName.BOOLEAN_TAG:
        throw new JavaGenerationException("Unsupported primitive cast.");

    case JavaTypeName.BYTE_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.SHORT_TAG:
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            //no-op
            return castType;

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.I2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.I2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.I2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.SHORT_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.CHAR_TAG:
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            //no-op
            return castType;

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.I2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.I2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.I2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.CHAR_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.INT_TAG:
            //no-op
            return castType;

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.I2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.I2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.I2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.INT_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.I2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.I2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.I2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.LONG_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            mv.visitInsn(Opcodes.L2I);
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            mv.visitInsn(Opcodes.L2I);
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            mv.visitInsn(Opcodes.L2I);
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            conversionOpCode = Opcodes.L2I;
            break;

        case JavaTypeName.LONG_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.L2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.L2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.DOUBLE_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            mv.visitInsn(Opcodes.D2I);
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            mv.visitInsn(Opcodes.D2I);
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            mv.visitInsn(Opcodes.D2I);
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            conversionOpCode = Opcodes.D2I;
            break;

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.D2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.FLOAT_TAG:
            conversionOpCode = Opcodes.D2F;
            break;

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.FLOAT_TAG: {
        switch (castType.getTag()) {

        case JavaTypeName.VOID_TAG:
        case JavaTypeName.BOOLEAN_TAG:
            throw new JavaGenerationException("Unsupported primitive cast.");

        case JavaTypeName.BYTE_TAG:
            mv.visitInsn(Opcodes.F2I);
            conversionOpCode = Opcodes.I2B;
            break;

        case JavaTypeName.SHORT_TAG:
            mv.visitInsn(Opcodes.F2I);
            conversionOpCode = Opcodes.I2S;
            break;

        case JavaTypeName.CHAR_TAG:
            mv.visitInsn(Opcodes.F2I);
            conversionOpCode = Opcodes.I2C;
            break;

        case JavaTypeName.INT_TAG:
            conversionOpCode = Opcodes.F2I;
            break;

        case JavaTypeName.LONG_TAG:
            conversionOpCode = Opcodes.F2L;
            break;

        case JavaTypeName.DOUBLE_TAG:
            conversionOpCode = Opcodes.F2D;
            break;

        case JavaTypeName.FLOAT_TAG:
            //should be handled above as a no-op.
            throw new IllegalArgumentException();

        case JavaTypeName.ARRAY_TAG:
        case JavaTypeName.OBJECT_TAG:
            throw new JavaGenerationException("Cannot cast a primitive type to a reference type.");

        default: {
            throw new IllegalArgumentException();
        }
        }

        break;
    }

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
        throw new JavaGenerationException("Cannot cast a reference type to a primitive type.");

    default: {
        throw new IllegalArgumentException();
    }
    }

    mv.visitInsn(conversionOpCode);
    return castType;
}

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

License:Apache License

@Override
public void visitInsn(final int opcode) {
    // I F L D + BS
    switch (opcode) {
    case Opcodes.IALOAD:
        if (this.shouldMutate("Incremented (a++) integer array field")) {
            mv.visitInsn(Opcodes.DUP2); // Array and its index on stack, times two
            mv.visitInsn(opcode); // IALOAD
            mv.visitInsn(Opcodes.DUP_X2); // put the result of array[index] under [array ref] [index] [array[index]]
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);//from   w  w w.j a  va  2s .c o  m
            mv.visitInsn(Opcodes.IASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FALOAD:
        if (this.shouldMutate("Incremented (a++) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Incremented (a++) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Incremented (a++) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

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

    case Opcodes.SALOAD:
        if (this.shouldMutate("Incremented (a++) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            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.UOIMutator1.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("Incremented (a++) integer field " + name)) {
                // Assuming we have the reference to [this] on the stack
                mv.visitInsn(Opcodes.DUP); // dup [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.IADD); // stack = [this.field] [this] [this.field +1]
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }/*from   ww w  .  j  a v a2s . co  m*/
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (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.FADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (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.LADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (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.DADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (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.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (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.IADD);
                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("Incremented (a++) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (a++) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (a++) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (a++) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (a++) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (a++) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                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.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 {/* www  .j a v  a  2  s  .  com*/
            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 ava  2 s  . com*/
        }
        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.UOIMutator3.java

License:Apache License

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

            mv.visitInsn(Opcodes.DUP2);/*w ww  .  j  a v  a 2  s  . com*/
            // stack = [array] [index] [array] [index]

            mv.visitInsn(opcode);
            // stack = [array] [index] [array(index)]

            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            // 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("Incremented (++a) float array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitInsn(Opcodes.DUP_X2);
            mv.visitInsn(Opcodes.FASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LALOAD:
        if (this.shouldMutate("Incremented (++a) long array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LADD);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.LASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DALOAD:
        if (this.shouldMutate("Incremented (++a) double array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DADD);
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.DASTORE);
        } else {
            mv.visitInsn(opcode);
        }
        break;

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

    case Opcodes.SALOAD:
        if (this.shouldMutate("Incremented (++a) short array field")) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(opcode);
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IADD);
            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.UOIMutator3.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("Incremented (++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.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                // 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  w  w w  .j a  v a2 s .  c o  m
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                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("Incremented (++a) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                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 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);// w ww. j a  va2 s .  co 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;
            }/*w w w.jav  a 2 s  .  c o 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);
}

From source file:serianalyzer.JVMImpl.java

License:Open Source License

/**
 * @param opcode//from w ww.jav a 2 s. co m
 * @param s
 */
static void handleJVMInsn(int opcode, JVMStackState s) {
    BaseType o1;
    BaseType o2;
    BaseType o3;
    List<BaseType> l1;
    List<BaseType> l2;
    switch (opcode) {
    case Opcodes.NOP:
        break;

    case Opcodes.ARRAYLENGTH:
        o1 = s.pop();
        s.push(new BasicConstant(Type.INT_TYPE, 0, !(o1 != null && !o1.isTainted())));
        break;
    case Opcodes.ACONST_NULL:
        s.push(new BasicConstant(Type.VOID_TYPE, "<null>")); //$NON-NLS-1$
        break;
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
        s.push(new BasicConstant(Type.INT_TYPE, opcode - 3));
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        s.push(new BasicConstant(Type.LONG_TYPE, opcode - 9L));
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        s.push(new BasicConstant(Type.FLOAT_TYPE, opcode - 11f));
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        s.push(new BasicConstant(Type.DOUBLE_TYPE, opcode - 14d));
        break;
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        o1 = s.pop();
        o2 = s.pop();
        s.push(new BasicVariable(toType(opcode), "primitive array elem", //$NON-NLS-1$
                (o1 == null || o1.isTainted()) | (o2 == null || o2.isTainted())));
        break;

    case Opcodes.AALOAD:
        o1 = s.pop();
        o2 = s.pop();
        if (o1 != null && o2 instanceof SimpleType && ((SimpleType) o2).getType().toString().startsWith("[")) { //$NON-NLS-1$
            Type atype = Type.getType(((SimpleType) o2).getType().toString().substring(1));
            if (o2.getAlternativeTypes() != null && !o2.getAlternativeTypes().isEmpty()) {
                s.clear();
                break;
            }
            s.push(new BasicVariable(atype, "array elem " + atype, o1.isTainted() | o2.isTainted())); //$NON-NLS-1$
        } else {
            s.clear();
        }
        break;

    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
        s.pop(3);
        break;

    case Opcodes.POP2:
        s.pop();
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        s.pop();
        break;

    case Opcodes.DUP:
        if (!s.isEmpty()) {
            o1 = s.pop();
            s.push(o1);
            s.push(o1);
        }
        break;
    case Opcodes.DUP_X1:
        o1 = s.pop();
        o2 = s.pop();
        s.push(o1);
        s.push(o2);
        s.push(o1);
        break;
    case Opcodes.DUP_X2:
        o1 = s.pop();
        o2 = s.pop();
        o3 = s.pop();
        s.push(o1);
        s.push(o3);
        s.push(o2);
        s.push(o1);
        break;
    case Opcodes.DUP2:
        l1 = s.popWord();
        if (l1.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.pushWord(l1);
        }
        break;
    case Opcodes.DUP2_X1:
        l1 = s.popWord();
        o1 = s.pop();
        if (l1.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.push(o1);
            s.pushWord(l1);
        }
        break;
    case Opcodes.DUP2_X2:
        l1 = s.popWord();
        l2 = s.popWord();
        if (l1.isEmpty() || l2.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.pushWord(l2);
            s.pushWord(l1);
        }
        break;

    case Opcodes.SWAP:
        o1 = s.pop();
        o2 = s.pop();
        s.push(o1);
        s.push(o2);
        break;

    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
    case Opcodes.IAND:
    case Opcodes.LAND:
    case Opcodes.IOR:
    case Opcodes.LOR:
    case Opcodes.IXOR:
    case Opcodes.LXOR:
    case Opcodes.LCMP:
    case Opcodes.FCMPL:
    case Opcodes.FCMPG:
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        s.merge(2);
        break;

    case Opcodes.ISHL:
    case Opcodes.LSHL:
    case Opcodes.ISHR:
    case Opcodes.LSHR:
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        s.pop(); // amount
        // ignore value
        break;

    case Opcodes.INEG:
    case Opcodes.F2I:
    case Opcodes.D2I:
    case Opcodes.L2I:
        s.push(cast(s.pop(), Type.INT_TYPE));
        break;

    case Opcodes.LNEG:
    case Opcodes.I2L:
    case Opcodes.F2L:
    case Opcodes.D2L:
        s.push(cast(s.pop(), Type.LONG_TYPE));
        break;

    case Opcodes.FNEG:
    case Opcodes.I2F:
    case Opcodes.L2F:
    case Opcodes.D2F:
        s.push(cast(s.pop(), Type.FLOAT_TYPE));

    case Opcodes.DNEG:
    case Opcodes.I2D:
    case Opcodes.L2D:
    case Opcodes.F2D:
        s.push(cast(s.pop(), Type.DOUBLE_TYPE));

    case Opcodes.I2B:
        s.push(cast(s.pop(), Type.BYTE_TYPE));
        break;
    case Opcodes.I2C:
        s.push(cast(s.pop(), Type.CHAR_TYPE));
        break;
    case Opcodes.I2S:
        s.push(cast(s.pop(), Type.SHORT_TYPE));
        break;

    case Opcodes.ARETURN:
        s.clear();
        break;

    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if (log.isTraceEnabled()) {
            log.trace("Found return " + s.pop()); //$NON-NLS-1$
        }
        s.clear();
        break;

    case Opcodes.ATHROW:
        Object thrw = s.pop();
        log.trace("Found throw " + thrw); //$NON-NLS-1$
        s.clear();
        break;

    default:
        log.warn("Unsupported instruction code " + opcode); //$NON-NLS-1$
    }
}