4040import org .sosy_lab .java_smt .api .FloatingPointNumber ;
4141import org .sosy_lab .java_smt .api .FloatingPointRoundingMode ;
4242import org .sosy_lab .java_smt .api .Formula ;
43+ import org .sosy_lab .java_smt .api .FormulaManager ;
4344import org .sosy_lab .java_smt .api .FormulaType ;
4445import org .sosy_lab .java_smt .api .FormulaType .ArrayFormulaType ;
4546import org .sosy_lab .java_smt .api .FormulaType .BitvectorType ;
6162public class SolverVisitorTest extends SolverBasedTest0 .ParameterizedSolverBasedTest0 {
6263
6364 /** visit a formula and fail on OTHER, i.e., unexpected function declaration type. */
64- private final class FunctionDeclarationVisitorNoOther
65+ public static final class FunctionDeclarationVisitorNoOther
6566 extends DefaultFormulaVisitor <List <FunctionDeclarationKind >> {
6667
6768 private final List <FunctionDeclarationKind > found = new ArrayList <>();
69+ private final FormulaManager manager ;
70+
71+ FunctionDeclarationVisitorNoOther (FormulaManager pMgr ) {
72+ manager = pMgr ;
73+ }
6874
6975 @ Override
7076 public List <FunctionDeclarationKind > visitFunction (
@@ -77,7 +83,7 @@ public List<FunctionDeclarationKind> visitFunction(
7783 .that (functionDeclaration .getKind ())
7884 .isNotEqualTo (FunctionDeclarationKind .OTHER );
7985 for (Formula arg : args ) {
80- mgr .visit (arg , this );
86+ manager .visit (arg , this );
8187 }
8288 return visitDefault (f );
8389 }
@@ -207,7 +213,7 @@ public void bitvectorIdVisit() throws SolverException, InterruptedException {
207213 if (Solvers .PRINCESS != solver ) {
208214 // Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
209215 // 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 ));
211217 }
212218 BooleanFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
213219 assertThat (f2 ).isEqualTo (f );
@@ -239,7 +245,7 @@ public void bitvectorIdVisit() throws SolverException, InterruptedException {
239245 if (Solvers .PRINCESS != solver ) {
240246 // Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
241247 // 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 ));
243249 }
244250 BitvectorFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
245251 assertThat (f2 ).isEqualTo (f );
@@ -258,7 +264,7 @@ public void bitvectorIdVisit2() throws SolverException, InterruptedException {
258264 if (Solvers .PRINCESS != solver ) {
259265 // Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
260266 // 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 ));
262268 }
263269 BitvectorFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
264270 assertThat (f2 ).isEqualTo (f );
@@ -315,13 +321,13 @@ public void arrayVisit() {
315321
316322 ArrayFormula <IntegerFormula , IntegerFormula > arr = amgr .makeArray ("some_array" , arrayType );
317323 IntegerFormula selectedElem = amgr .select (arr , index );
318- assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther ()))
324+ assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther (mgr )))
319325 .containsExactly (FunctionDeclarationKind .SELECT );
320326 assertThat (mgr .visit (selectedElem , new ConstantsVisitor (true )))
321327 .containsExactly (BigInteger .valueOf (1 ));
322328
323329 ArrayFormula <IntegerFormula , IntegerFormula > store = amgr .store (arr , index , elem );
324- assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther ()))
330+ assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther (mgr )))
325331 .containsExactly (FunctionDeclarationKind .STORE );
326332 assertThat (mgr .visit (store , new ConstantsVisitor (true )))
327333 .containsExactly (BigInteger .valueOf (1 ), BigInteger .valueOf (123 ));
@@ -332,7 +338,7 @@ public void arrayVisit() {
332338 .isNotEqualTo (Solvers .OPENSMT );
333339
334340 ArrayFormula <IntegerFormula , IntegerFormula > initializedArr = amgr .makeArray (arrayType , elem );
335- assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther ()))
341+ assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther (mgr )))
336342 .containsExactly (FunctionDeclarationKind .CONST );
337343 assertThat (mgr .visit (initializedArr , new ConstantsVisitor (true )))
338344 .containsExactly (BigInteger .valueOf (123 ));
@@ -351,13 +357,13 @@ public void arrayVisitBitvector() {
351357
352358 var arr = amgr .makeArray ("some_array" , arrayType );
353359 BitvectorFormula selectedElem = amgr .select (arr , index );
354- assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther ()))
360+ assertThat (mgr .visit (selectedElem , new FunctionDeclarationVisitorNoOther (mgr )))
355361 .containsExactly (FunctionDeclarationKind .SELECT );
356362 assertThat (mgr .visit (selectedElem , new ConstantsVisitor (true )))
357363 .containsExactly (BigInteger .valueOf (17 ));
358364
359365 var store = amgr .store (arr , index , elem );
360- assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther ()))
366+ assertThat (mgr .visit (store , new FunctionDeclarationVisitorNoOther (mgr )))
361367 .containsExactly (FunctionDeclarationKind .STORE );
362368 assertThat (mgr .visit (store , new ConstantsVisitor (true )))
363369 .containsExactly (BigInteger .valueOf (17 ), BigInteger .valueOf (2 ));
@@ -368,7 +374,7 @@ public void arrayVisitBitvector() {
368374 .isNotEqualTo (Solvers .OPENSMT );
369375
370376 var initializedArr = amgr .makeArray (arrayType , elem );
371- assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther ()))
377+ assertThat (mgr .visit (initializedArr , new FunctionDeclarationVisitorNoOther (mgr )))
372378 .containsExactly (FunctionDeclarationKind .CONST );
373379 assertThat (mgr .visit (initializedArr , new ConstantsVisitor (true )))
374380 .containsExactly (BigInteger .valueOf (2 ));
@@ -510,7 +516,7 @@ public void floatIdVisit() {
510516 fpmgr .round (x , FloatingPointRoundingMode .TOWARD_POSITIVE ),
511517 fpmgr .round (x , FloatingPointRoundingMode .TOWARD_NEGATIVE ),
512518 fpmgr .round (x , FloatingPointRoundingMode .TOWARD_ZERO ))) {
513- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
519+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
514520 mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
515521 Formula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
516522 assertThat (f2 ).isEqualTo (f );
@@ -715,7 +721,7 @@ public void stringInBooleanFormulaIdVisit() throws SolverException, InterruptedE
715721 smgr .suffix (x , y ),
716722 smgr .in (x , r ))) {
717723 mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
718- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
724+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
719725 BooleanFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
720726 assertThat (f2 ).isEqualTo (f );
721727 assertThatFormula (f ).isEquivalentTo (f2 );
@@ -743,7 +749,7 @@ public void stringInStringFormulaVisit() throws SolverException, InterruptedExce
743749 }
744750 for (StringFormula f : formulas .build ()) {
745751 mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
746- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
752+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
747753 StringFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
748754 assertThat (f2 ).isEqualTo (f );
749755 assertThatFormula (bmgr .not (smgr .equal (f , f2 ))).isUnsatisfiable ();
@@ -768,7 +774,7 @@ public void stringInRegexFormulaVisit() {
768774 }
769775 for (RegexFormula f : formulas .build ()) {
770776 mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
771- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
777+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
772778 RegexFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
773779 assertThat (f2 ).isEqualTo (f );
774780 }
@@ -784,15 +790,15 @@ public void stringInIntegerFormulaVisit() throws SolverException, InterruptedExc
784790 for (IntegerFormula f :
785791 ImmutableList .of (smgr .indexOf (x , y , offset ), smgr .length (x ), smgr .toIntegerFormula (x ))) {
786792 mgr .visit (f , new FunctionDeclarationVisitorNoUF ());
787- mgr .visit (f , new FunctionDeclarationVisitorNoOther ());
793+ mgr .visit (f , new FunctionDeclarationVisitorNoOther (mgr ));
788794 IntegerFormula f2 = mgr .transformRecursively (f , new FormulaTransformationVisitor (mgr ) {});
789795 assertThat (f2 ).isEqualTo (f );
790796 assertThatFormula (bmgr .not (imgr .equal (f , f2 ))).isUnsatisfiable ();
791797 }
792798 }
793799
794800 private void checkKind (Formula f , FunctionDeclarationKind expected ) {
795- FunctionDeclarationVisitorNoOther visitor = new FunctionDeclarationVisitorNoOther ();
801+ FunctionDeclarationVisitorNoOther visitor = new FunctionDeclarationVisitorNoOther (mgr );
796802 mgr .visit (f , visitor );
797803 Truth .assert_ ()
798804 .withMessage (
0 commit comments