Search in sources :

Example 51 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringUnaryExpression e, Void v) {
    SmtExpr operand = e.getOperand().accept(this, null);
    if (operand == null) {
        return null;
    }
    if (!operand.isSymbolic()) {
        String stringValue = e.getConcreteValue();
        return SmtExprBuilder.mkStringConstant(stringValue);
    }
    Operator op = e.getOperator();
    switch(op) {
        case TRIM:
        case TOLOWERCASE:
        case TOUPPERCASE:
            {
                String stringValue = e.getConcreteValue();
                return SmtExprBuilder.mkStringConstant(stringValue);
            }
        default:
            throw new IllegalArgumentException("The operation " + op + " is not a unary string operation");
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 52 with SmtExpr

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

the class ExprToCVC4Visitor 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:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        long rightValue = e.getRightOperand().getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkIntConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkIntDiv(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr expr = SmtExprBuilder.mkIntDiv(left, right);
                return expr;
            }
        case MUL:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        long rightValue = e.getRightOperand().getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkIntConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkMul(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr expr = SmtExprBuilder.mkMul(left, right);
                return expr;
            }
        case MINUS:
            {
                SmtExpr expr = SmtExprBuilder.mkSub(left, right);
                return expr;
            }
        case PLUS:
            {
                SmtExpr expr = SmtExprBuilder.mkAdd(left, right);
                return expr;
            }
        case REM:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        long rightValue = e.getRightOperand().getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkIntConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkMod(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr mod = SmtExprBuilder.mkMod(left, right);
                return 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 = 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 = 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 = 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 = 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 = 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 = 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 53 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

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

Example 54 with SmtExpr

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

the class ConstraintToCVC4Visitor method visit.

private SmtExpr visit(Expression<?> leftOperand, Comparator cmp, Expression<?> rightOperand) {
    SmtExpr left = leftOperand.accept(exprVisitor, null);
    SmtExpr right = rightOperand.accept(exprVisitor, null);
    if (left == null || right == null) {
        return null;
    }
    return mkComparison(left, cmp, right);
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 55 with SmtExpr

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

the class RegExpToCVC4Visitor method visitRepeatMin.

@Override
public SmtExpr visitRepeatMin(RegExp e, int min) {
    SmtExpr regExpr = this.visitRegExp(e);
    if (regExpr == null) {
        return null;
    }
    if (min == 1) {
        SmtExpr kleeneCrossExpr = SmtExprBuilder.mkRegExpKleeCross(regExpr);
        return kleeneCrossExpr;
    } else {
        SmtIntConstant minExpr = SmtExprBuilder.mkIntConstant(min);
        SmtExpr loopExpr = SmtExprBuilder.mkLoop(regExpr, minExpr);
        return loopExpr;
    }
}
Also used : SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) 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