Search in sources :

Example 46 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

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

Example 47 with SmtExpr

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

the class ExprToCVC4Visitor method mkBV2Int.

private static SmtExpr mkBV2Int(SmtExpr bv) {
    SmtExpr bv2nat = SmtExprBuilder.mkBV2Nat(bv);
    SmtIntConstant maxIntValue = SmtExprBuilder.mkIntConstant(Integer.MAX_VALUE);
    SmtExpr condExpr = SmtExprBuilder.mkLe(bv2nat, maxIntValue);
    SmtExpr bvMinusOne = SmtExprBuilder.mkInt2BV(32, SmtExprBuilder.mkIntConstant(-1));
    SmtExpr xor = SmtExprBuilder.mkBVXOR(bv, bvMinusOne);
    SmtExpr bvOne = SmtExprBuilder.mkInt2BV(32, SmtExprBuilder.ONE_INT);
    SmtExpr bvAdd = SmtExprBuilder.mkBVADD(xor, bvOne);
    SmtExpr bv2natAdd = SmtExprBuilder.mkBV2Nat(bvAdd);
    SmtExpr thenExpr = bv2nat;
    SmtExpr elseExpr = SmtExprBuilder.mkNeg(bv2natAdd);
    SmtExpr ite = SmtExprBuilder.mkITE(condExpr, thenExpr, elseExpr);
    return ite;
}
Also used : SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 48 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringMultipleExpression e, Void v) {
    Expression<String> leftOperand = e.getLeftOperand();
    Expression<?> rightOperand = e.getRightOperand();
    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<?> otherExpr : othersOperands) {
        SmtExpr other = otherExpr.accept(this, null);
        others.add(other);
    }
    if (isNull(left, right, others)) {
        return null;
    }
    if (!isSymbolic(left, right, others)) {
        String stringValue = e.getConcreteValue();
        SmtExpr strConstant = SmtExprBuilder.mkStringConstant(stringValue);
        return strConstant;
    }
    Operator op = e.getOperator();
    switch(op) {
        case SUBSTRING:
            {
                SmtExpr startIndex = right;
                SmtExpr endIndex = others.get(0);
                SmtExpr offset = SmtExprBuilder.mkSub(endIndex, startIndex);
                SmtExpr substring = SmtExprBuilder.mkStrSubstring(left, startIndex, offset);
                return substring;
            }
        case REPLACEC:
            {
                long concreteTarget = (Long) rightOperand.getConcreteValue();
                long concreteReplacement = (Long) othersOperands.get(0).getConcreteValue();
                String targetString = String.valueOf((char) concreteTarget);
                String replacementString = String.valueOf((char) concreteReplacement);
                SmtExpr target = SmtExprBuilder.mkStringConstant(targetString);
                SmtExpr replacement = SmtExprBuilder.mkStringConstant(replacementString);
                SmtExpr replace = SmtExprBuilder.mkStrReplace(left, target, replacement);
                return replace;
            }
        case REPLACECS:
            {
                SmtExpr target = right;
                SmtExpr replacement = others.get(0);
                SmtExpr replace = SmtExprBuilder.mkStrReplace(left, target, replacement);
                return replace;
            }
        case REPLACEALL:
        case REPLACEFIRST:
            {
                String stringValue = e.getConcreteValue();
                SmtExpr strConstant = SmtExprBuilder.mkStringConstant(stringValue);
                return strConstant;
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet! " + op);
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) 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) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) RealUnaryExpression(org.evosuite.symbolic.expr.fp.RealUnaryExpression) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) Expression(org.evosuite.symbolic.expr.Expression) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression) RealUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.RealUnaryToIntegerExpression) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) LinkedList(java.util.LinkedList)

Example 49 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringToIntegerCast e, Void v) {
    SmtExpr argument = e.getArgument().accept(this, null);
    if (argument == null) {
        return null;
    }
    if (!argument.isSymbolic()) {
        long concreteValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(concreteValue);
    }
    SmtExpr argumentExpr = SmtExprBuilder.mkStrToInt(argument);
    return argumentExpr;
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 50 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringUnaryToIntegerExpression e, Void v) {
    SmtExpr operand = e.getOperand().accept(this, null);
    if (operand == null) {
        return null;
    }
    if (!operand.isSymbolic()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    Operator op = e.getOperator();
    switch(op) {
        case LENGTH:
            {
                SmtExpr app = SmtExprBuilder.mkStrLen(operand);
                return app;
            }
        case IS_INTEGER:
            {
                long longValue = e.getConcreteValue();
                return SmtExprBuilder.mkIntConstant(longValue);
            }
        default:
            throw new IllegalArgumentException("The operator " + e.getOperator() + " is not a string operation returning an integer");
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) 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