use of org.evosuite.symbolic.solver.smt.SmtOperation.Operator in project evosuite by EvoSuite.
the class Z3Str2Solver method buildSmtQuerty.
private static SmtCheckSatQuery buildSmtQuerty(Collection<Constraint<?>> constraints) {
ConstraintToZ3Str2Visitor v = new ConstraintToZ3Str2Visitor();
List<SmtAssertion> assertions = new LinkedList<SmtAssertion>();
SmtVariableCollector varCollector = new SmtVariableCollector();
SmtOperatorCollector opCollector = new SmtOperatorCollector();
for (Constraint<?> c : constraints) {
SmtExpr smtExpr = c.accept(v, null);
if (smtExpr != null) {
SmtAssertion newAssertion = new SmtAssertion(smtExpr);
assertions.add(newAssertion);
smtExpr.accept(varCollector, null);
smtExpr.accept(opCollector, null);
}
}
Set<SmtVariable> smtVariables = varCollector.getSmtVariables();
Set<Operator> smtOperators = opCollector.getOperators();
boolean addCharToIntFunction;
if (smtOperators.contains(SmtOperation.Operator.CHAR_TO_INT)) {
addCharToIntFunction = true;
} else {
addCharToIntFunction = false;
}
Set<SmtVariable> smtVariablesToDeclare = new HashSet<SmtVariable>(smtVariables);
if (addCharToIntFunction) {
Set<SmtStringVariable> charVariables = buildCharVariables();
smtVariablesToDeclare.addAll(charVariables);
}
List<SmtConstantDeclaration> constantDeclarations = new LinkedList<SmtConstantDeclaration>();
for (SmtVariable v1 : smtVariablesToDeclare) {
String varName = v1.getName();
if (v1 instanceof SmtIntVariable) {
SmtConstantDeclaration constantDecl = SmtExprBuilder.mkIntConstantDeclaration(varName);
constantDeclarations.add(constantDecl);
} else if (v1 instanceof SmtRealVariable) {
SmtConstantDeclaration constantDecl = SmtExprBuilder.mkRealConstantDeclaration(varName);
constantDeclarations.add(constantDecl);
} else if (v1 instanceof SmtStringVariable) {
SmtConstantDeclaration constantDecl = SmtExprBuilder.mkStringConstantDeclaration(varName);
constantDeclarations.add(constantDecl);
} else {
throw new RuntimeException("Unknown variable type " + v1.getClass().getCanonicalName());
}
}
List<SmtFunctionDefinition> functionDefinitions = new LinkedList<SmtFunctionDefinition>();
if (addCharToIntFunction) {
String charToInt = buildCharToIntFunction();
SmtFunctionDefinition newFunctionDef = new SmtFunctionDefinition(charToInt);
functionDefinitions.add(newFunctionDef);
}
SmtCheckSatQuery smtCheckSatQuery = new SmtCheckSatQuery(constantDeclarations, functionDefinitions, assertions);
return smtCheckSatQuery;
}
Aggregations