/** * Finds the basic blocks that belong to a given subroutine, and marks these * blocks as belonging to this subroutine (by using {@link Label#status} as * a bit set (see {@link #visitMaxs}). This recursive method follows the * control flow graph to find all the blocks that are reachable from the * given ast WITHOUT following any JSR target. * * @param block a ast that belongs to the subroutine * @param id the id of this subroutine */ private void findSubroutine(final Label block, final int id) { // if 'ast' is already marked as belonging to subroutine 'id', returns if ((block.status & id) != 0) { return; } // marks 'ast' as belonging to subroutine 'id' block.status |= id; // calls this method recursively on each successor, except JSR targets Edge e = block.successors; while (e != null) { // if 'ast' is a JSR ast, then 'ast.successors.next' leads // to the JSR target (see {@link #visitJumpInsn}) and must therefore // not be followed if ((block.status & Label.JSR) == 0 || e != block.successors.next) { findSubroutine(e.successor, id); } e = e.next; } }
findSubroutine(labels, id); findSubroutine(subroutine, id);