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());
}
}
}
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);
}
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);
}
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;
}
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());
}
}
}
Aggregations