return null;
}
}
// Try transforms that apply to both IF and HOOK.
TernaryValue condValue = NodeUtil.getImpureBooleanValue(cond);
if (condValue == TernaryValue.UNKNOWN) {
return n; // We can't remove branches otherwise!
}
if (mayHaveSideEffects(cond)) {
// Transform "if (a = 2) {x =2}" into "if (true) {a=2;x=2}"
boolean newConditionValue = condValue == TernaryValue.TRUE;
// Add an elseBody if it is needed.
if (!newConditionValue && elseBody == null) {
elseBody = IR.block().srcref(n);
n.addChildToBack(elseBody);
}
Node newCond = NodeUtil.booleanNode(newConditionValue);
n.replaceChild(cond, newCond);
Node branchToKeep = newConditionValue ? thenBody : elseBody;
branchToKeep.addChildToFront(IR.exprResult(cond).srcref(cond));
reportCodeChange();
cond = newCond;
}
boolean condTrue = condValue.toBoolean(true);
if (n.getChildCount() == 2) {
Preconditions.checkState(type == Token.IF);
if (condTrue) {
// Replace "if (true) { X }" with "X".