Search in sources :

Example 31 with RealValue

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

the class ArithmeticVM method FCMPL.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc4.html#fcmpop
 */
@Override
public void FCMPL() {
    RealValue right = env.topFrame().operandStack.popFp32();
    RealValue left = env.topFrame().operandStack.popFp32();
    float left_concrete_value = ((Double) left.getConcreteValue()).floatValue();
    float right_concrete_value = ((Double) right.getConcreteValue()).floatValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewRealConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewRealConstant(right_concrete_value);
    }
    int concrete_value;
    if (new Double(left_concrete_value).isNaN() || new Double(right_concrete_value).isNaN()) {
        concrete_value = 1;
    } else if (left_concrete_value == right_concrete_value) {
        concrete_value = 0;
    } else if (left_concrete_value > right_concrete_value) {
        concrete_value = 1;
    } else {
        assert left_concrete_value < right_concrete_value;
        concrete_value = -1;
    }
    RealComparison ret = new RealComparison(left, right, (long) concrete_value);
    env.topFrame().operandStack.pushBv32(ret);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) RealComparison(org.evosuite.symbolic.expr.bv.RealComparison) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 32 with RealValue

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

the class ArithmeticVM method DMUL.

@Override
public void DMUL() {
    RealValue right = env.topFrame().operandStack.popFp64();
    RealValue left = env.topFrame().operandStack.popFp64();
    double left_concrete_value = ((Double) left.getConcreteValue()).doubleValue();
    double right_concrete_value = ((Double) right.getConcreteValue()).doubleValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewRealConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewRealConstant(right_concrete_value);
    }
    double con = left_concrete_value * right_concrete_value;
    RealValue realExpr = ExpressionFactory.mul(left, right, con);
    env.topFrame().operandStack.pushFp64(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue)

Example 33 with RealValue

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

the class ArithmeticVM method FADD.

/**
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc4.html#fadd
 */
@Override
public void FADD() {
    RealValue right = env.topFrame().operandStack.popFp32();
    RealValue left = env.topFrame().operandStack.popFp32();
    float left_concrete_value = ((Double) left.getConcreteValue()).floatValue();
    float right_concrete_value = ((Double) right.getConcreteValue()).floatValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewRealConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewRealConstant(right_concrete_value);
    }
    float con = left_concrete_value + right_concrete_value;
    RealValue realExpr = ExpressionFactory.add(left, right, (double) con);
    env.topFrame().operandStack.pushFp32(realExpr);
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue)

Example 34 with RealValue

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(RealBinaryExpression e, Void v) {
    SmtExpr left = e.getLeftOperand().accept(this, null);
    SmtExpr right = e.getRightOperand().accept(this, null);
    if (left == null || right == null) {
        return null;
    }
    if (!left.isSymbolic() && !right.isSymbolic()) {
        double doubleValue = e.getConcreteValue();
        return SmtExprBuilder.mkRealConstant(doubleValue);
    }
    switch(e.getOperator()) {
        case DIV:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        RealValue r = (RealValue) e.getRightOperand();
                        double rightValue = r.getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkRealConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkRealDiv(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr expr = SmtExprBuilder.mkRealDiv(left, right);
                return expr;
            }
        case MUL:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        RealValue r = (RealValue) e.getRightOperand();
                        double rightValue = r.getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkRealConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkMul(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr expr = SmtExprBuilder.mkMul(left, right);
                return expr;
            }
        case MINUS:
            {
                SmtExpr expr = SmtExprBuilder.mkSub(left, right);
                return expr;
            }
        case PLUS:
            {
                SmtExpr expr = SmtExprBuilder.mkAdd(left, right);
                return expr;
            }
        case MAX:
            {
                SmtExpr left_gt_right = SmtExprBuilder.mkGt(left, right);
                SmtExpr ite_expr = SmtExprBuilder.mkITE(left_gt_right, left, right);
                return ite_expr;
            }
        case MIN:
            {
                SmtExpr left_gt_right = SmtExprBuilder.mkLt(left, right);
                SmtExpr ite_expr = SmtExprBuilder.mkITE(left_gt_right, left, right);
                return ite_expr;
            }
        case ATAN2:
        case COPYSIGN:
        case HYPOT:
        case NEXTAFTER:
        case POW:
        case SCALB:
        case IEEEREMAINDER:
        case REM:
            {
                double concreteValue = e.getConcreteValue();
                SmtExpr realConstant = createRatNumber(concreteValue);
                return realConstant;
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
            }
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 35 with RealValue

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

the class HeapVM method FASTORE.

@Override
public void FASTORE(Object conc_array, int conc_index) {
    // get symbolic arguments
    RealValue symb_value = env.topFrame().operandStack.popFp32();
    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)

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