Search in sources :

Example 1 with IntegerComparison

use of org.evosuite.symbolic.expr.bv.IntegerComparison in project evosuite by EvoSuite.

the class ArithmeticVM method LCMP.

/**
 * <pre>
 * (a > b)  ==>  1
 * (a == b) ==>  0
 * (a < b)  ==> -1
 * </pre>
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc8.html#lcmp
 */
@Override
public void LCMP() {
    IntegerValue right = env.topFrame().operandStack.popBv64();
    IntegerValue left = env.topFrame().operandStack.popBv64();
    long left_concrete_value = (Long) left.getConcreteValue();
    long right_concrete_value = (Long) right.getConcreteValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    int concrete_value = 0;
    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;
    }
    IntegerComparison intComp = new IntegerComparison(left, right, (long) concrete_value);
    env.topFrame().operandStack.pushBv32(intComp);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerComparison(org.evosuite.symbolic.expr.bv.IntegerComparison) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 2 with IntegerComparison

use of org.evosuite.symbolic.expr.bv.IntegerComparison in project evosuite by EvoSuite.

the class ConstraintNormalizer method normalizeIntegerConstriant.

private static Constraint<?> normalizeIntegerConstriant(IntegerConstraint c) {
    if (c.getLeftOperand() instanceof IntegerComparison) {
        IntegerComparison cmp = (IntegerComparison) c.getLeftOperand();
        int value = ((Number) c.getRightOperand().getConcreteValue()).intValue();
        Comparator op = c.getComparator();
        Expression<Long> cmp_left = cmp.getLeftOperant();
        Expression<Long> cmp_right = cmp.getRightOperant();
        return createIntegerConstraint(cmp_left, op, cmp_right, value);
    } else {
        assert (c.getRightOperand() instanceof IntegerComparison);
        IntegerComparison cmp = (IntegerComparison) c.getRightOperand();
        int value = ((Number) c.getLeftOperand().getConcreteValue()).intValue();
        Comparator op = c.getComparator();
        Expression<Long> cmp_left = cmp.getLeftOperant();
        Expression<Long> cmp_right = cmp.getRightOperant();
        Comparator swap_op = op.swap();
        int swap_value = -value;
        return createIntegerConstraint(cmp_left, swap_op, cmp_right, swap_value);
    }
}
Also used : IntegerComparison(org.evosuite.symbolic.expr.bv.IntegerComparison) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) Comparator(org.evosuite.symbolic.expr.Comparator)

Aggregations

IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)2 IntegerComparison (org.evosuite.symbolic.expr.bv.IntegerComparison)2 Comparator (org.evosuite.symbolic.expr.Comparator)1 Constraint (org.evosuite.symbolic.expr.Constraint)1 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)1 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)1 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)1