Search in sources :

Example 21 with Operator

use of org.evosuite.symbolic.expr.Operator 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 22 with Operator

use of org.evosuite.symbolic.expr.Operator 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 23 with Operator

use of org.evosuite.symbolic.expr.Operator 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 24 with Operator

use of org.evosuite.symbolic.expr.Operator 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 25 with Operator

use of org.evosuite.symbolic.expr.Operator 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

Operator (org.evosuite.symbolic.expr.Operator)39 RealUnaryExpression (org.evosuite.symbolic.expr.fp.RealUnaryExpression)25 RealValue (org.evosuite.symbolic.expr.fp.RealValue)25 SmtExpr (org.evosuite.symbolic.solver.smt.SmtExpr)14 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)8 LinkedList (java.util.LinkedList)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 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 SmtIntConstant (org.evosuite.symbolic.solver.smt.SmtIntConstant)3 RegExp (dk.brics.automaton.RegExp)1 SmtStringConstant (org.evosuite.symbolic.solver.smt.SmtStringConstant)1