Search in sources :

Example 1 with IincInsnNode

use of org.objectweb.asm.tree.IincInsnNode in project spring-loaded by spring-projects.

the class TypeDiffComputer method sameIincInsn.

private static boolean sameIincInsn(AbstractInsnNode o, AbstractInsnNode n) {
    IincInsnNode oi = (IincInsnNode) o;
    if (!(n instanceof IincInsnNode)) {
        return false;
    }
    IincInsnNode ni = (IincInsnNode) n;
    return oi.var == ni.var && oi.incr == ni.incr;
}
Also used : IincInsnNode(org.objectweb.asm.tree.IincInsnNode)

Example 2 with IincInsnNode

use of org.objectweb.asm.tree.IincInsnNode in project enumerable by hraberg.

the class ExpressionInterpreter method unaryOperation.

public Value unaryOperation(final AbstractInsnNode insn, final Value value) throws AnalyzerException {
    ExpressionValue expressionValue = (ExpressionValue) value;
    switch(insn.getOpcode()) {
        case INEG:
            return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.negative));
        case IINC:
            IincInsnNode node = (IincInsnNode) insn;
            NameExpr nameExpr = new NameExpr(getLocalVariable(node.var).name);
            if (node.incr == 1)
                iinc = new UnaryExpr(nameExpr, UnaryExpr.Operator.posIncrement);
            if (node.incr == -1)
                iinc = new UnaryExpr(nameExpr, UnaryExpr.Operator.posDecrement);
            if (node.incr > 1)
                iincAssign = new AssignExpr(nameExpr, new IntegerLiteralExpr(node.incr + ""), AssignExpr.Operator.plus);
            if (node.incr < -1)
                iincAssign = new AssignExpr(nameExpr, new IntegerLiteralExpr(-node.incr + ""), AssignExpr.Operator.minus);
            return value;
        case L2I:
        case F2I:
        case D2I:
            return new ExpressionValue(PRIMITIVE_INT, new CastExpr(PRIMITIVE_INT, expressionValue.expression));
        case I2B:
            return new ExpressionValue(PRIMITIVE_BYTE, new CastExpr(PRIMITIVE_BYTE, expressionValue.expression));
        case I2C:
            return new ExpressionValue(PRIMITIVE_CHAR, new CastExpr(PRIMITIVE_CHAR, expressionValue.expression));
        case I2S:
            return new ExpressionValue(PRIMITIVE_SHORT, new CastExpr(PRIMITIVE_SHORT, expressionValue.expression));
        case FNEG:
            return new ExpressionValue(PRIMITIVE_FLOAT, new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.negative));
        case I2F:
        case L2F:
        case D2F:
            return new ExpressionValue(PRIMITIVE_FLOAT, new CastExpr(PRIMITIVE_FLOAT, expressionValue.expression));
        case LNEG:
            return new ExpressionValue(PRIMITIVE_LONG, new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.negative));
        case I2L:
        case F2L:
        case D2L:
            return new ExpressionValue(PRIMITIVE_LONG, new CastExpr(PRIMITIVE_LONG, expressionValue.expression));
        case DNEG:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.negative));
        case I2D:
        case L2D:
        case F2D:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new CastExpr(PRIMITIVE_DOUBLE, expressionValue.expression));
        case IFEQ:
            if (conditional != null) {
                if (conditional.getCondition() instanceof BinaryExpr && cmpConditional) {
                    ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.notEquals);
                    cmpConditional = false;
                } else {
                    handleNestedConditional(expressionValue.expression);
                }
            } else {
                conditional = new ConditionalExpr(expressionValue.expression, null, null);
            }
            return null;
        case IFNE:
            if (conditional != null) {
                if (conditional.getCondition() instanceof BinaryExpr && cmpConditional) {
                    ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.equals);
                    cmpConditional = false;
                } else {
                    handleNestedConditional(new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.not));
                }
            } else {
                conditional = new ConditionalExpr(new UnaryExpr(expressionValue.expression, UnaryExpr.Operator.not), null, null);
            }
            return null;
        case IFGT:
            ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.lessEquals);
            cmpConditional = false;
            return null;
        case IFLE:
            ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.greater);
            cmpConditional = false;
            return null;
        case IFLT:
            ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.greaterEquals);
            cmpConditional = false;
            return null;
        case IFGE:
            ((BinaryExpr) conditional.getCondition()).setOperator(BinaryExpr.Operator.less);
            cmpConditional = false;
            return null;
        case TABLESWITCH:
        case LOOKUPSWITCH:
            throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
        case IRETURN:
        case LRETURN:
        case FRETURN:
        case DRETURN:
        case ARETURN:
            return null;
        case PUTSTATIC:
            FieldInsnNode fieldNode = (FieldInsnNode) insn;
            ExpressionValue putField = (ExpressionValue) newValue(getType(fieldNode.desc));
            putField.expression = new AssignExpr(new FieldAccessExpr(new NameExpr(removeJavaLang(getObjectType(fieldNode.owner).getClassName())), fieldNode.name), expressionValue.expression, AssignExpr.Operator.assign);
            assign = putField;
            return null;
        case GETFIELD:
            fieldNode = (FieldInsnNode) insn;
            ExpressionValue getField = (ExpressionValue) newValue(Type.getType(fieldNode.desc));
            getField.expression = new FieldAccessExpr(expressionValue.expression, fieldNode.name);
            return getField;
        case NEWARRAY:
            PrimitiveType type;
            switch(((IntInsnNode) insn).operand) {
                case T_BOOLEAN:
                    type = PRIMITIVE_BOOLEAN;
                    break;
                case T_CHAR:
                    type = PRIMITIVE_CHAR;
                    break;
                case T_BYTE:
                    type = PRIMITIVE_BYTE;
                    break;
                case T_SHORT:
                    type = PRIMITIVE_SHORT;
                    break;
                case T_INT:
                    type = PRIMITIVE_INT;
                    break;
                case T_FLOAT:
                    type = PRIMITIVE_FLOAT;
                    break;
                case T_DOUBLE:
                    type = PRIMITIVE_DOUBLE;
                    break;
                case T_LONG:
                    type = PRIMITIVE_LONG;
                    break;
                default:
                    throw new AnalyzerException(insn, "Invalid array type");
            }
            ArrayList<Expression> dimensions = new ArrayList<Expression>();
            dimensions.add(expressionValue.expression);
            return new ExpressionValue(new ReferenceType(type, 1), new ArrayCreationExpr(type, dimensions, 0));
        case ANEWARRAY:
            ExpressionValue newArray = (ExpressionValue) newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
            dimensions = new ArrayList<Expression>();
            dimensions.add(expressionValue.expression);
            newArray.expression = new ArrayCreationExpr(newArray.type, dimensions, 0);
            return newArray;
        case ARRAYLENGTH:
            return new ExpressionValue(PRIMITIVE_INT, new FieldAccessExpr(expressionValue.expression, "length"));
        case ATHROW:
            throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
        case CHECKCAST:
            ExpressionValue cast = (ExpressionValue) newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
            cast.expression = new CastExpr(new ReferenceType(cast.type), expressionValue.expression);
            return cast;
        case INSTANCEOF:
            ExpressionValue instanceOf = (ExpressionValue) newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
            instanceOf.expression = new InstanceOfExpr(expressionValue.expression, new ReferenceType(instanceOf.type));
            return instanceOf;
        case MONITORENTER:
        case MONITOREXIT:
            throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
        case IFNULL:
            handleNestedConditional(new BinaryExpr(expressionValue.expression, new NullLiteralExpr(), BinaryExpr.Operator.notEquals));
            return null;
        case IFNONNULL:
            handleNestedConditional(new BinaryExpr(expressionValue.expression, new NullLiteralExpr(), BinaryExpr.Operator.equals));
            return null;
        default:
            throw new Error("Internal error.");
    }
}
Also used : AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) ArrayList(java.util.ArrayList) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) ReferenceType(japa.parser.ast.type.ReferenceType) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) PrimitiveType(japa.parser.ast.type.PrimitiveType)

Aggregations

IincInsnNode (org.objectweb.asm.tree.IincInsnNode)2 PrimitiveType (japa.parser.ast.type.PrimitiveType)1 ReferenceType (japa.parser.ast.type.ReferenceType)1 ArrayList (java.util.ArrayList)1 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)1 IntInsnNode (org.objectweb.asm.tree.IntInsnNode)1 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)1