@@ -28,15 +28,16 @@ private static ValDerivationNode simplifyToFixedPoint(ValDerivationNode current,
2828 // apply propagation and folding
2929 ValDerivationNode prop = ConstantPropagation .propagate (prevExp , current );
3030 ValDerivationNode fold = ConstantFolding .fold (prop );
31- Expression currExp = fold .getValue ();
31+ ValDerivationNode simplified = simplifyValDerivationNode (fold );
32+ Expression currExp = simplified .getValue ();
3233
3334 // fixed point reached
3435 if (current != null && currExp .equals (current .getValue ())) {
3536 return current ;
3637 }
3738
3839 // continue simplifying
39- return simplifyToFixedPoint (fold , current , fold .getValue ());
40+ return simplifyToFixedPoint (simplified , current , simplified .getValue ());
4041 }
4142
4243 /**
@@ -75,41 +76,10 @@ private static ValDerivationNode simplifyValDerivationNode(ValDerivationNode nod
7576 DerivationNode newOrigin = new BinaryDerivationNode (leftSimplified , rightSimplified , "&&" );
7677 return new ValDerivationNode (newValue , newOrigin );
7778 }
78-
79- // simplify origin
80- DerivationNode simplifiedOrigin = simplifyDerivationNode (origin );
81- if (simplifiedOrigin != origin ) {
82- return new ValDerivationNode (value , simplifiedOrigin );
83- }
84-
8579 // no simplification
8680 return node ;
8781 }
8882
89- private static DerivationNode simplifyDerivationNode (DerivationNode node ) {
90- if (node == null )
91- return null ;
92- if (node instanceof ValDerivationNode val ) {
93- return simplifyValDerivationNode (val );
94- }
95- if (node instanceof BinaryDerivationNode binary ) {
96- ValDerivationNode left = simplifyValDerivationNode (binary .getLeft ());
97- ValDerivationNode right = simplifyValDerivationNode (binary .getRight ());
98- if (left != binary .getLeft () || right != binary .getRight ()) {
99- return new BinaryDerivationNode (left , right , binary .getOp ());
100- }
101- return binary ;
102- }
103- if (node instanceof UnaryDerivationNode unary ) {
104- ValDerivationNode operand = simplifyValDerivationNode (unary .getOperand ());
105- if (operand != unary .getOperand ()) {
106- return new UnaryDerivationNode (operand , unary .getOp ());
107- }
108- return unary ;
109- }
110- return node ;
111- }
112-
11383 /**
11484 * Checks if an expression is redundant (e.g. true or x == x)
11585 */
0 commit comments