@Override public boolean apply(EdgeTuple<Node, Branch> input) { Branch branch = input.edge; if (!branch.isConditional()) { return true; } Node predecessor = input.sourceNode; Node condition = NodeUtil.getConditionExpression(predecessor); // TODO(user): Handle more complicated expression like true == true, // etc.... if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (branch == Branch.ON_TRUE); } } return true; } };
@Override public boolean apply(EdgeTuple<Node, Branch> input) { Branch branch = input.edge; if (!branch.isConditional()) { return true; } Node predecessor = input.sourceNode; Node condition = NodeUtil.getConditionExpression(predecessor); // TODO(user): Handle more complicated expression like true == true, // etc.... if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (branch == Branch.ON_TRUE); } } return true; } }
/** * Try to fold comparison nodes, e.g == */ private Node tryFoldComparison(Node n, Node left, Node right) { TernaryValue result = evaluateComparison(n.getType(), left, right, shouldUseTypes); if (result == TernaryValue.UNKNOWN) { return n; } Node newNode = NodeUtil.booleanNode(result.toBoolean(true)); n.getParent().replaceChild(n, newNode); reportCodeChange(); return newNode; }
/** * Try to fold comparison nodes, e.g == */ private Node tryFoldComparison(Node n, Node left, Node right) { TernaryValue result = evaluateComparison(n.getToken(), left, right); if (result == TernaryValue.UNKNOWN) { return n; } Node newNode = NodeUtil.booleanNode(result.toBoolean(true)); reportChangeToEnclosingScope(n); n.replaceWith(newNode); markFunctionsDeleted(n); return newNode; }
TernaryValue child = getPureBooleanValue(n.getFirstChild()); if (child != TernaryValue.UNKNOWN) { return child.toBoolean(true) ? "false" : "true"; // reversed.
@Override public boolean apply(DiGraphEdge<Node, ControlFlowGraph.Branch> input) { // First skill all exceptions. Branch branch = input.getValue(); if (branch == Branch.ON_EX) { return false; } else if (branch.isConditional()) { Node condition = NodeUtil.getConditionExpression( input.getSource().getValue()); // TODO(user): We CAN make this bit smarter just looking at // constants. We DO have a full blown ReverseAbstractInterupter and // type system that can evaluate some impressions' boolean value but // for now we will keep this pass lightweight. if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (Branch.ON_TRUE == branch); } } } return true; } };
@Override public boolean apply(DiGraphEdge<Node, ControlFlowGraph.Branch> input) { // First skill all exceptions. Branch branch = input.getValue(); if (branch == Branch.ON_EX) { return false; } else if (branch.isConditional()) { Node condition = NodeUtil.getConditionExpression( input.getSource().getValue()); // TODO(user): We CAN make this bit smarter just looking at // constants. We DO have a full blown ReverseAbstractInterupter and // type system that can evaluate some impressions' boolean value but // for now we will keep this pass lightweight. if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (Branch.ON_TRUE == branch); } } } return true; } };
Node branchToKeep = condValue.toBoolean(true) ? thenBody : elseBody; Node replacement; boolean condHasSideEffects = mayHaveSideEffects(cond);
TernaryValue child = getPureBooleanValue(n.getFirstChild()); if (child != TernaryValue.UNKNOWN) { return child.toBoolean(true) ? "false" : "true"; // reversed.
TernaryValue child = getPureBooleanValue(n.getFirstChild()); if (child != TernaryValue.UNKNOWN) { return child.toBoolean(true) ? 0.0 : 1.0; // reversed.
TernaryValue child = getPureBooleanValue(n.getFirstChild()); if (child != TernaryValue.UNKNOWN) { return child.toBoolean(true) ? 0.0 : 1.0; // reversed.
if (condValue.toBoolean(true)) { branchToKeep = thenBody; branchToRemove = elseBody;
boolean lval = leftVal.toBoolean(true);
if (value != TernaryValue.UNKNOWN) { Node replacementConditionNode = NodeUtil.booleanNode(value.toBoolean(true)); condition.replaceWith(replacementConditionNode); reportChangeToEnclosingScope(replacementConditionNode);
if (value != TernaryValue.UNKNOWN) { Node replacementConditionNode = NodeUtil.booleanNode(value.toBoolean(true)); condition.getParent().replaceChild(condition, replacementConditionNode);
Node replacementNode = NodeUtil.booleanNode(!leftVal.toBoolean(true)); parent.replaceChild(n, replacementNode); reportChangeToEnclosingScope(parent);
boolean lval = leftVal.toBoolean(true);
Node replacementNode = NodeUtil.booleanNode(!leftVal.toBoolean(true)); parent.replaceChild(n, replacementNode); reportCodeChange();
boolean condTrue = condValue.toBoolean(true); if (n.hasTwoChildren()) { checkState(type == Token.IF);