use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class ExprToCVC4Visitor method visit.
@Override
public SmtExpr visit(StringBinaryExpression 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()) {
String stringValue = e.getConcreteValue();
SmtExpr strConstant = SmtExprBuilder.mkStringConstant(stringValue);
return strConstant;
}
Operator op = e.getOperator();
switch(op) {
case CONCAT:
{
SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, right);
return concatExpr;
}
case APPEND_STRING:
{
SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, right);
return concatExpr;
}
case APPEND_INTEGER:
{
SmtExpr rigthStr = SmtExprBuilder.mkIntToStr(right);
SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, rigthStr);
return concatExpr;
}
case APPEND_BOOLEAN:
{
SmtIntConstant zero = SmtExprBuilder.ZERO_INT;
SmtExpr eqZero = SmtExprBuilder.mkEq(right, zero);
SmtStringConstant falseConstantExpr = SmtExprBuilder.mkStringConstant(String.valueOf(Boolean.FALSE));
SmtStringConstant trueConstantExpr = SmtExprBuilder.mkStringConstant(String.valueOf(Boolean.TRUE));
SmtExpr ite = SmtExprBuilder.mkITE(eqZero, falseConstantExpr, trueConstantExpr);
SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, ite);
return concatExpr;
}
case APPEND_CHAR:
{
SmtExpr rigthStr = SmtExprBuilder.mkIntToChar(right);
SmtExpr concatExpr = SmtExprBuilder.mkStrConcat(left, rigthStr);
return concatExpr;
}
case APPEND_REAL:
{
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(StringBinaryComparison e, Void v) {
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();
SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
return intConst;
}
SmtIntConstant oneConstant = SmtExprBuilder.ONE_INT;
SmtIntConstant zeroConstant = SmtExprBuilder.ZERO_INT;
switch(op) {
case EQUALS:
{
SmtExpr equalsFormula = SmtExprBuilder.mkEq(left, right);
SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(equalsFormula, oneConstant, zeroConstant);
return ifThenElseFormula;
}
case ENDSWITH:
{
SmtExpr endsWithExpr = SmtExprBuilder.mkStrSuffixOf(right, left);
SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(endsWithExpr, oneConstant, zeroConstant);
return ifThenElseFormula;
}
case CONTAINS:
{
SmtExpr equalsFormula = SmtExprBuilder.mkStrContains(left, right);
SmtExpr ifThenElseFormula = SmtExprBuilder.mkITE(equalsFormula, oneConstant, zeroConstant);
return ifThenElseFormula;
}
case STARTSWITH:
{
throw new IllegalArgumentException("Illegal StringBinaryComparison operator " + op);
}
case PATTERNMATCHES:
{
String regex = e.getLeftOperand().getConcreteValue();
String expandedRegex = RegexDistanceUtils.expandRegex(regex);
RegExp regexp = new RegExp(expandedRegex, RegExp.INTERSECTION);
RegExpToCVC4Visitor visitor = new RegExpToCVC4Visitor();
SmtExpr regExpSmtExpr = visitor.visitRegExp(regexp);
if (regExpSmtExpr == null) {
long longValue = e.getConcreteValue();
SmtExpr intConst = SmtExprBuilder.mkIntConstant(longValue);
return intConst;
} else {
SmtExpr strInRegExp = SmtExprBuilder.mkStrInRegExp(right, regExpSmtExpr);
SmtExpr iteExpr = SmtExprBuilder.mkITE(strInRegExp, SmtExprBuilder.ONE_INT, SmtExprBuilder.ZERO_INT);
return iteExpr;
}
}
case EQUALSIGNORECASE:
case REGIONMATCHES:
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 RegExpToCVC4Visitor method visitOptional.
@Override
public SmtExpr visitOptional(RegExp e) {
SmtExpr expr = this.visitRegExp(e);
if (expr == null) {
return null;
}
SmtExpr optExpr = SmtExprBuilder.mkRegExpOptional(expr);
return optExpr;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class RegExpToCVC4Visitor method visitUnion.
@Override
public SmtExpr visitUnion(RegExp left, RegExp right) {
SmtExpr leftExpr = visitRegExp(left);
SmtExpr rightExpr = visitRegExp(right);
if (leftExpr == null || rightExpr == null) {
return null;
}
SmtExpr unionExpr = SmtExprBuilder.mkRegExpUnion(leftExpr, rightExpr);
return unionExpr;
}
use of org.evosuite.symbolic.solver.smt.SmtExpr in project evosuite by EvoSuite.
the class RegExpToCVC4Visitor method visitRepeat.
@Override
public SmtExpr visitRepeat(RegExp arg) {
SmtExpr expr = this.visitRegExp(arg);
if (expr == null) {
return null;
}
SmtExpr repeatExpr = SmtExprBuilder.mkReKleeneStar(expr);
return repeatExpr;
}
Aggregations