X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FFlowGraph.java;h=c8914f1450eea8486f8e701e78777c3684b62d12;hb=561af6103d5d245d56589c369041dccddf43cf48;hp=0655c5faccdfcb84418236e2c816c742ee40043e;hpb=ec795f9b357096a8a74b539b3a3057b325bfa7f3;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index 0655c5fa..c8914f14 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -13,15 +13,12 @@ import IR.ClassDescriptor; import IR.Descriptor; import IR.FieldDescriptor; import IR.MethodDescriptor; -import IR.NameDescriptor; import IR.VarDescriptor; public class FlowGraph { MethodDescriptor md; - Set nodeSet; - Set returnNodeSet; FlowNode thisVarNode; @@ -47,7 +44,6 @@ public class FlowGraph { this.md = md; this.mapFlowNodeToLocTuple = new HashMap>(); this.mapLocTupleToFlowNode = new HashMap, FlowNode>(); - this.nodeSet = new HashSet(); this.mapDescTupleToInferNode = new HashMap, FlowNode>(); this.mapParamDescToIdx = new HashMap(); this.mapParamDescToIdx.putAll(mapParamDescToIdx); @@ -87,10 +83,6 @@ public class FlowGraph { this.mapLocTupleToFlowNode.putAll(in); } - public void setNodeSet(Set in) { - this.nodeSet.addAll(in); - } - public void setReturnNodeSet(Set in) { this.returnNodeSet.addAll(in); } @@ -113,7 +105,7 @@ public class FlowGraph { newNode.setIntermediate(true); mapDescTupleToInferNode.put(tuple, newNode); - nodeSet.add(newNode); + // nodeSet.add(newNode); System.out.println("create new intermediate node= " + newNode); @@ -144,7 +136,9 @@ public class FlowGraph { } public Set getNodeSet() { - return nodeSet; + Set set = new HashSet(); + set.addAll(mapDescTupleToInferNode.values()); + return set; } public MethodDescriptor getMethodDescriptor() { @@ -184,6 +178,26 @@ public class FlowGraph { return false; } + public Set getOutEdgeSetStartingFrom(FlowNode startNode) { + + Descriptor prefixDesc = startNode.getCurrentDescTuple().get(0); + + // returns the set of edges that share the same prefix of startNode + Set edgeSet = new HashSet(); + + for (Iterator> iter = mapFlowNodeToOutEdgeSet.values().iterator(); iter.hasNext();) { + Set nodeEdgeSet = iter.next(); + for (Iterator iter2 = nodeEdgeSet.iterator(); iter2.hasNext();) { + FlowEdge edge = iter2.next(); + if (edge.getInitTuple().get(0).equals(prefixDesc)) { + edgeSet.add(edge); + } + } + } + + return edgeSet; + } + public Set getOutEdgeSet(FlowNode node) { if (!mapFlowNodeToOutEdgeSet.containsKey(node)) { mapFlowNodeToOutEdgeSet.put(node, new HashSet()); @@ -196,7 +210,7 @@ public class FlowGraph { FlowNode fromNode = getFlowNode(fromDescTuple); FlowNode toNode = getFlowNode(toDescTuple); - System.out.println("create an edge from " + fromNode + " to " + toNode); + // System.out.println("create an edge from " + fromNode + " to " + toNode); int fromTupleSize = fromDescTuple.size(); NTuple curFromTuple = new NTuple(); @@ -263,7 +277,7 @@ public class FlowGraph { if (!mapDescTupleToInferNode.containsKey(tuple)) { FlowNode node = new FlowNode(tuple); mapDescTupleToInferNode.put(tuple, node); - nodeSet.add(node); + // nodeSet.add(node); mapLocTupleToFlowNode.put(getLocationTuple(node), node); @@ -442,7 +456,7 @@ public class FlowGraph { public void getIncomingFlowNodeSet(FlowNode node, Set visited) { - for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { + for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) { FlowNode curNode = (FlowNode) iterator.next(); Set edgeSet = getOutEdgeSet(curNode); @@ -470,7 +484,7 @@ public class FlowGraph { ClassDescriptor cd = null; - for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { + for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) { FlowNode node = (FlowNode) iterator.next(); Set edgeSet = getOutEdgeSet(node); @@ -504,10 +518,15 @@ public class FlowGraph { return mapParamDescToIdx.containsKey(firstIdxDesc); } + public int getParamIdx(NTuple tuple) { + Descriptor firstIdxDesc = tuple.get(0); + return mapParamDescToIdx.get(firstIdxDesc); + } + public FlowGraph clone() { FlowGraph clone = new FlowGraph(md, mapParamDescToIdx); - clone.setNodeSet(getNodeSet()); + // clone.setNodeSet(getNodeSet()); clone.setMapLocTupleToFlowNode(getMapLocTupleToFlowNode()); clone.setMapFlowNodeToLocTuple(getMapFlowNodeToLocTuple()); clone.setMapDescTupleToInferNode(getMapDescTupleToInferNode()); @@ -595,7 +614,8 @@ public class FlowGraph { // then visit every flow node - Iterator iter = nodeSet.iterator(); + // Iterator iter = nodeSet.iterator(); + Iterator iter = getNodeSet().iterator(); Set addedEdgeSet = new HashSet(); Set addedNodeSet = new HashSet(); @@ -619,7 +639,7 @@ public class FlowGraph { } public boolean constainsNode(FlowNode node) { - return nodeSet.contains(node); + return getNodeSet().contains(node); } private void drawSubgraph(FlowNode node, BufferedWriter bw, Set addedSet)