Search in sources :

Example 1 with SmtIntConstant

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringBinaryExpression 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()) {
        String stringValue = e.getConcreteValue();
        SmtExpr strConstant = SmtExprBuilder.mkStringConstant(stringValue);
        return strConstant;
    }
    Operator op = e.getOperator();
    switch(op) {
        case CONCAT:
            {
                SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, right);
                return concatExpr;
            }
        case APPEND_STRING:
            {
                SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, right);
                return concatExpr;
            }
        case APPEND_INTEGER:
            {
                SmtExpr rigthStr = SmtExprBuilder.mkIntToStr(right);
                SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, rigthStr);
                return concatExpr;
            }
        case APPEND_BOOLEAN:
            {
                SmtIntConstant zero = SmtExprBuilder.ZERO_INT;
                SmtExpr eqZero = SmtExprBuilder.mkEq(right, zero);
                SmtStringConstant falseConstantExpr = SmtExprBuilder.mkStringConstant(String.valueOf(Boolean.FALSE));
                SmtStringConstant trueConstantExpr = SmtExprBuilder.mkStringConstant(String.valueOf(Boolean.TRUE));
                SmtExpr ite = SmtExprBuilder.mkITE(eqZero, falseConstantExpr, trueConstantExpr);
                SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, ite);
                return concatExpr;
            }
        case APPEND_CHAR:
            {
                SmtExpr rigthStr = SmtExprBuilder.mkIntToChar(right);
                SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, rigthStr);
                return concatExpr;
            }
        case APPEND_REAL:
            {
                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) SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) SmtStringConstant(org.evosuite.symbolic.solver.smt.SmtStringConstant)

Example 2 with SmtIntConstant

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringBinaryComparison e, Void v) {
    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();
        SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
        return intConst;
    }
    SmtIntConstant oneConstant = SmtExprBuilder.ONE_INT;
    SmtIntConstant zeroConstant = SmtExprBuilder.ZERO_INT;
    switch(op) {
        case EQUALS:
            {
                SmtExpr equalsFormula = SmtExprBuilder.mkEq(left, right);
                SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(equalsFormula, oneConstant, zeroConstant);
                return ifThenElseFormula;
            }
        case ENDSWITH:
            {
                SmtExpr endsWithExpr = SmtExprBuilder.mkStrSuffixOf(right, left);
                SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(endsWithExpr, oneConstant, zeroConstant);
                return ifThenElseFormula;
            }
        case CONTAINS:
            {
                SmtExpr equalsFormula = SmtExprBuilder.mkStrContains(left, right);
                SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(equalsFormula, oneConstant, zeroConstant);
                return ifThenElseFormula;
            }
        case STARTSWITH:
            {
                throw new IllegalArgumentException("Illegal StringBinaryComparison operator " + op);
            }
        case PATTERNMATCHES:
            {
                String regex = e.getLeftOperand().getConcreteValue();
                String expandedRegex = RegexDistanceUtils.expandRegex(regex);
                RegExp regexp = new RegExp(expandedRegex, RegExp.INTERSECTION);
                RegExpToCVC4Visitor visitor = new RegExpToCVC4Visitor();
                SmtExpr regExpSmtExpr = visitor.visitRegExp(regexp);
                if (regExpSmtExpr == null) {
                    long longValue = e.getConcreteValue();
                    SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
                    return intConst;
                } else {
                    SmtExpr strInRegExp = SmtExprBuilder.mkStrInRegExp(right, regExpSmtExpr);
                    SmtExpr iteExpr = SmtExprBuilder.mkITE(strInRegExp, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
                    return iteExpr;
                }
            }
        case EQUALSIGNORECASE:
        case REGIONMATCHES:
        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) SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) RegExp(dk.brics.automaton.RegExp) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 3 with SmtIntConstant

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

the class RegExpToCVC4Visitor method visitRepeatMinMax.

@Override
public SmtExpr visitRepeatMinMax(RegExp e, int min, int max) {
    SmtExpr regExpr = this.visitRegExp(e);
    if (regExpr == null) {
        return null;
    }
    SmtIntConstant minExpr = SmtExprBuilder.mkIntConstant(min);
    SmtIntConstant maxExpr = SmtExprBuilder.mkIntConstant(max);
    SmtExpr loopExpr = SmtExprBuilder.mkLoop(regExpr, minExpr, maxExpr);
    return loopExpr;
}
Also used : SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr)

Example 4 with SmtIntConstant

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

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringMultipleComparison e, Void v) {
    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 (isNull(left, right, others)) {
        return null;
    }
    if (!isSymbolic(left, right, others)) {
        long longValue = e.getConcreteValue();
        SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
        return intConst;
    }
    switch(op) {
        case STARTSWITH:
            {
                SmtExpr indexExpr = others.get(0);
                if (indexExpr.equals(SmtExprBuilder.ZERO_INT)) {
                    SmtIntConstant oneExpr = SmtExprBuilder.ONE_INT;
                    SmtIntConstant zeroExpr = SmtExprBuilder.ZERO_INT;
                    SmtExpr startsWithFormula = SmtExprBuilder.mkStrPrefixOf(right, left);
                    SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(startsWithFormula, oneExpr, zeroExpr);
                    return ifThenElseFormula;
                } else {
                    long longValue = e.getConcreteValue();
                    SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
                    return intConst;
                }
            }
        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) SmtIntConstant(org.evosuite.symbolic.solver.smt.SmtIntConstant) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) LinkedList(java.util.LinkedList) 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)

Example 5 with SmtIntConstant

use of org.evosuite.symbolic.solver.smt.SmtIntConstant 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)

Aggregations

SmtExpr (org.evosuite.symbolic.solver.smt.SmtExpr)6 SmtIntConstant (org.evosuite.symbolic.solver.smt.SmtIntConstant)6 Operator (org.evosuite.symbolic.expr.Operator)3 RegExp (dk.brics.automaton.RegExp)1 LinkedList (java.util.LinkedList)1 Expression (org.evosuite.symbolic.expr.Expression)1 IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)1 IntegerUnaryExpression (org.evosuite.symbolic.expr.bv.IntegerUnaryExpression)1 RealUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.RealUnaryToIntegerExpression)1 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)1 StringMultipleToIntegerExpression (org.evosuite.symbolic.expr.bv.StringMultipleToIntegerExpression)1 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)1 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)1 RealUnaryExpression (org.evosuite.symbolic.expr.fp.RealUnaryExpression)1 GetFieldExpression (org.evosuite.symbolic.expr.ref.GetFieldExpression)1 StringBinaryExpression (org.evosuite.symbolic.expr.str.StringBinaryExpression)1 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)1 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)1 SmtStringConstant (org.evosuite.symbolic.solver.smt.SmtStringConstant)1