+ public Set<FlowNode> getReachFlowNodeSetFrom(FlowNode fn) {
+ Set<FlowNode> set = new HashSet<FlowNode>();
+ getReachFlowNodeSetFrom(fn, set);
+ return set;
+ }
+
+ public Set<FlowNode> getReachableSetFrom(NTuple<Descriptor> prefix) {
+ Set<FlowNode> reachableSet = new HashSet<FlowNode>();
+
+ Set<FlowNode> nodeSet = getNodeSet();
+ for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+ FlowNode originalSrcNode = (FlowNode) iterator.next();
+
+ Set<FlowNode> srcNodeSet = new HashSet<FlowNode>();
+ if (originalSrcNode instanceof FlowReturnNode) {
+ FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
+ Set<NTuple<Descriptor>> rtupleSetFromRNode = rnode.getReturnTupleSet();
+ Set<NTuple<Descriptor>> rtupleSet = getReturnTupleSet(rtupleSetFromRNode);
+ // System.out.println("#rnode=" + rnode + " rtupleSet=" + rtupleSet);
+ for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) {
+ NTuple<Descriptor> rtuple = (NTuple<Descriptor>) iterator2.next();
+ if (rtuple.startsWith(prefix)) {
+ // System.out.println("rtuple=" + rtuple + " give it to recur=" + originalSrcNode);
+ recurReachableSetFrom(originalSrcNode, reachableSet);
+ }
+ }
+ } else {
+ if (originalSrcNode.getCurrentDescTuple().startsWith(prefix)) {
+ recurReachableSetFrom(originalSrcNode, reachableSet);
+ }
+ }
+
+ }
+
+ return reachableSet;
+ }
+
+ public Set<NTuple<Descriptor>> getReturnTupleSet(Set<NTuple<Descriptor>> in) {
+
+ Set<NTuple<Descriptor>> normalTupleSet = new HashSet<NTuple<Descriptor>>();
+ for (Iterator iterator2 = in.iterator(); iterator2.hasNext();) {
+ NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator2.next();
+ FlowNode tupleNode = getFlowNode(tuple);
+ if (tupleNode instanceof FlowReturnNode) {
+ normalTupleSet.addAll(getReturnTupleSet(((FlowReturnNode) tupleNode).getReturnTupleSet()));
+ } else {
+ normalTupleSet.add(tuple);
+ }
+ }
+ return normalTupleSet;
+ }
+
+ // private void getReachFlowNodeSetFrom(FlowNode fn, Set<FlowNode> visited) {
+ //
+ // for (Iterator iterator = fn.getOutEdgeSet().iterator();
+ // iterator.hasNext();) {
+ // FlowEdge edge = (FlowEdge) iterator.next();
+ //
+ // if (fn.equals(getFlowNode(edge.getInitTuple()))) {
+ //
+ // FlowNode dstNode = getFlowNode(edge.getEndTuple());
+ //
+ // if (!visited.contains(dstNode)) {
+ // visited.add(dstNode);
+ // getReachFlowNodeSetFrom(dstNode, visited);
+ // }
+ // }
+ // }
+ //
+ // }
+
+ private void recurReachableSetFrom(FlowNode curNode, Set<FlowNode> reachableSet) {
+
+ Set<FlowEdge> edgeSet = getOutEdgeSet(curNode);
+ for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge edge = (FlowEdge) iterator.next();
+ FlowNode dstNode = getFlowNode(edge.getEndTuple());
+ if (!reachableSet.contains(dstNode)) {
+ reachableSet.add(dstNode);
+ recurReachableSetFrom(dstNode, reachableSet);
+ }
+ }
+
+ }
+