Search in sources :

Example 31 with SmtExpr

use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.

the class ExprToZ3Visitor method visit.

@Override
public SmtExpr visit(IntegerBinaryExpression 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()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    switch(e.getOperator()) {
        case DIV:
            {
                SmtExpr z3_div = SmtExprBuilder.mkIntDiv(left, right);
                return z3_div;
            }
        case MUL:
            {
                SmtExpr z3_mul = SmtExprBuilder.mkMul(left, right);
                return z3_mul;
            }
        case MINUS:
            {
                SmtExpr z3_sub = SmtExprBuilder.mkSub(left, right);
                return z3_sub;
            }
        case PLUS:
            {
                SmtExpr z3_add = SmtExprBuilder.mkAdd(left, right);
                return z3_add;
            }
        case REM:
            {
                SmtExpr z3_mod = SmtExprBuilder.mkMod(left, right);
                return z3_mod;
            }
        case IOR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvor = SmtExprBuilder.mkBVOR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvor);
                return ret_val;
            }
        case IAND:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bv_and = SmtExprBuilder.mkBVAND(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bv_and);
                return ret_val;
            }
        case IXOR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bv_xor = SmtExprBuilder.mkBVXOR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bv_xor);
                return ret_val;
            }
        case SHL:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bv_shl = SmtExprBuilder.mkBVSHL(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bv_shl);
                return ret_val;
            }
        case SHR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bv_shr = SmtExprBuilder.mkBVASHR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bv_shr);
                return ret_val;
            }
        case USHR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bv_shr = SmtExprBuilder.mkBVLSHR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bv_shr);
                return ret_val;
            }
        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;
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
            }
    }
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 32 with SmtExpr

use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.

the class ConstraintToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(IntegerConstraint c, Void arg) {
    ExprToZ3Str2Visitor v = new ExprToZ3Str2Visitor();
    SmtExpr left = c.getLeftOperand().accept(v, null);
    SmtExpr right = c.getRightOperand().accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 33 with SmtExpr

use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.

the class ConstraintToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringConstraint c, Void arg) {
    ExprToZ3Str2Visitor v = new ExprToZ3Str2Visitor();
    SmtExpr left = c.getLeftOperand().accept(v, null);
    SmtExpr right = c.getRightOperand().accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 34 with SmtExpr

use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.

the class Z3Solver method buildSmtQuery.

private static SmtCheckSatQuery buildSmtQuery(Collection<Constraint<?>> constraints, Set<Variable<?>> variables) {
    List<SmtConstantDeclaration> constantDeclarations = new LinkedList<SmtConstantDeclaration>();
    for (Variable<?> v : variables) {
        String varName = v.getName();
        if (v instanceof IntegerVariable) {
            SmtConstantDeclaration intVar = SmtExprBuilder.mkIntConstantDeclaration(varName);
            constantDeclarations.add(intVar);
        } else if (v instanceof RealVariable) {
            SmtConstantDeclaration realVar = SmtExprBuilder.mkRealConstantDeclaration(varName);
            constantDeclarations.add(realVar);
        } else if (v instanceof StringVariable) {
        // ignore string variables
        } else {
            throw new RuntimeException("Unknown variable type " + v.getClass().getCanonicalName());
        }
    }
    List<SmtAssertion> assertions = new LinkedList<SmtAssertion>();
    for (Constraint<?> c : constraints) {
        ConstraintToZ3Visitor v = new ConstraintToZ3Visitor();
        SmtExpr bool_expr = c.accept(v, null);
        if (bool_expr != null && bool_expr.isSymbolic()) {
            SmtAssertion newAssertion = new SmtAssertion(bool_expr);
            assertions.add(newAssertion);
        }
    }
    SmtCheckSatQuery smtCheckSatQuery = new SmtCheckSatQuery(constantDeclarations, assertions);
    return smtCheckSatQuery;
}
Also used : SmtAssertion(org.evosuite.symbolic.solver.smt.SmtAssertion) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) SmtConstantDeclaration(org.evosuite.symbolic.solver.smt.SmtConstantDeclaration) LinkedList(java.util.LinkedList) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) SmtCheckSatQuery(org.evosuite.symbolic.solver.smt.SmtCheckSatQuery)

Example 35 with SmtExpr

use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(IntegerBinaryExpression 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()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    switch(e.getOperator()) {
        case DIV:
            {
                return SmtExprBuilder.mkIntDiv(left, right);
            }
        case MUL:
            {
                return SmtExprBuilder.mkMul(left, right);
            }
        case MINUS:
            {
                return SmtExprBuilder.mkSub(left, right);
            }
        case PLUS:
            {
                return SmtExprBuilder.mkAdd(left, right);
            }
        case REM:
            {
                return SmtExprBuilder.mkRem(left, right);
            }
        case IOR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvor = SmtExprBuilder.mkBVOR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvor);
                return ret_val;
            }
        case IAND:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvand = SmtExprBuilder.mkBVAND(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvand);
                return ret_val;
            }
        case IXOR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvxor = SmtExprBuilder.mkBVXOR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvxor);
                return ret_val;
            }
        case SHL:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvshl = SmtExprBuilder.mkBVSHL(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvshl);
                return ret_val;
            }
        case USHR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvlshr = SmtExprBuilder.mkBVLSHR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvlshr);
                return ret_val;
            }
        case SHR:
            {
                SmtExpr bv_left = SmtExprBuilder.mkInt2BV(32, left);
                SmtExpr bv_right = SmtExprBuilder.mkInt2BV(32, right);
                SmtExpr bvashr = SmtExprBuilder.mkBVASHR(bv_left, bv_right);
                SmtExpr ret_val = SmtExprBuilder.mkBV2Int(bvashr);
                return ret_val;
            }
        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;
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
            }
    }
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Aggregations

SmtExpr (org.evosuite.symbolic.solver.smt.SmtExpr)60 Operator (org.evosuite.symbolic.expr.Operator)14 LinkedList (java.util.LinkedList)8 Comparator (org.evosuite.symbolic.expr.Comparator)6 SmtAssertion (org.evosuite.symbolic.solver.smt.SmtAssertion)6 SmtIntConstant (org.evosuite.symbolic.solver.smt.SmtIntConstant)6 SmtConstantDeclaration (org.evosuite.symbolic.solver.smt.SmtConstantDeclaration)5 Expression (org.evosuite.symbolic.expr.Expression)4 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)4 IntegerUnaryExpression (org.evosuite.symbolic.expr.bv.IntegerUnaryExpression)4 RealUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.RealUnaryToIntegerExpression)4 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)4 StringMultipleToIntegerExpression (org.evosuite.symbolic.expr.bv.StringMultipleToIntegerExpression)4 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)4 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)4 RealUnaryExpression (org.evosuite.symbolic.expr.fp.RealUnaryExpression)4 GetFieldExpression (org.evosuite.symbolic.expr.ref.GetFieldExpression)4 StringBinaryExpression (org.evosuite.symbolic.expr.str.StringBinaryExpression)4 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)4 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)4