use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToCVC4Visitor method visit.
@Override
public SmtExpr visit(HasMoreTokensExpr e, Void v) {
long longValue = e.getConcreteValue();
SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
return intConst;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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);
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToCVC4Visitor method visit.
@Override
public SmtExpr visit(StringToIntegerCast e, Void v) {
SmtExpr argument = e.getArgument().accept(this, null);
if (argument == null) {
return null;
}
if (!argument.isSymbolic()) {
long concreteValue = e.getConcreteValue();
return SmtExprBuilder.mkIntConstant(concreteValue);
}
SmtExpr argumentExpr = SmtExprBuilder.mkStrToInt(argument);
return argumentExpr;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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");
}
}
Aggregations