use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ConstraintToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(RealConstraint c, Void arg) {
ExprToZ3Str2Visitor v = new ExprToZ3Str2Visitor();
SmtExpr left = c.getLeftOperand().accept(v, null);
SmtExpr right = c.getRightOperand().accept(v, null);
if (left == null || right == null) {
return null;
}
Comparator cmp = c.getComparator();
return mkComparison(left, cmp, right);
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class Z3QueryPrinter method print.
public String print(SmtCheckSatQuery smtQuery, long timeout) {
StringBuffer buff = new StringBuffer();
buff.append("(set-option :timeout " + timeout + ")");
buff.append("\n");
for (SmtConstantDeclaration constantDeclaration : smtQuery.getConstantDeclarations()) {
String str = String.format("(declare-const %s %s)", constantDeclaration.getConstantName(), constantDeclaration.getConstantSort());
buff.append(str);
buff.append("\n");
}
SmtExprPrinter printer = new SmtExprPrinter();
for (SmtAssertion assertionDeclaration : smtQuery.getAssertions()) {
SmtExpr formula = assertionDeclaration.getFormula();
String formulaStr = formula.accept(printer, null);
String str = String.format("(assert %s)", formulaStr);
buff.append(str);
buff.append("\n");
}
buff.append("(check-sat)");
buff.append("\n");
buff.append("(get-model)");
buff.append("\n");
buff.append("(exit)");
buff.append("\n");
return buff.toString();
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(StringReaderExpr e, Void arg) {
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 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);
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(RealBinaryExpression e, Void arg) {
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()) {
double doubleValue = e.getConcreteValue();
return mkRepresentableRealConstant(doubleValue);
}
switch(e.getOperator()) {
case DIV:
{
SmtExpr divExpr = SmtExprBuilder.mkRealDiv(left, right);
return divExpr;
}
case MUL:
{
SmtExpr mulExpr = SmtExprBuilder.mkMul(left, right);
return mulExpr;
}
case MINUS:
{
SmtExpr subExpr = SmtExprBuilder.mkSub(left, right);
return subExpr;
}
case PLUS:
{
SmtExpr addExpr = SmtExprBuilder.mkAdd(left, right);
return addExpr;
}
case MAX:
{
SmtExpr left_gt_right = SmtExprBuilder.mkGt(left, right);
SmtExpr ite_expr = SmtExprBuilder.mkITE(left_gt_right, left, right);
return ite_expr;
}
case MIN:
{
SmtExpr left_gt_right = SmtExprBuilder.mkLt(left, right);
SmtExpr ite_expr = SmtExprBuilder.mkITE(left_gt_right, left, right);
return ite_expr;
}
case ATAN2:
case COPYSIGN:
case HYPOT:
case NEXTAFTER:
case POW:
case SCALB:
case IEEEREMAINDER:
case REM:
{
Double concreteValue = e.getConcreteValue();
if (!isRepresentable(concreteValue)) {
return null;
} else {
return SmtExprBuilder.mkRealConstant(concreteValue);
}
}
default:
{
throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
}
}
}
Aggregations