| Code with Finding: |
class PeepholeRemoveDeadCode {
/**
* Removes DOs that always evaluate to false. This leaves the
* statements that were in the loop in a BLOCK node.
* The block will be removed in a later pass, if possible.
*/
Node tryFoldDo(Node n) {
Preconditions.checkArgument(n.getType() == Token.DO);
Node cond = NodeUtil.getConditionExpression(n);
if (NodeUtil.getBooleanValue(cond) != TernaryValue.FALSE) {
return n;
}
// TODO(johnlenz): The do-while can be turned into a label with
// named breaks and the label optimized away (maybe).
if (hasBreakOrContinue(n)) {
return n;
}
Preconditions.checkState(
NodeUtil.isControlStructureCodeBlock(n, n.getFirstChild()));
Node block = n.removeFirstChild();
n.getParent().replaceChild(n, block);
reportCodeChange();
return n;
}
}
|