Search in sources :

Example 11 with Operator

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

the class LOG10 method executeFunction.

@Override
public Object executeFunction() {
    double res = this.getConcDoubleRetVal();
    RealValue realExpression = this.getSymbRealArgument(0);
    RealValue log10Expr;
    if (realExpression.containsSymbolicVariable()) {
        Operator op = Operator.LOG10;
        log10Expr = new RealUnaryExpression(realExpression, op, res);
    } else {
        log10Expr = this.getSymbRealRetVal();
    }
    return log10Expr;
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) Operator(org.evosuite.symbolic.expr.Operator) RealUnaryExpression(org.evosuite.symbolic.expr.fp.RealUnaryExpression)

Example 12 with Operator

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

the class SQRT method executeFunction.

@Override
public Object executeFunction() {
    double res = this.getConcDoubleRetVal();
    RealValue realExpression = this.getSymbRealArgument(0);
    RealValue sqrtExpr;
    if (realExpression.containsSymbolicVariable()) {
        Operator op = Operator.SQRT;
        sqrtExpr = new RealUnaryExpression(realExpression, op, res);
    } else {
        sqrtExpr = this.getSymbRealRetVal();
    }
    return sqrtExpr;
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) Operator(org.evosuite.symbolic.expr.Operator) RealUnaryExpression(org.evosuite.symbolic.expr.fp.RealUnaryExpression)

Example 13 with Operator

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

the class ExprToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringMultipleExpression 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;
            }
        }
        if (!isSymbolic) {
            String stringValue = e.getConcreteValue();
            return mkStringConstant(stringValue);
        }
    }
    switch(op) {
        case REPLACECS:
            {
                SmtExpr string = left;
                SmtExpr target = right;
                SmtExpr replacement = others.get(0);
                SmtExpr substringExpr = SmtExprBuilder.mkReplace(string, target, replacement);
                return substringExpr;
            }
        case SUBSTRING:
            {
                SmtExpr string = left;
                SmtExpr fromExpr = right;
                SmtExpr toExpr = others.get(0);
                SmtExpr substringExpr = SmtExprBuilder.mkSubstring(string, fromExpr, toExpr);
                return substringExpr;
            }
        case REPLACEC:
        case REPLACEALL:
        case REPLACEFIRST:
            {
                String stringValue = e.getConcreteValue();
                return mkStringConstant(stringValue);
            }
        default:
            throw new UnsupportedOperationException("Not implemented yet! " + op);
    }
}
Also used : Operator(org.evosuite.symbolic.expr.Operator) 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) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) LinkedList(java.util.LinkedList)

Example 14 with Operator

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

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

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