Search in sources :

Example 11 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

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

Example 12 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringBinaryToIntegerExpression e, Void arg) {
    Expression<String> leftOperand = e.getLeftOperand();
    Operator op = e.getOperator();
    Expression<?> rightOperand = e.getRightOperand();
    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 INDEXOFS:
            {
                SmtExpr indexOfExpr = SmtExprBuilder.mkIndexOf(left, right);
                return indexOfExpr;
            }
        case CHARAT:
            {
                SmtExpr startExpr = right;
                SmtExpr lengthExpr = SmtExprBuilder.ONE_INT;
                SmtExpr charAtExpr = SmtExprBuilder.mkSubstring(left, startExpr, lengthExpr);
                SmtExpr charToInt = SmtExprBuilder.mkCharToInt(charAtExpr);
                return charToInt;
            }
        case INDEXOFC:
        case LASTINDEXOFC:
        case LASTINDEXOFS:
        case COMPARETO:
        case COMPARETOIGNORECASE:
            {
                long longValue = e.getConcreteValue();
                return SmtExprBuilder.mkIntConstant(longValue);
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet!" + e.getOperator());
            }
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 13 with SmtExpr

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringUnaryToIntegerExpression e, Void arg) {
    SmtExpr innerString = e.getOperand().accept(this, null);
    if (innerString == null) {
        return null;
    }
    if (!innerString.isSymbolic()) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    Operator op = e.getOperator();
    switch(op) {
        case LENGTH:
            {
                return SmtExprBuilder.mkLength(innerString);
            }
        case IS_INTEGER:
            {
                long longValue = e.getConcreteValue();
                return SmtExprBuilder.mkIntConstant(longValue);
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet!");
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 14 with SmtExpr

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

the class CVC4Solver method buildSmtCheckSatQuery.

private static SmtCheckSatQuery buildSmtCheckSatQuery(Collection<Constraint<?>> constraints) {
    ConstraintToCVC4Visitor v = new ConstraintToCVC4Visitor(true);
    SmtVariableCollector varCollector = new SmtVariableCollector();
    SmtOperatorCollector funCollector = new SmtOperatorCollector();
    List<SmtAssertion> smtAssertions = new LinkedList<SmtAssertion>();
    for (Constraint<?> c : constraints) {
        SmtExpr smtExpr = c.accept(v, null);
        if (smtExpr != null) {
            SmtAssertion smtAssertion = new SmtAssertion(smtExpr);
            smtAssertions.add(smtAssertion);
            smtExpr.accept(varCollector, null);
            smtExpr.accept(funCollector, null);
        }
    }
    Set<SmtVariable> variables = varCollector.getSmtVariables();
    if (variables.isEmpty()) {
        // no variables, constraint system is trivial
        return null;
    }
    List<SmtFunctionDefinition> functionDefinitions = new LinkedList<SmtFunctionDefinition>();
    final boolean addCharToInt = funCollector.getOperators().contains(Operator.CHAR_TO_INT);
    if (addCharToInt) {
        String charToIntFunction = buildCharToIntFunction();
        SmtFunctionDefinition funcDefinition = new SmtFunctionDefinition(charToIntFunction);
        functionDefinitions.add(funcDefinition);
    }
    final boolean addIntToChar = funCollector.getOperators().contains(Operator.INT_TO_CHAR);
    if (addIntToChar) {
        String intToCharFunction = buildIntToCharFunction();
        SmtFunctionDefinition funcDefinition = new SmtFunctionDefinition(intToCharFunction);
        functionDefinitions.add(funcDefinition);
    }
    List<SmtFunctionDeclaration> functionDeclarations = new LinkedList<SmtFunctionDeclaration>();
    for (SmtVariable var : variables) {
        String varName = var.getName();
        if (var instanceof SmtIntVariable) {
            SmtFunctionDeclaration intVar = SmtExprBuilder.mkIntFunctionDeclaration(varName);
            functionDeclarations.add(intVar);
        } else if (var instanceof SmtRealVariable) {
            SmtFunctionDeclaration realVar = SmtExprBuilder.mkRealFunctionDeclaration(varName);
            functionDeclarations.add(realVar);
        } else if (var instanceof SmtStringVariable) {
            SmtFunctionDeclaration stringVar = SmtExprBuilder.mkStringFunctionDeclaration(varName);
            functionDeclarations.add(stringVar);
        } else {
            throw new RuntimeException("Unknown variable type " + var.getClass().getCanonicalName());
        }
    }
    SmtCheckSatQuery smtQuery = new SmtCheckSatQuery(new LinkedList<SmtConstantDeclaration>(), functionDeclarations, functionDefinitions, smtAssertions);
    return smtQuery;
}
Also used : SmtFunctionDefinition(org.evosuite.symbolic.solver.smt.SmtFunctionDefinition) SmtAssertion(org.evosuite.symbolic.solver.smt.SmtAssertion) SmtVariableCollector(org.evosuite.symbolic.solver.smt.SmtVariableCollector) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) SmtStringVariable(org.evosuite.symbolic.solver.smt.SmtStringVariable) SmtOperatorCollector(org.evosuite.symbolic.solver.smt.SmtOperatorCollector) SmtIntVariable(org.evosuite.symbolic.solver.smt.SmtIntVariable) SmtFunctionDeclaration(org.evosuite.symbolic.solver.smt.SmtFunctionDeclaration) SmtConstantDeclaration(org.evosuite.symbolic.solver.smt.SmtConstantDeclaration) LinkedList(java.util.LinkedList) SmtRealVariable(org.evosuite.symbolic.solver.smt.SmtRealVariable) SmtCheckSatQuery(org.evosuite.symbolic.solver.smt.SmtCheckSatQuery) SmtVariable(org.evosuite.symbolic.solver.smt.SmtVariable)

Example 15 with SmtExpr

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(RealBinaryExpression 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()) {
        double doubleValue = e.getConcreteValue();
        return SmtExprBuilder.mkRealConstant(doubleValue);
    }
    switch(e.getOperator()) {
        case DIV:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        RealValue r = (RealValue) e.getRightOperand();
                        double rightValue = r.getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkRealConstant(rightValue);
                        SmtExpr rewrite_expr = SmtExprBuilder.mkRealDiv(left, conc_right);
                        return rewrite_expr;
                    }
                }
                SmtExpr expr = SmtExprBuilder.mkRealDiv(left, right);
                return expr;
            }
        case MUL:
            {
                if (rewriteNonLinearExpressions) {
                    if (left.isSymbolic() && right.isSymbolic()) {
                        RealValue r = (RealValue) e.getRightOperand();
                        double rightValue = r.getConcreteValue();
                        SmtExpr conc_right = SmtExprBuilder.mkRealConstant(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 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();
                SmtExpr realConstant = createRatNumber(concreteValue);
                return realConstant;
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
            }
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) 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