X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FFlowGraph.java;h=c2a8f8ecc98f1b34288a25729b7bc5a739e43966;hp=f553fccfa76a1d93a8f2bede47b45080d0975c94;hb=8d750e51bc5fa6b54ed568859dd8a6a25ad9e4c4;hpb=c8beb00c3d243b803b8b632b5e299f9a5b498f04 diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index f553fccf..c2a8f8ec 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -41,6 +41,8 @@ public class FlowGraph { Map mapMethodInvokeNodeToFlowReturnNode; + Map mapIntersectionDescToEnclosingDescriptor; + public static int interseed = 0; boolean debug = true; @@ -57,6 +59,7 @@ public class FlowGraph { this.mapFlowNodeToOutEdgeSet = new HashMap>(); this.mapFlowNodeToInEdgeSet = new HashMap>(); this.mapMethodInvokeNodeToFlowReturnNode = new HashMap(); + this.mapIntersectionDescToEnclosingDescriptor = new HashMap(); if (!md.isStatic()) { // create a node for 'this' varialbe @@ -74,6 +77,15 @@ public class FlowGraph { } + public void addMapInterLocNodeToEnclosingDescriptor(Descriptor interDesc, ClassDescriptor desc) { + System.out.println("##### INTERLOC=" + interDesc + " enclosing desc=" + desc); + mapIntersectionDescToEnclosingDescriptor.put(interDesc, desc); + } + + public ClassDescriptor getEnclosingDescriptor(Descriptor interDesc) { + return mapIntersectionDescToEnclosingDescriptor.get(interDesc); + } + public Map, FlowNode> getMapDescTupleToInferNode() { return mapDescTupleToInferNode; } @@ -306,7 +318,7 @@ public class FlowGraph { addOutEdge(fromNode, edge); addInEdge(toNode, edge); - // System.out.println("add a new edge=" + edge); + System.out.println("add a new edge=" + edge); } private void addInEdge(FlowNode toNode, FlowEdge edge) { @@ -338,6 +350,7 @@ public class FlowGraph { public FlowNode createNewFlowNode(NTuple tuple) { + // System.out.println("createNewFlowNode=" + tuple); if (!mapDescTupleToInferNode.containsKey(tuple)) { FlowNode node = new FlowNode(tuple); mapDescTupleToInferNode.put(tuple, node); @@ -383,12 +396,29 @@ public class FlowGraph { Set outEdgeSet = getOutEdgeSet(fn); for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) { FlowEdge edge = (FlowEdge) iterator.next(); - FlowNode dstNode = edge.getDst(); + FlowNode originalDstNode = edge.getDst(); + + Set dstNodeSet = new HashSet(); + if (originalDstNode instanceof FlowReturnNode) { + FlowReturnNode rnode = (FlowReturnNode) originalDstNode; + Set> rtupleSetFromRNode = rnode.getReturnTupleSet(); + Set> rtupleSet = getReturnTupleSet(rtupleSetFromRNode); + for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) { + NTuple rtuple = (NTuple) iterator2.next(); + dstNodeSet.add(getFlowNode(rtuple)); + } + } else { + dstNodeSet.add(originalDstNode); + } - if (!visited.contains(dstNode)) { - visited.add(dstNode); - recurLocalReachFlowNodeSet(dstNode, visited); + for (Iterator iterator2 = dstNodeSet.iterator(); iterator2.hasNext();) { + FlowNode dstNode = (FlowNode) iterator2.next(); + if (!visited.contains(dstNode)) { + visited.add(dstNode); + recurLocalReachFlowNodeSet(dstNode, visited); + } } + } } @@ -421,15 +451,47 @@ public class FlowGraph { Set nodeSet = getNodeSet(); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { - FlowNode flowNode = (FlowNode) iterator.next(); - if (flowNode.getCurrentDescTuple().startsWith(prefix)) { - recurReachableSetFrom(flowNode, reachableSet); + FlowNode originalSrcNode = (FlowNode) iterator.next(); + + Set srcNodeSet = new HashSet(); + if (originalSrcNode instanceof FlowReturnNode) { + FlowReturnNode rnode = (FlowReturnNode) originalSrcNode; + Set> rtupleSetFromRNode = rnode.getReturnTupleSet(); + Set> rtupleSet = getReturnTupleSet(rtupleSetFromRNode); + System.out.println("#rnode=" + rnode + " rtupleSet=" + rtupleSet); + for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) { + NTuple rtuple = (NTuple) 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> getReturnTupleSet(Set> in) { + + Set> normalTupleSet = new HashSet>(); + for (Iterator iterator2 = in.iterator(); iterator2.hasNext();) { + NTuple tuple = (NTuple) 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 visited) { // // for (Iterator iterator = fn.getOutEdgeSet().iterator(); @@ -497,7 +559,7 @@ public class FlowGraph { Descriptor localDesc = fn.getDescTuple().get(0); - if (fn.isIntermediate()) { + if (fn.isIntermediate() && fn.getDescTuple().size() == 1) { Location interLoc = new Location(md, localDesc.getSymbol()); interLoc.setLocDescriptor(localDesc); locTuple.add(interLoc); @@ -519,6 +581,8 @@ public class FlowGraph { loc.setLocDescriptor(curDesc); if (curDesc instanceof VarDescriptor) { cd = ((VarDescriptor) curDesc).getType().getClassDesc(); + } else if (curDesc instanceof InterDescriptor) { + cd = mapIntersectionDescToEnclosingDescriptor.get(curDesc); } else { // otherwise it should be the last element cd = null; @@ -566,8 +630,9 @@ public class FlowGraph { if (incomingNode instanceof FlowReturnNode) { FlowReturnNode rnode = (FlowReturnNode) incomingNode; - Set> nodeTupleSet = rnode.getTupleSet(); - for (Iterator iterator3 = nodeTupleSet.iterator(); iterator3.hasNext();) { + Set> nodeTupleSet = rnode.getReturnTupleSet(); + Set> rtupleSet = getReturnTupleSet(nodeTupleSet); + for (Iterator iterator3 = rtupleSet.iterator(); iterator3.hasNext();) { NTuple nodeTuple = (NTuple) iterator3.next(); FlowNode fn = getFlowNode(nodeTuple); if (!visited.contains(fn)) {