Search in sources :

Example 1 with IntegerToRealCast

use of org.evosuite.symbolic.expr.fp.IntegerToRealCast in project evosuite by EvoSuite.

the class SymbolicObserver method pushParameterList.

private void pushParameterList(List<VariableReference> parameters, Scope scope, String desc) {
    Type[] argTypes = Type.getArgumentTypes(desc);
    for (int i = 0; i < parameters.size(); i++) {
        VariableReference varRef = parameters.get(i);
        Type argType = argTypes[i];
        ReferenceExpressionPair readResult = this.read(varRef, scope);
        Expression<?> symb_expr = readResult.getExpression();
        ReferenceExpression symb_ref = readResult.getReference();
        if (isValue(argType)) {
            if (symb_expr instanceof RealValue) {
                RealValue realExpr = (RealValue) symb_expr;
                if (isFp32(argType)) {
                    env.topFrame().operandStack.pushFp32(realExpr);
                } else if (isFp64(argType)) {
                    env.topFrame().operandStack.pushFp64(realExpr);
                } else if (isBv32(argType)) {
                    int concV = realExpr.getConcreteValue().intValue();
                    RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, (long) concV);
                    env.topFrame().operandStack.pushBv32(castExpr);
                } else if (isBv64(argType)) {
                    long concV = realExpr.getConcreteValue().longValue();
                    RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, concV);
                    env.topFrame().operandStack.pushBv64(castExpr);
                } else {
                /* unreachable code */
                }
            } else if (symb_expr instanceof IntegerValue) {
                IntegerValue integerExpr = (IntegerValue) symb_expr;
                if (isBv32(argType)) {
                    env.topFrame().operandStack.pushBv32(integerExpr);
                } else if (isBv64(argType)) {
                    env.topFrame().operandStack.pushBv64(integerExpr);
                } else if (isFp32(argType)) {
                    float concV = integerExpr.getConcreteValue().floatValue();
                    IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, (double) concV);
                    env.topFrame().operandStack.pushFp32(castExpr);
                } else if (isFp64(argType)) {
                    double concV = integerExpr.getConcreteValue().doubleValue();
                    IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, concV);
                    env.topFrame().operandStack.pushFp64(castExpr);
                } else {
                /* unreachable code */
                }
            } else {
                if (symb_ref.getConcreteValue() == null) {
                    // although this will lead in the JVM to a NPE, we push
                    // a dummy
                    // value to prevent the DSE VM from crashing
                    pushDummyValue(argType);
                } else {
                    // auto unboxing reference
                    ReferenceConstant non_null_symb_ref = (ReferenceConstant) symb_ref;
                    Object conc_object = scope.getObject(varRef);
                    Expression<?> unboxed_expr = unboxReference(argType, conc_object, non_null_symb_ref);
                    pushValue(argType, unboxed_expr);
                }
            }
        } else {
            ReferenceExpression ref = readResult.getReference();
            env.topFrame().operandStack.pushRef(ref);
        }
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) VariableReference(org.evosuite.testcase.variable.VariableReference) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) RealToIntegerCast(org.evosuite.symbolic.expr.bv.RealToIntegerCast) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) PrimitiveExpression(org.evosuite.testcase.statements.PrimitiveExpression) Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 2 with IntegerToRealCast

use of org.evosuite.symbolic.expr.fp.IntegerToRealCast in project evosuite by EvoSuite.

the class ArithmeticVM method I2F.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#i2f
 */
@Override
public void I2F() {
    IntegerValue integerExpr = env.topFrame().operandStack.popBv32();
    int integerValue = ((Long) integerExpr.getConcreteValue()).intValue();
    RealValue realExpr;
    float concreteValue = (float) integerValue;
    if (!integerExpr.containsSymbolicVariable()) {
        realExpr = ExpressionFactory.buildNewRealConstant(concreteValue);
    } else {
        realExpr = new IntegerToRealCast(integerExpr, (double) concreteValue);
    }
    env.topFrame().operandStack.pushFp32(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 3 with IntegerToRealCast

use of org.evosuite.symbolic.expr.fp.IntegerToRealCast in project evosuite by EvoSuite.

the class ArithmeticVM method L2D.

@Override
public void L2D() {
    IntegerValue integerExpr = env.topFrame().operandStack.popBv64();
    long longValue = ((Long) integerExpr.getConcreteValue()).longValue();
    RealValue realExpr;
    double concreteValue = (double) longValue;
    if (!integerExpr.containsSymbolicVariable()) {
        realExpr = ExpressionFactory.buildNewRealConstant(concreteValue);
    } else {
        realExpr = new IntegerToRealCast(integerExpr, (double) concreteValue);
    }
    env.topFrame().operandStack.pushFp64(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 4 with IntegerToRealCast

use of org.evosuite.symbolic.expr.fp.IntegerToRealCast in project evosuite by EvoSuite.

the class ArithmeticVM method L2F.

@Override
public void L2F() {
    IntegerValue integerExpr = env.topFrame().operandStack.popBv64();
    long longValue = ((Long) integerExpr.getConcreteValue()).longValue();
    RealValue realExpr;
    float concreteValue = (float) longValue;
    if (!integerExpr.containsSymbolicVariable()) {
        realExpr = ExpressionFactory.buildNewRealConstant(concreteValue);
    } else {
        realExpr = new IntegerToRealCast(integerExpr, (double) concreteValue);
    }
    env.topFrame().operandStack.pushFp32(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 5 with IntegerToRealCast

use of org.evosuite.symbolic.expr.fp.IntegerToRealCast in project evosuite by EvoSuite.

the class ArithmeticVM method I2D.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#i2d
 */
@Override
public void I2D() {
    IntegerValue integerExpr = env.topFrame().operandStack.popBv32();
    int integerValue = ((Long) integerExpr.getConcreteValue()).intValue();
    RealValue realExpr;
    double concreteValue = (double) integerValue;
    if (!integerExpr.containsSymbolicVariable()) {
        realExpr = ExpressionFactory.buildNewRealConstant(concreteValue);
    } else {
        realExpr = new IntegerToRealCast(integerExpr, (double) concreteValue);
    }
    env.topFrame().operandStack.pushFp64(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerToRealCast(org.evosuite.symbolic.expr.fp.IntegerToRealCast) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Aggregations

IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)6 IntegerToRealCast (org.evosuite.symbolic.expr.fp.IntegerToRealCast)6 RealValue (org.evosuite.symbolic.expr.fp.RealValue)6 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)2 RealToIntegerCast (org.evosuite.symbolic.expr.bv.RealToIntegerCast)2 Expression (org.evosuite.symbolic.expr.Expression)1 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)1 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)1 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1 Type (org.objectweb.asm.Type)1