Search in sources :

Example 51 with RealValue

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

the class ArithmeticVM method F2L.

@Override
public void F2L() {
    RealValue realExpr = env.topFrame().operandStack.popFp32();
    float floatValue = ((Double) realExpr.getConcreteValue()).floatValue();
    IntegerValue intExpr;
    long concreteValue = (long) floatValue;
    if (!realExpr.containsSymbolicVariable()) {
        intExpr = ExpressionFactory.buildNewIntegerConstant(concreteValue);
    } else {
        intExpr = new RealToIntegerCast(realExpr, concreteValue);
    }
    env.topFrame().operandStack.pushBv64(intExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) RealToIntegerCast(org.evosuite.symbolic.expr.bv.RealToIntegerCast)

Example 52 with RealValue

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

the class ArithmeticVM method F2D.

@Override
public void F2D() {
    RealValue e = env.topFrame().operandStack.popFp32();
    env.topFrame().operandStack.pushFp64(e);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue)

Example 53 with RealValue

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

the class HeapVM method GETSTATIC.

/**
 * GetStatic mypackage/MyClass fieldName FieldType
 *
 * @param owner
 *            name of a class or interface.
 * @param fieldName
 *            name of the field to be read. The owner class or interface
 *            itself my have declared this field. If owner is a class, then
 *            this field may also be declared by a - super-class of the
 *            owner class, or by a - interface implemented by (a super-class
 *            of) the owner class.
 *
 *            http://java.sun.com/docs/books/jvms/second_edition/html/
 *            Instructions2.doc5.html#getstatic
 */
@Override
public void GETSTATIC(String owner, String fieldName, String desc) {
    /**
     * Prepare Class
     */
    // type name given in
    Class<?> claz = env.ensurePrepared(owner);
    // bytecode
    // field may be
    Field concrete_field = resolveField(claz, fieldName);
    // declared by
    // interface
    Class<?> declaringClass = concrete_field.getDeclaringClass();
    if (declaringClass.isInterface()) {
        /*
			 * Unlikely that we ever get here. Java compiler probably computes
			 * value of this (final) field and replaces any
			 * "getstatic MyInterface myField" by "sipush fieldValue" or such.
			 * Even if we get here, there should be no need to prepare this
			 * field, as there has to be an explicit initialization, hence a
			 * <clinit>().
			 */
        logger.debug("Do we have to prepare the static fields of an interface?");
        env.ensurePrepared(declaringClass);
    }
    boolean isAccessible = concrete_field.isAccessible();
    if (!isAccessible) {
        concrete_field.setAccessible(true);
    }
    /**
     * First, Get symbolic expression. If no symbolic expression exists, use
     * concrete value. Then, update operand stack according to type
     */
    Type type = Type.getType(desc);
    try {
        if (type.equals(Type.INT_TYPE)) {
            int value = concrete_field.getInt(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.CHAR_TYPE)) {
            char value = concrete_field.getChar(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.SHORT_TYPE)) {
            short value = concrete_field.getShort(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BOOLEAN_TYPE)) {
            boolean booleanValue = concrete_field.getBoolean(null);
            int value = booleanValue ? 1 : 0;
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BYTE_TYPE)) {
            byte value = concrete_field.getByte(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.LONG_TYPE)) {
            long value = concrete_field.getLong(null);
            IntegerValue intExpr = (IntegerValue) env.heap.getStaticField(owner, fieldName, value);
            env.topFrame().operandStack.pushBv64(intExpr);
        } else if (type.equals(Type.FLOAT_TYPE)) {
            float value = concrete_field.getFloat(null);
            RealValue fp32 = (RealValue) env.heap.getStaticField(owner, fieldName, (double) value);
            env.topFrame().operandStack.pushFp32(fp32);
        } else if (type.equals(Type.DOUBLE_TYPE)) {
            double value = concrete_field.getDouble(null);
            RealValue fp64 = (RealValue) env.heap.getStaticField(owner, fieldName, value);
            env.topFrame().operandStack.pushFp64(fp64);
        } else {
            Object value = concrete_field.get(null);
            ReferenceExpression ref = env.heap.getReference(value);
            env.topFrame().operandStack.pushRef(ref);
        }
        if (!isAccessible) {
            concrete_field.setAccessible(false);
        }
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Field(java.lang.reflect.Field) Type(org.objectweb.asm.Type) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 54 with RealValue

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

the class HeapVM method DASTORE.

@Override
public void DASTORE(Object conc_array, int conc_index) {
    // get symbolic arguments
    RealValue symb_value = env.topFrame().operandStack.popFp64();
    IntegerValue symb_index = env.topFrame().operandStack.popBv32();
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    /* negative index */
    if (negativeIndexViolation(conc_index, symb_index)) {
        return;
    }
    /* out of bound index */
    ReferenceExpression symb_array = array_ref;
    int conc_array_length = Array.getLength(conc_array);
    IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
    if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
        return;
    env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 55 with RealValue

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

the class HeapVM method DALOAD.

/**
 * Load double from array
 *
 * ..., arrayref, index ==> ..., value
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc3.html#daload
 */
@Override
public void DALOAD(Object conc_array, int conc_index) {
    // pop symbolic arguments
    IntegerValue symb_index = env.topFrame().operandStack.popBv32();
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    /* negative index */
    if (negativeIndexViolation(conc_index, symb_index)) {
        return;
    }
    /* out of bound index */
    ReferenceExpression symb_array = (ReferenceExpression) array_ref;
    int conc_array_length = Array.getLength(conc_array);
    IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
    if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
        return;
    double fp64 = Array.getDouble(conc_array, conc_index);
    RealValue c = env.heap.array_load(symb_array, conc_index, (double) fp64);
    env.topFrame().operandStack.pushFp64(c);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Aggregations

RealValue (org.evosuite.symbolic.expr.fp.RealValue)81 Operator (org.evosuite.symbolic.expr.Operator)25 RealUnaryExpression (org.evosuite.symbolic.expr.fp.RealUnaryExpression)23 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)22 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)13 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)12 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)11 Expression (org.evosuite.symbolic.expr.Expression)6 RealToIntegerCast (org.evosuite.symbolic.expr.bv.RealToIntegerCast)6 IntegerToRealCast (org.evosuite.symbolic.expr.fp.IntegerToRealCast)6 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)6 StringValue (org.evosuite.symbolic.expr.str.StringValue)4 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)4 Type (org.objectweb.asm.Type)4 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)3 Field (java.lang.reflect.Field)2 RealComparison (org.evosuite.symbolic.expr.bv.RealComparison)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 VariableReference (org.evosuite.testcase.variable.VariableReference)2 SmtExpr (org.evosuite.symbolic.solver.smt.SmtExpr)1