Search in sources :

Example 56 with RealValue

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

the class HeapVM method FALOAD.

@Override
public void FALOAD(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;
    float fp32 = Array.getFloat(conc_array, conc_index);
    RealValue c = env.heap.array_load(symb_array, conc_index, (double) fp32);
    env.topFrame().operandStack.pushFp32(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)

Example 57 with RealValue

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

the class HeapVM method GETFIELD.

/**
 * Retrieve the value of an instance field
 *
 * <p>
 * Before actually retrieving the value, the JVM will check if the instance
 * is null. If the receiver instance is null, the JVM will throw a null
 * pointer exception.
 *
 * @see http
 *      ://java.sun.com/docs/books/jvms/second_edition/html/Instructions2
 *      .doc5.html#getfield
 */
@Override
public void GETFIELD(Object conc_receiver, String className, String fieldName, String desc) {
    // consume symbolic operand
    ReferenceExpression receiver_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_receiver, receiver_ref);
    Field field = resolveField(classLoader.getClassForName(className), fieldName);
    env.ensurePrepared(field.getDeclaringClass());
    boolean isAccessible = field.isAccessible();
    if (!isAccessible) {
        field.setAccessible(true);
    }
    /* null-check */
    if (nullReferenceViolation(receiver_ref, conc_receiver)) {
        return;
    }
    ReferenceExpression symb_receiver = receiver_ref;
    Type type = Type.getType(desc);
    try {
        if (type.equals(Type.INT_TYPE)) {
            int value = field.getInt(conc_receiver);
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.LONG_TYPE)) {
            long value = field.getLong(conc_receiver);
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, value);
            env.topFrame().operandStack.pushBv64(intExpr);
        } else if (type.equals(Type.FLOAT_TYPE)) {
            float value = field.getFloat(conc_receiver);
            RealValue fp32 = (RealValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (double) value);
            env.topFrame().operandStack.pushFp32(fp32);
        } else if (type.equals(Type.DOUBLE_TYPE)) {
            double value = field.getDouble(conc_receiver);
            RealValue fp64 = (RealValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, value);
            env.topFrame().operandStack.pushFp64(fp64);
        } else if (type.equals(Type.CHAR_TYPE)) {
            char value = field.getChar(conc_receiver);
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.SHORT_TYPE)) {
            short value = field.getShort(conc_receiver);
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BOOLEAN_TYPE)) {
            boolean booleanValue = field.getBoolean(conc_receiver);
            int value = booleanValue ? 1 : 0;
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else if (type.equals(Type.BYTE_TYPE)) {
            byte value = field.getByte(conc_receiver);
            IntegerValue intExpr = (IntegerValue) env.heap.getField(className, fieldName, conc_receiver, symb_receiver, (long) value);
            env.topFrame().operandStack.pushBv32(intExpr);
        } else {
            Object value = field.get(conc_receiver);
            ReferenceExpression ref = env.heap.getReference(value);
            env.topFrame().operandStack.pushRef(ref);
        }
        if (!isAccessible) {
            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 58 with RealValue

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

the class LocalsVM method FSTORE.

@Override
public void FSTORE(int i) {
    RealValue realExpr = env.topFrame().operandStack.popFp32();
    env.topFrame().localsTable.setFp32Local(i, realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue)

Example 59 with RealValue

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

the class LocalsVM method DLOAD.

@Override
public void DLOAD(int i) {
    RealValue realExpr = (RealValue) env.topFrame().localsTable.getFp64Local(i);
    env.topFrame().operandStack.pushFp64(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue)

Example 60 with RealValue

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

the class CEIL method executeFunction.

@Override
public Object executeFunction() {
    double res = this.getConcDoubleRetVal();
    RealValue realExpression = this.getSymbRealArgument(0);
    RealValue ceilExpr;
    if (realExpression.containsSymbolicVariable()) {
        Operator op = Operator.CEIL;
        ceilExpr = new RealUnaryExpression(realExpression, op, res);
    } else {
        ceilExpr = this.getSymbRealRetVal();
    }
    return ceilExpr;
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) Operator(org.evosuite.symbolic.expr.Operator) RealUnaryExpression(org.evosuite.symbolic.expr.fp.RealUnaryExpression)

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