diff options
Diffstat (limited to 'chapter10/src/main/java/com/seaofnodes')
| -rw-r--r-- | chapter10/src/main/java/com/seaofnodes/simple/node/ScopeNode.java | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/chapter10/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter10/src/main/java/com/seaofnodes/simple/node/ScopeNode.java index 843ce733..455f4b3a 100644 --- a/chapter10/src/main/java/com/seaofnodes/simple/node/ScopeNode.java +++ b/chapter10/src/main/java/com/seaofnodes/simple/node/ScopeNode.java @@ -254,6 +254,13 @@ public class ScopeNode extends Node { // combinations, and replaces the variable with the upcast variant. public Node upcast( Node ctrl, Node pred, boolean invert ) { if( ctrl._type==Type.XCONTROL ) return null; + // A single negation is handled below. For !!p (including p != null), + // also refine the underlying p without changing the Boolean result. + if( pred instanceof NotNode not && not.in(1) instanceof NotNode ) { + pred.keep(); // Recursive peepholes may rediscover this Not. + upcast(ctrl,not.in(1),!invert); + pred.unkeep(); + } // Invert the If conditional if( invert ) pred = pred instanceof NotNode not ? not.in(1) : IterPeeps.add(new NotNode(pred).peephole()); |
