Search in sources :

Example 36 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringBinaryExpression e, Void arg) {
    SmtExpr left = e.getLeftOperand().accept(this, null);
    SmtExpr right = e.getRightOperand().accept(this, null);
    Operator op = e.getOperator();
    if (left == null || right == null) {
        return null;
    }
    if (!left.isSymbolic() && !right.isSymbolic()) {
        String stringValue = e.getConcreteValue();
        return mkStringConstant(stringValue);
    }
    switch(op) {
        case APPEND_BOOLEAN:
        case APPEND_CHAR:
        case APPEND_INTEGER:
            {
                long longValue = (Long) e.getRightOperand().getConcreteValue();
                String concreteRight = String.valueOf(longValue);
                SmtExpr concreteRightConstant = mkStringConstant(concreteRight);
                return SmtExprBuilder.mkConcat(left, concreteRightConstant);
            }
        case APPEND_REAL:
            {
                double doubleValue = (Double) e.getRightOperand().getConcreteValue();
                String concreteRight = String.valueOf(doubleValue);
                SmtExpr concreteRightConstant = mkStringConstant(concreteRight);
                return SmtExprBuilder.mkConcat(left, concreteRightConstant);
            }
        case APPEND_STRING:
        case CONCAT:
            {
                return SmtExprBuilder.mkConcat(left, right);
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + op);
            }
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 37 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringMultipleComparison 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;
                break;
            }
        }
        if (!isSymbolic) {
            long longValue = e.getConcreteValue();
            return SmtExprBuilder.mkIntConstant(longValue);
        }
    }
    switch(op) {
        case STARTSWITH:
            {
                // discard index (over-approximate solution)
                SmtExpr startsWithExpr = SmtExprBuilder.mkStartsWith(left, right);
                SmtExpr ifThenElseExpr = SmtExprBuilder.mkITE(startsWithExpr, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                return ifThenElseExpr;
            }
        case EQUALS:
        case EQUALSIGNORECASE:
        case ENDSWITH:
        case CONTAINS:
            {
                throw new IllegalArgumentException("Illegal StringMultipleComparison operator " + op);
            }
        case REGIONMATCHES:
        case PATTERNMATCHES:
        case APACHE_ORO_PATTERN_MATCHES:
            {
                long longValue = e.getConcreteValue();
                SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
                return intConst;
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet! " + op);
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) LinkedList(java.util.LinkedList) 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)

Example 38 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(RealToIntegerCast n, Void arg) {
    SmtExpr operandExpr = n.getArgument().accept(this, null);
    if (operandExpr == null) {
        return null;
    }
    if (!operandExpr.isSymbolic()) {
        long longValue = n.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    SmtExpr realToIntStr = SmtExprBuilder.mkReal2Int(operandExpr);
    return realToIntStr;
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 39 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringBinaryComparison e, Void arg) {
    Expression<String> leftOperand = e.getLeftOperand();
    Expression<?> rightOperand = e.getRightOperand();
    Operator op = e.getOperator();
    SmtExpr left = leftOperand.accept(this, null);
    SmtExpr right = rightOperand.accept(this, null);
    if (left == null || right == null) {
        return null;
    }
    if (!left.isSymbolic() && !right.isSymbolic()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    switch(op) {
        case EQUALS:
            {
                SmtExpr equalsFormula = SmtExprBuilder.mkEq(left, right);
                SmtExpr ifThenElseExpr = SmtExprBuilder.mkITE(equalsFormula, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                return ifThenElseExpr;
            }
        case ENDSWITH:
            {
                SmtExpr endsWithExpr = SmtExprBuilder.mkEndsWith(left, right);
                SmtExpr ifThenElseExpr = SmtExprBuilder.mkITE(endsWithExpr, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                return ifThenElseExpr;
            }
        case CONTAINS:
            {
                SmtExpr containsExpr = SmtExprBuilder.mkContains(left, right);
                SmtExpr ifThenElseExpr = SmtExprBuilder.mkITE(containsExpr, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                return ifThenElseExpr;
            }
        case STARTSWITH:
            {
                SmtExpr startsWithExpr = SmtExprBuilder.mkStartsWith(left, right);
                SmtExpr eqTrue = SmtExprBuilder.mkEq(startsWithExpr, SmtExprBuilder.TRUE);
                SmtExpr ifThenElseExpr = SmtExprBuilder.mkITE(eqTrue, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                return ifThenElseExpr;
            }
        case EQUALSIGNORECASE:
        case REGIONMATCHES:
        case PATTERNMATCHES:
        case APACHE_ORO_PATTERN_MATCHES:
            {
                long longValue = e.getConcreteValue();
                SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
                return intConst;
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet! " + op);
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 40 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(IntegerUnaryExpression e, Void v) {
    SmtExpr intExpr = e.getOperand().accept(this, null);
    if (intExpr == null) {
        return null;
    }
    if (!intExpr.isSymbolic()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    switch(e.getOperator()) {
        case NEG:
            {
                SmtExpr minus_expr = SmtExprBuilder.mkNeg(intExpr);
                return minus_expr;
            }
        case GETNUMERICVALUE:
        case ISDIGIT:
        case ISLETTER:
            {
                long longValue = e.getConcreteValue();
                return SmtExprBuilder.mkIntConstant(longValue);
            }
        case ABS:
            SmtExpr zero = SmtExprBuilder.mkIntConstant(0);
            SmtExpr gte_than_zero = SmtExprBuilder.mkGe(intExpr, zero);
            SmtExpr minus_expr = SmtExprBuilder.mkNeg(intExpr);
            SmtExpr ite_expr = SmtExprBuilder.mkITE(gte_than_zero, intExpr, minus_expr);
            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