public void acceptVisitorStartingFromLocation ( CFG cfg , PathVisitor visitor , BasicBlock startBlock , InstructionHandle startHandle ) { // Find the start block in the path int index ; for ( index = 0 ; index < getLength ( ) ; index ++ ) { if ( getBlockIdAt ( index ) == startBlock . getLabel ( ) ) { break ; } } assert index < getLength ( ) ; Iterator < InstructionHandle > i = startBlock . instructionIterator ( ) ; // Position iterator at start instruction handle if ( startHandle != startBlock . getFirstInstruction ( ) ) { while ( i . hasNext ( ) ) { InstructionHandle handle = i . next ( ) ; if ( handle . getNext ( ) == startHandle ) { break ; } } } BasicBlock basicBlock = startBlock ; while ( true ) { // visit block visitor . visitBasicBlock ( basicBlock ) ; // visit instructions in block while ( i . hasNext ( ) ) { visitor . visitInstructionHandle ( i . next ( ) ) ; } // end of path? index ++ ; if ( index >= getLength ( ) ) { break ; } // visit edge BasicBlock next = cfg . lookupBlockByLabel ( getBlockIdAt ( index ) ) ; Edge edge = cfg . lookupEdge ( basicBlock , next ) ; assert edge != null ; visitor . visitEdge ( edge ) ; // continue to next block basicBlock = next ; i = basicBlock . instructionIterator ( ) ; } }
Accept a PathVisitor starting from a given BasicBlock and InstructionHandle .