+ public void addReturnFlowNode(NTuple<Descriptor> tuple) {
+
+ if (!mapDescTupleToInferNode.containsKey(tuple)) {
+ createNewFlowNode(tuple);
+ }
+
+ FlowNode node = mapDescTupleToInferNode.get(tuple);
+ node.setReturn(true);
+
+ returnNodeSet.add(node);
+ }
+
+ public Set<FlowNode> getReturnNodeSet() {
+ return returnNodeSet;
+ }
+
+ public Set<FlowNode> getLocalReachFlowNodeSetFrom(FlowNode fn) {
+ Set<FlowNode> set = new HashSet<FlowNode>();
+ recurLocalReachFlowNodeSet(fn, set);
+ return set;
+ }
+
+ private void recurLocalReachFlowNodeSet(FlowNode fn, Set<FlowNode> visited) {
+
+ Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
+ for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge edge = (FlowEdge) iterator.next();
+ FlowNode dstNode = edge.getDst();
+
+ if (!visited.contains(dstNode)) {
+ visited.add(dstNode);
+ recurLocalReachFlowNodeSet(dstNode, visited);
+ }
+ }
+
+ }
+
+ private void getReachFlowNodeSetFrom(FlowNode fn, Set<FlowNode> visited) {
+
+ Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
+ for (Iterator iterator = outEdgeSet.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);
+ }
+ }
+ }
+
+ }
+
+ 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 flowNode = (FlowNode) iterator.next();
+ if (flowNode.getCurrentDescTuple().startsWith(prefix)) {
+ recurReachableSetFrom(flowNode, reachableSet);
+ }
+ }
+
+ return reachableSet;
+ }
+
+ // 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);
+ }
+ }
+
+ }
+
+ public Set<NTuple<Location>> getReachableFlowTupleSet(Set<NTuple<Location>> visited, FlowNode fn) {
+
+ Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
+
+ for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge edge = (FlowEdge) iterator.next();
+
+ if (fn.getDescTuple().equals(edge.getInitTuple())) {
+ FlowNode dstNode = getFlowNode(edge.getEndTuple());
+ NTuple<Location> dstTuple = getLocationTuple(dstNode);
+
+ if (!visited.contains(dstTuple)) {
+ visited.add(dstTuple);
+ visited.addAll(getReachableFlowTupleSet(visited, dstNode));
+ }
+
+ }
+ }
+ return visited;
+ }
+
+ public NTuple<Location> getLocationTuple(NTuple<Descriptor> descTuple) {
+ return getLocationTuple(getFlowNode(descTuple));
+ }
+
+ public NTuple<Location> getLocationTuple(FlowNode fn) {
+
+ if (!mapFlowNodeToLocTuple.containsKey(fn)) {
+ NTuple<Descriptor> descTuple = fn.getDescTuple();
+ NTuple<Location> locTuple = new NTuple<Location>();
+ ClassDescriptor cd = null;
+
+ Descriptor localDesc = fn.getDescTuple().get(0);
+
+ if (fn.isIntermediate()) {
+ Location interLoc = new Location(md, localDesc.getSymbol());
+ interLoc.setLocDescriptor(localDesc);
+ locTuple.add(interLoc);
+ } else if (localDesc.getSymbol().equals(LocationInference.TOPLOC)) {
+ Location topLoc = new Location(md, Location.TOP);
+ topLoc.setLocDescriptor(LocationInference.TOPDESC);
+ locTuple.add(topLoc);
+ } else if (localDesc.getSymbol().equals(LocationInference.GLOBALLOC)) {
+ Location globalLoc = new Location(md, LocationInference.GLOBALLOC);
+ globalLoc.setLocDescriptor(LocationInference.GLOBALDESC);
+ locTuple.add(globalLoc);
+ } else {
+ // normal case
+ for (int i = 0; i < descTuple.size(); i++) {
+ Descriptor curDesc = descTuple.get(i);
+ Location loc;
+ if (i == 0) {
+ loc = new Location(md, curDesc.getSymbol());
+ loc.setLocDescriptor(curDesc);
+ cd = ((VarDescriptor) curDesc).getType().getClassDesc();
+ } else {
+ loc = new Location(cd, curDesc.getSymbol());
+ loc.setLocDescriptor(curDesc);
+
+ if (curDesc instanceof FieldDescriptor) {
+ cd = ((FieldDescriptor) curDesc).getType().getClassDesc();
+ } else {
+ cd = ((LocationDescriptor) curDesc).getEnclosingClassDesc();
+ }
+
+ }
+ locTuple.add(loc);
+ }
+ }
+
+ mapFlowNodeToLocTuple.put(fn, locTuple);
+ }
+ return mapFlowNodeToLocTuple.get(fn);
+ }
+
+ public Set<FlowNode> getIncomingFlowNodeSet(FlowNode node) {
+ Set<FlowNode> set = new HashSet<FlowNode>();
+ getIncomingFlowNodeSet(node, set);
+ return set;
+ }
+
+ public void getIncomingFlowNodeSet(FlowNode node, Set<FlowNode> visited) {
+
+ for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+ FlowNode curNode = (FlowNode) iterator.next();
+ Set<FlowEdge> edgeSet = getOutEdgeSet(curNode);
+
+ for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
+ FlowEdge flowEdge = (FlowEdge) iterator2.next();
+
+ if (node.equals(getFlowNode(flowEdge.getEndTuple()))) {
+ FlowNode incomingNode = getFlowNode(flowEdge.getInitTuple());
+
+ if (!visited.contains(incomingNode)) {
+ visited.add(incomingNode);
+ getIncomingFlowNodeSet(incomingNode, visited);
+ }
+ }
+ }
+ }
+
+ }
+
+ public Set<NTuple<Location>> getIncomingFlowTupleSet(FlowNode fn) {
+
+ NTuple<Descriptor> dstTuple = fn.getDescTuple();
+
+ Set<NTuple<Location>> set = new HashSet<NTuple<Location>>();
+
+ ClassDescriptor cd = null;
+
+ for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+ FlowNode node = (FlowNode) iterator.next();
+
+ Set<FlowEdge> edgeSet = getOutEdgeSet(node);
+ for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
+ FlowEdge flowEdge = (FlowEdge) iterator2.next();
+ if (dstTuple.equals(flowEdge.getEndTuple())) {
+ NTuple<Descriptor> initTuple = flowEdge.getInitTuple();
+ NTuple<Location> locTuple = new NTuple<Location>();
+ for (int i = 0; i < initTuple.size(); i++) {
+ Descriptor d = initTuple.get(i);
+ Location loc;
+ if (i == 0) {
+ loc = new Location(md, d.getSymbol());
+ cd = ((VarDescriptor) d).getType().getClassDesc();
+ } else {
+ loc = new Location(cd, d.getSymbol());
+ cd = ((FieldDescriptor) d).getType().getClassDesc();
+ }
+ locTuple.add(loc);
+ }
+ set.add(locTuple);
+ }
+ }
+ }
+ return set;
+ }
+
+ public boolean isParameter(NTuple<Descriptor> tuple) {