/** * Try to minimize condition expression, as there are additional * assumptions that can be made when it is known that the final result * is a boolean. * * @return The replacement for n, or the original if no change was made. */ private Node tryMinimizeCondition(Node n) { n = performConditionSubstitutions(n); MinimizedCondition minCond = MinimizedCondition.fromConditionNode(n); return replaceNode( n, minCond.getMinimized(MinimizationStyle.PREFER_UNNEGATED)); }
/** * Try to minimize condition expression, as there are additional * assumptions that can be made when it is known that the final result * is a boolean. * * @return The replacement for n, or the original if no change was made. */ private Node tryMinimizeCondition(Node n) { n = performConditionSubstitutions(n); MinimizedCondition minCond = MinimizedCondition.fromConditionNode(n); return replaceNode( minCond.getPlaceholder(), minCond.getMinimized(MinimizationStyle.PREFER_UNNEGATED)); }
/** * Try to remove leading NOTs from EXPR_RESULTS. * * Returns the replacement for n or the original if no replacement was * necessary. */ private Node tryMinimizeExprResult(Node n) { Node originalExpr = n.getFirstChild(); MinimizedCondition minCond = MinimizedCondition.fromConditionNode(originalExpr); MeasuredNode mNode = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT); if (mNode.isNot()) { // Remove the leading NOT in the EXPR_RESULT. replaceNode(originalExpr, mNode.withoutNot()); } else { replaceNode(originalExpr, mNode); } return n; }
/** * Try to remove leading NOTs from EXPR_RESULTS. * * Returns the replacement for n or the original if no replacement was * necessary. */ private Node tryMinimizeExprResult(Node n) { MinimizedCondition minCond = MinimizedCondition.fromConditionNode(n.getFirstChild()); MinimizedCondition.MeasuredNode mNode = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT); Node placeholder = minCond.getPlaceholder(); if (mNode.getNode().isNot()) { // Remove the leading NOT in the EXPR_RESULT. n.replaceChild(placeholder, mNode.getNode().removeFirstChild()); reportCodeChange(); } else { replaceNode(placeholder, mNode); } return n; }
/** * Try flipping HOOKs that have negated conditions. * * Returns the replacement for n or the original if no replacement was * necessary. */ private Node tryMinimizeHook(Node n) { Node originalCond = n.getFirstChild(); MinimizedCondition minCond = MinimizedCondition.fromConditionNode(originalCond); MeasuredNode mNode = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT); if (mNode.isNot()) { // Swap the HOOK Node thenBranch = n.getSecondChild(); replaceNode(originalCond, mNode.withoutNot()); n.removeChild(thenBranch); n.addChildToBack(thenBranch); reportChangeToEnclosingScope(n); } else { replaceNode(originalCond, mNode); } return n; }
/** * Try flipping HOOKs that have negated conditions. * * Returns the replacement for n or the original if no replacement was * necessary. */ private Node tryMinimizeHook(Node n) { MinimizedCondition minCond = MinimizedCondition.fromConditionNode(n.getFirstChild()); MinimizedCondition.MeasuredNode mNode = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT); Node placeholder = minCond.getPlaceholder(); if (mNode.getNode().isNot()) { // Swap the HOOK Node thenBranch = n.getSecondChild(); n.replaceChild(placeholder, mNode.getNode().removeFirstChild()); n.removeChild(thenBranch); n.addChildToBack(thenBranch); reportCodeChange(); } else { replaceNode(placeholder, mNode); } return n; }
MeasuredNode unnegatedCond = minCond.getMinimized(MinimizationStyle.PREFER_UNNEGATED); MeasuredNode shortCond = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT);
unnegatedCond = minCond.getMinimized(MinimizationStyle.PREFER_UNNEGATED); shortCond = minCond.getMinimized(MinimizationStyle.ALLOW_LEADING_NOT);