40
40
import org .sosy_lab .java_smt .api .FloatingPointNumber ;
41
41
import org .sosy_lab .java_smt .api .FloatingPointRoundingMode ;
42
42
import org .sosy_lab .java_smt .api .Formula ;
43
+ import org .sosy_lab .java_smt .api .FormulaManager ;
43
44
import org .sosy_lab .java_smt .api .FormulaType ;
44
45
import org .sosy_lab .java_smt .api .FormulaType .ArrayFormulaType ;
45
46
import org .sosy_lab .java_smt .api .FormulaType .BitvectorType ;
61
62
public class SolverVisitorTest extends SolverBasedTest0 .ParameterizedSolverBasedTest0 {
62
63
63
64
/** visit a formula and fail on OTHER, i.e., unexpected function declaration type. */
64
- private final class FunctionDeclarationVisitorNoOther
65
+ public static final class FunctionDeclarationVisitorNoOther
65
66
extends DefaultFormulaVisitor <List <FunctionDeclarationKind >> {
66
67
67
68
private final List <FunctionDeclarationKind > found = new ArrayList <>();
69
+ private final FormulaManager manager ;
70
+
71
+ FunctionDeclarationVisitorNoOther (FormulaManager pMgr ) {
72
+ manager = pMgr ;
73
+ }
68
74
69
75
@ Override
70
76
public List <FunctionDeclarationKind > visitFunction (
@@ -77,7 +83,7 @@ public List<FunctionDeclarationKind> visitFunction(
77
83
.that (functionDeclaration .getKind ())
78
84
.isNotEqualTo (FunctionDeclarationKind .OTHER );
79
85
for (Formula arg : args ) {
80
- mgr .visit (arg , this );
86
+ manager .visit (arg , this );
81
87
}
82
88
return visitDefault (f );
83
89
}
@@ -207,7 +213,7 @@ public void bitvectorIdVisit() throws SolverException, InterruptedException {
207
213
if (Solvers .PRINCESS != solver ) {
208
214
// Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
209
215
// The interval function is of FunctionDeclarationKind.OTHER and thus we cannot check it.
210
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
216
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
211
217
}
212
218
BooleanFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
213
219
assertThat (f2 ).isEqualTo (f );
@@ -239,7 +245,7 @@ public void bitvectorIdVisit() throws SolverException, InterruptedException {
239
245
if (Solvers .PRINCESS != solver ) {
240
246
// Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
241
247
// The interval function is of FunctionDeclarationKind.OTHER and thus we cannot check it.
242
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
248
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
243
249
}
244
250
BitvectorFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
245
251
assertThat (f2 ).isEqualTo (f );
@@ -258,7 +264,7 @@ public void bitvectorIdVisit2() throws SolverException, InterruptedException {
258
264
if (Solvers .PRINCESS != solver ) {
259
265
// Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
260
266
// The interval function is of FunctionDeclarationKind.OTHER and thus we cannot check it.
261
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
267
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
262
268
}
263
269
BitvectorFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
264
270
assertThat (f2 ).isEqualTo (f );
@@ -315,13 +321,13 @@ public void arrayVisit() {
315
321
316
322
ArrayFormula <IntegerFormula , IntegerFormula > arr = amgr .makeArray ("some_array" , arrayType );
317
323
IntegerFormula selectedElem = amgr .select (arr , index );
318
- assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther ()))
324
+ assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther (mgr )))
319
325
.containsExactly (FunctionDeclarationKind .SELECT );
320
326
assertThat (mgr .visit (selectedElem , new ConstantsVisitor (true )))
321
327
.containsExactly (BigInteger .valueOf (1 ));
322
328
323
329
ArrayFormula <IntegerFormula , IntegerFormula > store = amgr .store (arr , index , elem );
324
- assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther ()))
330
+ assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther (mgr )))
325
331
.containsExactly (FunctionDeclarationKind .STORE );
326
332
assertThat (mgr .visit (store , new ConstantsVisitor (true )))
327
333
.containsExactly (BigInteger .valueOf (1 ), BigInteger .valueOf (123 ));
@@ -332,7 +338,7 @@ public void arrayVisit() {
332
338
.isNotEqualTo (Solvers .OPENSMT );
333
339
334
340
ArrayFormula <IntegerFormula , IntegerFormula > initializedArr = amgr .makeArray (arrayType , elem );
335
- assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther ()))
341
+ assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther (mgr )))
336
342
.containsExactly (FunctionDeclarationKind .CONST );
337
343
assertThat (mgr .visit (initializedArr , new ConstantsVisitor (true )))
338
344
.containsExactly (BigInteger .valueOf (123 ));
@@ -351,13 +357,13 @@ public void arrayVisitBitvector() {
351
357
352
358
var arr = amgr .makeArray ("some_array" , arrayType );
353
359
BitvectorFormula selectedElem = amgr .select (arr , index );
354
- assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther ()))
360
+ assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther (mgr )))
355
361
.containsExactly (FunctionDeclarationKind .SELECT );
356
362
assertThat (mgr .visit (selectedElem , new ConstantsVisitor (true )))
357
363
.containsExactly (BigInteger .valueOf (17 ));
358
364
359
365
var store = amgr .store (arr , index , elem );
360
- assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther ()))
366
+ assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther (mgr )))
361
367
.containsExactly (FunctionDeclarationKind .STORE );
362
368
assertThat (mgr .visit (store , new ConstantsVisitor (true )))
363
369
.containsExactly (BigInteger .valueOf (17 ), BigInteger .valueOf (2 ));
@@ -368,7 +374,7 @@ public void arrayVisitBitvector() {
368
374
.isNotEqualTo (Solvers .OPENSMT );
369
375
370
376
var initializedArr = amgr .makeArray (arrayType , elem );
371
- assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther ()))
377
+ assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther (mgr )))
372
378
.containsExactly (FunctionDeclarationKind .CONST );
373
379
assertThat (mgr .visit (initializedArr , new ConstantsVisitor (true )))
374
380
.containsExactly (BigInteger .valueOf (2 ));
@@ -510,7 +516,7 @@ public void floatIdVisit() {
510
516
fpmgr .round (x , FloatingPointRoundingMode .TOWARD_POSITIVE ),
511
517
fpmgr .round (x , FloatingPointRoundingMode .TOWARD_NEGATIVE ),
512
518
fpmgr .round (x , FloatingPointRoundingMode .TOWARD_ZERO ))) {
513
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
519
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
514
520
mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
515
521
Formula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
516
522
assertThat (f2 ).isEqualTo (f );
@@ -715,7 +721,7 @@ public void stringInBooleanFormulaIdVisit() throws SolverException, InterruptedE
715
721
smgr .suffix (x , y ),
716
722
smgr .in (x , r ))) {
717
723
mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
718
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
724
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
719
725
BooleanFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
720
726
assertThat (f2 ).isEqualTo (f );
721
727
assertThatFormula (f ).isEquivalentTo (f2 );
@@ -743,7 +749,7 @@ public void stringInStringFormulaVisit() throws SolverException, InterruptedExce
743
749
}
744
750
for (StringFormula f : formulas .build ()) {
745
751
mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
746
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
752
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
747
753
StringFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
748
754
assertThat (f2 ).isEqualTo (f );
749
755
assertThatFormula (bmgr .not (smgr .equal (f , f2 ))).isUnsatisfiable ();
@@ -768,7 +774,7 @@ public void stringInRegexFormulaVisit() {
768
774
}
769
775
for (RegexFormula f : formulas .build ()) {
770
776
mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
771
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
777
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
772
778
RegexFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
773
779
assertThat (f2 ).isEqualTo (f );
774
780
}
@@ -784,15 +790,15 @@ public void stringInIntegerFormulaVisit() throws SolverException, InterruptedExc
784
790
for (IntegerFormula f :
785
791
ImmutableList .of (smgr .indexOf (x , y , offset ), smgr .length (x ), smgr .toIntegerFormula (x ))) {
786
792
mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
787
- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
793
+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
788
794
IntegerFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
789
795
assertThat (f2 ).isEqualTo (f );
790
796
assertThatFormula (bmgr .not (imgr .equal (f , f2 ))).isUnsatisfiable ();
791
797
}
792
798
}
793
799
794
800
private void checkKind (Formula f , FunctionDeclarationKind expected ) {
795
- FunctionDeclarationVisitorNoOther visitor = new FunctionDeclarationVisitorNoOther ();
801
+ FunctionDeclarationVisitorNoOther visitor = new FunctionDeclarationVisitorNoOther (mgr );
796
802
mgr .visit (f , visitor );
797
803
Truth .assert_ ()
798
804
.withMessage (
0 commit comments