Search in sources :

Example 6 with SmtExpr

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

the class ConstraintToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(RealConstraint 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 7 with SmtExpr

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

the class Z3QueryPrinter method print.

public String print(SmtCheckSatQuery smtQuery, long timeout) {
    StringBuffer buff = new StringBuffer();
    buff.append("(set-option :timeout " + timeout + ")");
    buff.append("\n");
    for (SmtConstantDeclaration constantDeclaration : smtQuery.getConstantDeclarations()) {
        String str = String.format("(declare-const %s %s)", constantDeclaration.getConstantName(), constantDeclaration.getConstantSort());
        buff.append(str);
        buff.append("\n");
    }
    SmtExprPrinter printer = new SmtExprPrinter();
    for (SmtAssertion assertionDeclaration : smtQuery.getAssertions()) {
        SmtExpr formula = assertionDeclaration.getFormula();
        String formulaStr = formula.accept(printer, null);
        String str = String.format("(assert %s)", formulaStr);
        buff.append(str);
        buff.append("\n");
    }
    buff.append("(check-sat)");
    buff.append("\n");
    buff.append("(get-model)");
    buff.append("\n");
    buff.append("(exit)");
    buff.append("\n");
    return buff.toString();
}
Also used : SmtAssertion(org.evosuite.symbolic.solver.smt.SmtAssertion) SmtExprPrinter(org.evosuite.symbolic.solver.smt.SmtExprPrinter) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) SmtConstantDeclaration(org.evosuite.symbolic.solver.smt.SmtConstantDeclaration)

Example 8 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringReaderExpr e, Void arg) {
    long longValue = e.getConcreteValue();
    SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
    return intConst;
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 9 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringMultipleExpression e, Void arg) {
    Expression<String> leftOperand = e.getLeftOperand();
    Expression<?> rightOperand = e.getRightOperand();
    Operator op = e.getOperator();
    ArrayList<Expression<?>> othersOperands = e.getOther();
    SmtExpr left = leftOperand.accept(this, null);
    SmtExpr right = rightOperand.accept(this, null);
    List<SmtExpr> others = new LinkedList<SmtExpr>();
    for (Expression<?> otherOperand : othersOperands) {
        SmtExpr other = otherOperand.accept(this, null);
        others.add(other);
    }
    if (left == null || right == null) {
        return null;
    }
    for (SmtExpr expr : others) {
        if (expr == null) {
            return null;
        }
    }
    if (!left.isSymbolic() && !right.isSymbolic()) {
        boolean isSymbolic = false;
        for (SmtExpr smtExpr : others) {
            if (smtExpr.isSymbolic()) {
                isSymbolic = true;
            }
        }
        if (!isSymbolic) {
            String stringValue = e.getConcreteValue();
            return mkStringConstant(stringValue);
        }
    }
    switch(op) {
        case REPLACECS:
            {
                SmtExpr string = left;
                SmtExpr target = right;
                SmtExpr replacement = others.get(0);
                SmtExpr substringExpr = SmtExprBuilder.mkReplace(string, target, replacement);
                return substringExpr;
            }
        case SUBSTRING:
            {
                SmtExpr string = left;
                SmtExpr fromExpr = right;
                SmtExpr toExpr = others.get(0);
                SmtExpr substringExpr = SmtExprBuilder.mkSubstring(string, fromExpr, toExpr);
                return substringExpr;
            }
        case REPLACEC:
        case REPLACEALL:
        case REPLACEFIRST:
            {
                String stringValue = e.getConcreteValue();
                return mkStringConstant(stringValue);
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet! " + op);
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) Expression(org.evosuite.symbolic.expr.Expression) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) StringBinaryExpression(org.evosuite.symbolic.expr.str.StringBinaryExpression) GetFieldExpression(org.evosuite.symbolic.expr.ref.GetFieldExpression) StringMultipleToIntegerExpression(org.evosuite.symbolic.expr.bv.StringMultipleToIntegerExpression) IntegerUnaryExpression(org.evosuite.symbolic.expr.bv.IntegerUnaryExpression) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) RealUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.RealUnaryToIntegerExpression) RealUnaryExpression(org.evosuite.symbolic.expr.fp.RealUnaryExpression) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) LinkedList(java.util.LinkedList)

Example 10 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(RealBinaryExpression e, Void arg) {
    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 mkRepresentableRealConstant(doubleValue);
    }
    switch(e.getOperator()) {
        case DIV:
            {
                SmtExpr divExpr = SmtExprBuilder.mkRealDiv(left, right);
                return divExpr;
            }
        case MUL:
            {
                SmtExpr mulExpr = SmtExprBuilder.mkMul(left, right);
                return mulExpr;
            }
        case MINUS:
            {
                SmtExpr subExpr = SmtExprBuilder.mkSub(left, right);
                return subExpr;
            }
        case PLUS:
            {
                SmtExpr addExpr = SmtExprBuilder.mkAdd(left, right);
                return addExpr;
            }
        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();
                if (!isRepresentable(concreteValue)) {
                    return null;
                } else {
                    return SmtExprBuilder.mkRealConstant(concreteValue);
                }
            }
        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