Search in sources :

Example 16 with Operator

use of org.evosuite.symbolic.expr.Operator in project evosuite by EvoSuite.

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringBinaryToIntegerExpression e, Void v) {
    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 CHARAT:
            {
                SmtExpr charAtExpr = SmtExprBuilder.mkStrAt(left, right);
                SmtExpr strToInt = SmtExprBuilder.mkCharToInt(charAtExpr);
                return strToInt;
            }
        case INDEXOFS:
            {
                SmtExpr zeroIndex = SmtExprBuilder.mkIntConstant(0);
                SmtExpr indexOf = SmtExprBuilder.mkStrIndexOf(left, right, zeroIndex);
                return indexOf;
            }
        case INDEXOFC:
            {
                SmtExpr zeroIndex = SmtExprBuilder.mkIntConstant(0);
                SmtExpr charExpr = SmtExprBuilder.mkIntToChar(right);
                SmtExpr indexOf = SmtExprBuilder.mkStrIndexOf(left, charExpr, zeroIndex);
                return indexOf;
            }
        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 17 with Operator

use of org.evosuite.symbolic.expr.Operator in project evosuite by EvoSuite.

the class ExprToCVC4Visitor method visit.

@Override
public SmtExpr visit(StringMultipleToIntegerExpression e, Void v) {
    SmtExpr left = e.getLeftOperand().accept(this, null);
    SmtExpr right = e.getRightOperand().accept(this, null);
    List<SmtExpr> others = new LinkedList<SmtExpr>();
    for (Expression<?> otherExpr : e.getOther()) {
        SmtExpr otherSmtExpr = otherExpr.accept(this, null);
        others.add(otherSmtExpr);
    }
    if (isNull(left, right, others)) {
        return null;
    }
    if (!isSymbolic(left, right, others)) {
        long longValue = e.getConcreteValue();
        return SmtExprBuilder.mkIntConstant(longValue);
    }
    Operator op = e.getOperator();
    switch(op) {
        case INDEXOFSI:
            {
                SmtExpr other = e.getOther().get(0).accept(this, null);
                SmtExpr indexOf = SmtExprBuilder.mkStrIndexOf(left, right, other);
                return indexOf;
            }
        case INDEXOFCI:
            {
                SmtExpr int2Str = SmtExprBuilder.mkIntToChar(right);
                SmtExpr other = e.getOther().get(0).accept(this, null);
                SmtExpr indexOf = SmtExprBuilder.mkStrIndexOf(left, int2Str, other);
                return indexOf;
            }
        case LASTINDEXOFCI:
        case LASTINDEXOFSI:
            {
                long longValue = e.getConcreteValue();
                SmtExpr intNum = SmtExprBuilder.mkIntConstant(longValue);
                return intNum;
            }
        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)

Example 18 with Operator

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

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

use of org.evosuite.symbolic.expr.Operator in project evosuite by EvoSuite.

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringBinaryExpression e, Void arg) {
    SmtExpr left = e.getLeftOperand().accept(this, null);
    SmtExpr right = e.getRightOperand().accept(this, null);
    Operator op = e.getOperator();
    if (left == null || right == null) {
        return null;
    }
    if (!left.isSymbolic() && !right.isSymbolic()) {
        String stringValue = e.getConcreteValue();
        return mkStringConstant(stringValue);
    }
    switch(op) {
        case APPEND_BOOLEAN:
        case APPEND_CHAR:
        case APPEND_INTEGER:
            {
                long longValue = (Long) e.getRightOperand().getConcreteValue();
                String concreteRight = String.valueOf(longValue);
                SmtExpr concreteRightConstant = mkStringConstant(concreteRight);
                return SmtExprBuilder.mkConcat(left, concreteRightConstant);
            }
        case APPEND_REAL:
            {
                double doubleValue = (Double) e.getRightOperand().getConcreteValue();
                String concreteRight = String.valueOf(doubleValue);
                SmtExpr concreteRightConstant = mkStringConstant(concreteRight);
                return SmtExprBuilder.mkConcat(left, concreteRightConstant);
            }
        case APPEND_STRING:
        case CONCAT:
            {
                return SmtExprBuilder.mkConcat(left, right);
            }
        default:
            {
                throw new UnsupportedOperationException("Not implemented yet! " + op);
            }
    }
}
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