use of org.evosuite.symbolic.solver.smt.SmtExpr 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);
}
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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);
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(RealToIntegerCast n, Void arg) {
SmtExpr operandExpr = n.getArgument().accept(this, null);
if (operandExpr == null) {
return null;
}
if (!operandExpr.isSymbolic()) {
long longValue = n.getConcreteValue();
return SmtExprBuilder.mkIntConstant(longValue);
}
SmtExpr realToIntStr = SmtExprBuilder.mkReal2Int(operandExpr);
return realToIntStr;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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);
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(IntegerUnaryExpression e, Void v) {
SmtExpr intExpr = e.getOperand().accept(this, null);
if (intExpr == null) {
return null;
}
if (!intExpr.isSymbolic()) {
long longValue = e.getConcreteValue();
return SmtExprBuilder.mkIntConstant(longValue);
}
switch(e.getOperator()) {
case NEG:
{
SmtExpr minus_expr = SmtExprBuilder.mkNeg(intExpr);
return minus_expr;
}
case GETNUMERICVALUE:
case ISDIGIT:
case ISLETTER:
{
long longValue = e.getConcreteValue();
return SmtExprBuilder.mkIntConstant(longValue);
}
case ABS:
SmtExpr zero = SmtExprBuilder.mkIntConstant(0);
SmtExpr gte_than_zero = SmtExprBuilder.mkGe(intExpr, zero);
SmtExpr minus_expr = SmtExprBuilder.mkNeg(intExpr);
SmtExpr ite_expr = SmtExprBuilder.mkITE(gte_than_zero, intExpr, minus_expr);
return ite_expr;
default:
throw new UnsupportedOperationException("Not implemented yet!" + e.getOperator());
}
}
Aggregations