Skip to content

Commit 8d5fcd1

Browse files
Princess: Handle all constant values for the visitor in isValue()
1 parent ccc8cbe commit 8d5fcd1

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

src/org/sosy_lab/java_smt/solvers/princess/PrincessFormulaCreator.java

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import static scala.collection.JavaConverters.asJava;
1616
import static scala.collection.JavaConverters.asJavaCollection;
1717

18-
import ap.basetypes.IdealInt;
1918
import ap.parser.IAtom;
2019
import ap.parser.IBinFormula;
2120
import ap.parser.IBinJunctor;
@@ -364,30 +363,38 @@ private String getName(IExpression input) {
364363
}
365364

366365
/** Returns true if the expression is a constant value. */
367-
private static boolean isValue(IFunApp pExpr) {
368-
if (!pExpr.fun().equals(Rationals.frac()) && !pExpr.fun().equals(Rationals.fromRing())) {
369-
return false;
370-
}
371-
for (IExpression sub : asJava(pExpr.args())) {
372-
if (!(sub instanceof IIntLit)) {
373-
return false;
366+
private static boolean isValue(IExpression input) {
367+
if (input instanceof IBoolLit || input instanceof IIntLit) {
368+
// Boolean or integer literal
369+
return true;
370+
} else if (input instanceof IFunApp) {
371+
IFunApp app = (IFunApp) input;
372+
IFunction fun = app.fun();
373+
if (fun.equals(Rationals.fromRing()) || fun.equals(Rationals.frac())) {
374+
// Rational number literal
375+
for (IExpression sub : asJava(app.args())) {
376+
if (!(sub instanceof IIntLit)) {
377+
return false;
378+
}
379+
}
380+
return true;
381+
}
382+
if (fun.equals(ModuloArithmetic.mod_cast()) && input.apply(2) instanceof IIntLit) {
383+
// Bitvector literal
384+
return true;
385+
}
386+
if (CONSTANT_UFS.contains(fun.name())) {
387+
// Nil, Cons from String theory
388+
return true;
374389
}
375390
}
376-
return true;
391+
return false;
377392
}
378393

379394
@SuppressWarnings("deprecation")
380395
@Override
381396
public <R> R visit(FormulaVisitor<R> visitor, final Formula f, final IExpression input) {
382-
if (input instanceof IIntLit) {
383-
IdealInt value = ((IIntLit) input).value();
384-
return visitor.visitConstant(f, value.bigIntValue());
385-
386-
} else if (input instanceof IBoolLit) {
387-
IBoolLit literal = (IBoolLit) input;
388-
return visitor.visitConstant(f, literal.value());
389-
390-
} else if (input instanceof IFunApp && isValue((IFunApp) input)) {
397+
if (isValue(input)) {
391398
return visitor.visitConstant(f, convertValue(input));
392399

393400
} else if (input instanceof IQuantified) {
@@ -462,20 +469,6 @@ public <R> R visit(FormulaVisitor<R> visitor, final Formula f, final IExpression
462469
return visit(visitor, f, ((IIntFormula) input).t());
463470
}
464471

465-
if (kind == FunctionDeclarationKind.OTHER && input instanceof IFunApp) {
466-
if (ModuloArithmetic.mod_cast().equals(((IFunApp) input).fun())
467-
&& ((IFunApp) input).apply(2) instanceof IIntLit) {
468-
// mod_cast(0, 256, 7) -> BV=7 with bitsize=8
469-
return visitor.visitConstant(f, convertValue(input));
470-
}
471-
}
472-
473-
if (kind == FunctionDeclarationKind.UF && input instanceof IFunApp) {
474-
if (CONSTANT_UFS.contains(((IFunApp) input).fun().name())) {
475-
return visitor.visitConstant(f, convertValue(input));
476-
}
477-
}
478-
479472
ImmutableList.Builder<Formula> args = ImmutableList.builder();
480473
ImmutableList.Builder<FormulaType<?>> argTypes = ImmutableList.builder();
481474
int arity = input.length();

0 commit comments

Comments
 (0)