use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToZ3Str2Visitor method visit.
@Override
public SmtExpr visit(HasMoreTokensExpr 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(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());
}
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr 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!");
}
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class CVC4Solver method buildSmtCheckSatQuery.
private static SmtCheckSatQuery buildSmtCheckSatQuery(Collection<Constraint<?>> constraints) {
ConstraintToCVC4Visitor v = new ConstraintToCVC4Visitor(true);
SmtVariableCollector varCollector = new SmtVariableCollector();
SmtOperatorCollector funCollector = new SmtOperatorCollector();
List<SmtAssertion> smtAssertions = new LinkedList<SmtAssertion>();
for (Constraint<?> c : constraints) {
SmtExpr smtExpr = c.accept(v, null);
if (smtExpr != null) {
SmtAssertion smtAssertion = new SmtAssertion(smtExpr);
smtAssertions.add(smtAssertion);
smtExpr.accept(varCollector, null);
smtExpr.accept(funCollector, null);
}
}
Set<SmtVariable> variables = varCollector.getSmtVariables();
if (variables.isEmpty()) {
// no variables, constraint system is trivial
return null;
}
List<SmtFunctionDefinition> functionDefinitions = new LinkedList<SmtFunctionDefinition>();
final boolean addCharToInt = funCollector.getOperators().contains(Operator.CHAR_TO_INT);
if (addCharToInt) {
String charToIntFunction = buildCharToIntFunction();
SmtFunctionDefinition funcDefinition = new SmtFunctionDefinition(charToIntFunction);
functionDefinitions.add(funcDefinition);
}
final boolean addIntToChar = funCollector.getOperators().contains(Operator.INT_TO_CHAR);
if (addIntToChar) {
String intToCharFunction = buildIntToCharFunction();
SmtFunctionDefinition funcDefinition = new SmtFunctionDefinition(intToCharFunction);
functionDefinitions.add(funcDefinition);
}
List<SmtFunctionDeclaration> functionDeclarations = new LinkedList<SmtFunctionDeclaration>();
for (SmtVariable var : variables) {
String varName = var.getName();
if (var instanceof SmtIntVariable) {
SmtFunctionDeclaration intVar = SmtExprBuilder.mkIntFunctionDeclaration(varName);
functionDeclarations.add(intVar);
} else if (var instanceof SmtRealVariable) {
SmtFunctionDeclaration realVar = SmtExprBuilder.mkRealFunctionDeclaration(varName);
functionDeclarations.add(realVar);
} else if (var instanceof SmtStringVariable) {
SmtFunctionDeclaration stringVar = SmtExprBuilder.mkStringFunctionDeclaration(varName);
functionDeclarations.add(stringVar);
} else {
throw new RuntimeException("Unknown variable type " + var.getClass().getCanonicalName());
}
}
SmtCheckSatQuery smtQuery = new SmtCheckSatQuery(new LinkedList<SmtConstantDeclaration>(), functionDeclarations, functionDefinitions, smtAssertions);
return smtQuery;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToCVC4Visitor method visit.
@Override
public SmtExpr visit(RealBinaryExpression 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()) {
double doubleValue = e.getConcreteValue();
return SmtExprBuilder.mkRealConstant(doubleValue);
}
switch(e.getOperator()) {
case DIV:
{
if (rewriteNonLinearExpressions) {
if (left.isSymbolic() && right.isSymbolic()) {
RealValue r = (RealValue) e.getRightOperand();
double rightValue = r.getConcreteValue();
SmtExpr conc_right = SmtExprBuilder.mkRealConstant(rightValue);
SmtExpr rewrite_expr = SmtExprBuilder.mkRealDiv(left, conc_right);
return rewrite_expr;
}
}
SmtExpr expr = SmtExprBuilder.mkRealDiv(left, right);
return expr;
}
case MUL:
{
if (rewriteNonLinearExpressions) {
if (left.isSymbolic() && right.isSymbolic()) {
RealValue r = (RealValue) e.getRightOperand();
double rightValue = r.getConcreteValue();
SmtExpr conc_right = SmtExprBuilder.mkRealConstant(rightValue);
SmtExpr rewrite_expr = SmtExprBuilder.mkMul(left, conc_right);
return rewrite_expr;
}
}
SmtExpr expr = SmtExprBuilder.mkMul(left, right);
return expr;
}
case MINUS:
{
SmtExpr expr = SmtExprBuilder.mkSub(left, right);
return expr;
}
case PLUS:
{
SmtExpr expr = SmtExprBuilder.mkAdd(left, right);
return expr;
}
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();
SmtExpr realConstant = createRatNumber(concreteValue);
return realConstant;
}
default:
{
throw new UnsupportedOperationException("Not implemented yet! " + e.getOperator());
}
}
}
Aggregations