Skip to content

Commit

Permalink
fixed files form Closure #85
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 126173b commit 86239fc
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,7 @@ private Node tryRemoveUnconditionalBranching(Node n) {
return n;
}

if (n.getParent() == null) {
List<DiGraphEdge<Node,Branch>> outEdges = gNode.getOutEdges();
if (outEdges.size() == 1) {
return tryRemoveUnconditionalBranching(outEdges.get(0).getDestination().getValue());
}
}
switch (n.getType()) {
case Token.BLOCK:
if (n.hasChildren()) {
Node first = n.getFirstChild();
return tryRemoveUnconditionalBranching(first);
} else {
return tryRemoveUnconditionalBranching(ControlFlowAnalysis.computeFollowNode(n));
}
case Token.RETURN:
if (n.hasChildren()) {
break;
Expand All @@ -180,7 +167,7 @@ private Node tryRemoveUnconditionalBranching(Node n) {
(n.getNext() == null || n.getNext().getType() == Token.FUNCTION)) {

Preconditions.checkState(outEdges.get(0).getValue() == Branch.UNCOND);
Node fallThrough = tryRemoveUnconditionalBranching(computeFollowing(n));
Node fallThrough = computeFollowing(n);
Node nextCfgNode = outEdges.get(0).getDestination().getValue();
if (nextCfgNode == fallThrough) {
removeDeadExprStatementSafely(n);
Expand All @@ -193,6 +180,13 @@ private Node tryRemoveUnconditionalBranching(Node n) {

private Node computeFollowing(Node n) {
Node next = ControlFlowAnalysis.computeFollowNode(n);
while (next != null && next.getType() == Token.BLOCK) {
if (next.hasChildren()) {
next = next.getFirstChild();
} else {
next = computeFollowing(next);
}
}
return next;
}

Expand Down

0 comments on commit 86239fc

Please sign in to comment.