当我们获取到一个method的UnitGraph时,可以通过下面方法遍历CFG:
UnitGraph: g
Listulist = g.getHeads(); Unit u = ulist.get(0); while (!unitBelongList(u, g.getTails())) { EntityNode eNode = new EntityNode(); u = g.getSuccsOf(u).get(0); Stmt stmt = (Stmt) u; }
boolean unitBelongList(Unit u, Listg) { for(Unit i:g) { if(i.equals(u)) return true; } return false; }