X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FLocationInference.java;h=6594444c987a90ec76aef8c5baf42b6c875cae56;hb=d77839806b116bae81d35232998b6c1ac3ddf23d;hp=dbcc415dec5918a53cf396956546e7df309423ba;hpb=03f449200cf7e78de07f884509619d0e37edfacf;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index dbcc415d..6594444c 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -120,20 +120,26 @@ public class LocationInference { public static final String GLOBALLOC = "GLOBALLOC"; - public static final String TOPLOC = "TOPLOC"; - public static final String INTERLOC = "INTERLOC"; - public static final String PCLOC = "PCLOC"; + public static final String PCLOC = "_PCLOC_"; - public static final String RLOC = "RLOC"; + public static final String RLOC = "_RLOC_"; public static final Descriptor GLOBALDESC = new NameDescriptor(GLOBALLOC); - public static final Descriptor TOPDESC = new NameDescriptor(TOPLOC); + public static final Descriptor TOPDESC = new NameDescriptor(SSJavaAnalysis.TOP); + + public static final Descriptor BOTTOMDESC = new NameDescriptor(SSJavaAnalysis.BOTTOM); public static final Descriptor RETURNLOC = new NameDescriptor(RLOC); + public static final Descriptor LITERALDESC = new NameDescriptor("LITERAL"); + + public static final HNode TOPHNODE = new HNode(TOPDESC); + + public static final HNode BOTTOMHNODE = new HNode(BOTTOMDESC); + public static String newline = System.getProperty("line.separator"); LocationInfo curMethodInfo; @@ -223,20 +229,24 @@ public class LocationInference { public void inference() { + ssjava.init(); + // construct value flow graph constructFlowGraph(); assignCompositeLocation(); + // calculate RETURNLOC,PCLOC + calculateExtraLocations(); + + _debug_writeFlowGraph(); + // System.exit(0); constructHierarchyGraph(); debug_writeHierarchyDotFiles(); - // calculate RETURNLOC,PCLOC - calculateExtraLocations(); - simplifyHierarchyGraph(); debug_writeSimpleHierarchyDotFiles(); @@ -288,7 +298,6 @@ public class LocationInference { System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:"); MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop(); translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc); - _debug_printGraph(); } private void updateCompositeLocationAssignments() { @@ -316,6 +325,7 @@ public class LocationInference { System.out.println("---updatedCompLoc1=" + updatedCompLoc); } else { NTuple descTuple = node.getDescTuple(); + System.out.println("update desc=" + descTuple); CompositeLocation compLoc = convertToCompositeLocation(md, descTuple); compLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(compLoc); @@ -350,10 +360,9 @@ public class LocationInference { String locName; if (!enclosingDesc.equals(GLOBALDESC)) { LocationSummary locSummary = getLocationSummary(enclosingDesc); - HierarchyGraph hierarchyGraph = getSimpleHierarchyGraph(enclosingDesc); - if (hierarchyGraph != null) { - - HNode curNode = hierarchyGraph.getCurrentHNode(nodeIdentifier); + HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc); + if (scGraph != null) { + HNode curNode = scGraph.getCurrentHNode(nodeIdentifier); if (curNode != null) { nodeIdentifier = curNode.getName(); } @@ -411,7 +420,8 @@ public class LocationInference { Set nodeSet = flowGraph.getNodeSet(); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { FlowNode node = (FlowNode) iterator.next(); - if (node.getDescTuple().startsWith(localDesc)) { + if (node.getDescTuple().startsWith(localDesc) + && !node.getDescTuple().get(0).equals(LITERALDESC)) { // need to assign the inferred composite location to this node CompositeLocation newCompLoc = generateCompositeLocation(node.getDescTuple(), inferCompLoc); node.setCompositeLocation(newCompLoc); @@ -1279,7 +1289,8 @@ public class LocationInference { // inferred composite location for (int paramIdx = 0; paramIdx < flowGraph.getNumParameters(); paramIdx++) { FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx); - CompositeLocation inferredCompLoc = flowNode.getCompositeLocation(); + CompositeLocation inferredCompLoc = + updateCompositeLocation(flowNode.getCompositeLocation()); // NTuple descTuple = flowNode.getDescTuple(); // // CompositeLocation assignedCompLoc = flowNode.getCompositeLocation(); @@ -1292,8 +1303,8 @@ public class LocationInference { // loc.setLocDescriptor(locDesc); // inferredCompLoc = new CompositeLocation(loc); // } - System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc); - System.out.println("-flowNode inferLoc=" + flowNode.getCompositeLocation()); + System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original=" + + flowNode.getCompositeLocation()); Descriptor localVarDesc = flowNode.getDescTuple().get(0); methodSummary.addMapVarNameToInferCompLoc(localVarDesc, inferredCompLoc); @@ -1507,10 +1518,10 @@ public class LocationInference { Set keySet = mapDescriptorToHierarchyGraph.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { Descriptor desc = (Descriptor) iterator.next(); + System.out.println("SSJAVA: remove redundant edges: " + desc); HierarchyGraph simpleHierarchyGraph = getHierarchyGraph(desc).clone(); simpleHierarchyGraph.setName(desc + "_SIMPLE"); simpleHierarchyGraph.removeRedundantEdges(); - // simpleHierarchyGraph.simplifyHierarchyGraph(); mapDescriptorToSimpleHierarchyGraph.put(desc, simpleHierarchyGraph); } } @@ -1536,6 +1547,7 @@ public class LocationInference { Set keySet = mapDescriptorToHierarchyGraph.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { Descriptor desc = (Descriptor) iterator.next(); + System.out.println("SSJAVA: Constructing Skeleton Hierarchy Graph: " + desc); HierarchyGraph simpleGraph = getSimpleHierarchyGraph(desc); HierarchyGraph skeletonGraph = simpleGraph.generateSkeletonGraph(); skeletonGraph.setMapDescToHNode(simpleGraph.getMapDescToHNode()); @@ -1610,7 +1622,6 @@ public class LocationInference { // do fixed-point analysis - ssjava.init(); LinkedList descriptorListToAnalyze = ssjava.getSortedDescriptors(); // Collections.sort(descriptorListToAnalyze, new @@ -1683,6 +1694,29 @@ public class LocationInference { } } + Set keySet = mapDescriptorToHierarchyGraph.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Descriptor key = (Descriptor) iterator.next(); + HierarchyGraph graph = getHierarchyGraph(key); + + Set nodeToBeConnected = new HashSet(); + for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) { + HNode node = (HNode) iterator2.next(); + if (!node.isSkeleton() && !node.isCombinationNode()) { + if (graph.getIncomingNodeSet(node).size() == 0) { + nodeToBeConnected.add(node); + } + } + } + + for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) { + HNode node = (HNode) iterator2.next(); + System.out.println("NEED TO BE CONNECTED TO TOP=" + node); + graph.addEdge(graph.getHNode(TOPDESC), node); + } + + } + } private HierarchyGraph getHierarchyGraph(Descriptor d) { @@ -1730,7 +1764,6 @@ public class LocationInference { NTuple srcCurTuple = srcNode.getCurrentDescTuple(); NTuple dstCurTuple = dstNode.getCurrentDescTuple(); - if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1) && srcCurTuple.get(0).equals(dstCurTuple.get(0))) { @@ -1774,6 +1807,16 @@ public class LocationInference { } methodGraph.getHNode(GLOBALDESC).setSkeleton(true); + if (ssjava.getMethodContainingSSJavaLoop().equals(md)) { + // if the current method contains the event loop + // we need to set all nodes of the hierarchy graph as a skeleton node + Set hnodeSet = methodGraph.getNodeSet(); + for (Iterator iterator = hnodeSet.iterator(); iterator.hasNext();) { + HNode hnode = (HNode) iterator.next(); + hnode.setSkeleton(true); + } + } + } private MethodSummary getMethodSummary(MethodDescriptor md) { @@ -1910,7 +1953,8 @@ public class LocationInference { if (desc instanceof MethodDescriptor) { System.out.println("#EXTRA LOC DECLARATION GEN=" + desc); - MethodSummary methodSummary = getMethodSummary((MethodDescriptor) desc); + MethodDescriptor md = (MethodDescriptor) desc; + MethodSummary methodSummary = getMethodSummary(md); if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) { TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); @@ -1924,7 +1968,9 @@ public class LocationInference { } } - rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")"; + if (!md.isStatic()) { + rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")"; + } rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")"; } @@ -2039,7 +2085,8 @@ public class LocationInference { int idx = getParamLocation(methodDefStr, generateVarDeclaration((VarDescriptor) localVarDesc)); - + System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc + + " idx=" + idx); assert (idx != -1); String annoatedStr = @@ -2228,17 +2275,16 @@ public class LocationInference { } - private void inferLattices() { - } - private void calculateExtraLocations() { - LinkedList descriptorListToAnalyze = ssjava.getSortedDescriptors(); - for (Iterator iterator = descriptorListToAnalyze.iterator(); iterator.hasNext();) { + + LinkedList methodDescList = ssjava.getSortedDescriptors(); + for (Iterator iterator = methodDescList.iterator(); iterator.hasNext();) { MethodDescriptor md = (MethodDescriptor) iterator.next(); if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) { calculateExtraLocations(md); } } + } private void checkLatticesOfVirtualMethods(MethodDescriptor md) { @@ -2345,21 +2391,26 @@ public class LocationInference { // PC location is higher than location types of parameters which has incoming flows. Set> paramLocTupleHavingInFlowSet = new HashSet>(); + Set paramDescNOTHavingInFlowSet = new HashSet(); + // Set paramNodeNOThavingInFlowSet = new HashSet(); int numParams = fg.getNumParameters(); for (int i = 0; i < numParams; i++) { FlowNode paramFlowNode = fg.getParamFlowNode(i); Descriptor prefix = paramFlowNode.getDescTuple().get(0); + NTuple paramDescTuple = paramFlowNode.getCurrentDescTuple(); + NTuple paramLocTuple = translateToLocTuple(md, paramDescTuple); if (fg.getIncomingNodeSetByPrefix(prefix).size() > 0) { // parameter has in-value flows - NTuple paramDescTuple = paramFlowNode.getCurrentDescTuple(); - NTuple paramLocTuple = translateToLocTuple(md, paramDescTuple); paramLocTupleHavingInFlowSet.add(paramLocTuple); + } else { + // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple)); + paramDescNOTHavingInFlowSet.add(prefix); } } - System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet); + System.out.println("paramNodeNOThavingInFlowSet=" + paramDescNOTHavingInFlowSet); if (paramLocTupleHavingInFlowSet.size() > 0 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) { @@ -2369,24 +2420,20 @@ public class LocationInference { NTuple pcLocTuple = generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC); - int pcLocTupleIdx = pcLocTuple.size() - 1; - Location pcLoc = pcLocTuple.get(pcLocTupleIdx); - Descriptor pcDesc = pcLoc.getLocDescriptor(); - Descriptor enclosingDesc = pcLocTuple.get(pcLocTupleIdx).getDescriptor(); + NTuple pcDescTuple = translateToDescTuple(pcLocTuple); - HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc); - HNode pcNode = hierarchyGraph.getHNode(pcDesc); - pcNode.setSkeleton(true); + // add ordering relations s.t. PCLOC is higher than all flow nodes except the set of + // parameters that do not have incoming flows - for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) { - NTuple paramLocTuple = (NTuple) iterator.next(); - if (paramLocTuple.size() > pcLocTupleIdx) { - Descriptor lowerDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor(); - hierarchyGraph.addEdge(pcDesc, lowerDesc); + for (Iterator iterator = fg.getNodeSet().iterator(); iterator.hasNext();) { + FlowNode node = (FlowNode) iterator.next(); + + if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) { + fg.addValueFlowEdge(pcDescTuple, node.getDescTuple()); } } - System.out.println("pcLoc=" + pcLoc); + System.out.println("pcLoc=" + pcLocTuple); methodSummary.setPCLoc(new CompositeLocation(pcLocTuple)); } @@ -2435,11 +2482,8 @@ public class LocationInference { System.out.println("#calculateRETURNLOC= " + md); // calculate a return location: // the return location type is lower than all parameters and the location of return values - MethodSummary methodSummary = getMethodSummary(md); - FlowGraph fg = getFlowGraph(md); - Map mapParamToLoc = methodSummary.getMapParamIdxToInferLoc(); Set paramIdxSet = mapParamToLoc.keySet(); @@ -2447,53 +2491,42 @@ public class LocationInference { // first, generate the set of return value location types that starts // with 'this' reference - Set> inferFieldReturnLocSet = new HashSet>(); - Set paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md); System.out.println("paramFlowNodeFlowingToReturnValueSet=" + paramFlowNodeFlowingToReturnValueSet); - Set> locFlowingToReturnValueSet = new HashSet>(); + Set> tupleToBeHigherThanReturnLocSet = new HashSet>(); for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) { FlowNode fn = (FlowNode) iterator.next(); - NTuple paramDescTuple = fn.getCurrentDescTuple(); - NTuple paramLocTuple = translateToLocTuple(md, paramDescTuple); - - locFlowingToReturnValueSet.add(paramLocTuple); + tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, paramDescTuple)); } Set returnNodeSet = fg.getReturnNodeSet(); for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) { FlowNode returnNode = (FlowNode) iterator.next(); NTuple returnDescTuple = returnNode.getCurrentDescTuple(); - NTuple returnLocTuple = translateToLocTuple(md, returnDescTuple); - locFlowingToReturnValueSet.add(returnLocTuple); + tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple)); } - System.out.println("locFlowingToReturnValueSet=" + locFlowingToReturnValueSet); + System.out.println("-flow graph's returnNodeSet=" + returnNodeSet); + System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet); // Here, generates a return location in the method lattice that is lower than the // locFlowingToReturnValueSet NTuple returnLocTuple = - generateLocTupleRelativeTo(md, locFlowingToReturnValueSet, RLOC); + generateLocTupleRelativeTo(md, tupleToBeHigherThanReturnLocSet, RLOC); System.out.println("returnLocTuple=" + returnLocTuple); - int returnLocTupleIdx = returnLocTuple.size() - 1; - Location returnLoc = returnLocTuple.get(returnLocTupleIdx); - Descriptor returnDesc = returnLoc.getLocDescriptor(); - Descriptor enclosingDesc = returnLocTuple.get(returnLocTupleIdx).getDescriptor(); - - HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc); - HNode returnNode = hierarchyGraph.getHNode(returnDesc); - returnNode.setSkeleton(true); - - for (Iterator iterator = locFlowingToReturnValueSet.iterator(); iterator.hasNext();) { - NTuple locTuple = (NTuple) iterator.next(); - Descriptor higherDesc = locTuple.get(returnLocTupleIdx).getLocDescriptor(); - hierarchyGraph.addEdge(higherDesc, returnDesc); + NTuple returnDescTuple = translateToDescTuple(returnLocTuple); + for (Iterator iterator = tupleToBeHigherThanReturnLocSet.iterator(); iterator.hasNext();) { + NTuple higherTuple = (NTuple) iterator.next(); + fg.addValueFlowEdge(translateToDescTuple(higherTuple), returnDescTuple); } + fg.getFlowNode(returnDescTuple).setSkeleton(true); + System.out.println("fg node set=" + fg.getNodeSet()); + methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple)); // skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) { @@ -3411,13 +3444,13 @@ public class LocationInference { if (curDescriptor instanceof VarDescriptor) { enclosingDescriptor = md.getClassDesc(); + } else if (curDescriptor instanceof FieldDescriptor) { + enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor(); } else if (curDescriptor instanceof NameDescriptor) { // it is "GLOBAL LOC" case! enclosingDescriptor = GLOBALDESC; - } else if (curDescriptor instanceof InterDescriptor) { - enclosingDescriptor = null; } else { - enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor(); + enclosingDescriptor = null; } } @@ -3986,7 +4019,7 @@ public class LocationInference { newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); newImplicitTupleSet.addTupleSet(condTupleNode); - if (newImplicitTupleSet.size() > 1) { + if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional // locations & implicit flows NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); @@ -4013,6 +4046,7 @@ public class LocationInference { private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn, NodeTupleSet implicitFlowTupleSet) { + System.out.println("-analyzeFlowReturnNode=" + rn.printNode(0)); ExpressionNode returnExp = rn.getReturnExpression(); if (returnExp != null) { @@ -4050,22 +4084,54 @@ public class LocationInference { // add tuples corresponding to the current implicit flows currentFlowTupleSet.addTupleSet(implicitFlowTupleSet); - if (currentFlowTupleSet.size() > 1) { + System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet); + + if (needToGenerateInterLoc(currentFlowTupleSet)) { + System.out.println("---needToGenerateInterLoc"); FlowNode meetNode = fg.createIntermediateNode(); for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) { NTuple currentFlowTuple = (NTuple) iterator.next(); fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple()); } fg.addReturnFlowNode(meetNode.getDescTuple()); - } else if (currentFlowTupleSet.size() == 1) { - NTuple tuple = currentFlowTupleSet.iterator().next(); - fg.addReturnFlowNode(tuple); + } else { + // currentFlowTupleSet = removeLiteralTuple(currentFlowTupleSet); + for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) { + NTuple currentFlowTuple = (NTuple) iterator.next(); + fg.addReturnFlowNode(currentFlowTuple); + } } } } + private NodeTupleSet removeLiteralTuple(NodeTupleSet inSet) { + NodeTupleSet tupleSet = new NodeTupleSet(); + for (Iterator> iter = inSet.iterator(); iter.hasNext();) { + NTuple tuple = iter.next(); + if (!tuple.get(0).equals(LITERALDESC)) { + tupleSet.addTuple(tuple); + } + } + return tupleSet; + } + + private boolean needToGenerateInterLoc(NodeTupleSet tupleSet) { + int size = 0; + for (Iterator> iter = tupleSet.iterator(); iter.hasNext();) { + NTuple descTuple = iter.next(); + if (!descTuple.get(0).equals(LITERALDESC)) { + size++; + } + } + if (size > 1) { + return true; + } else { + return false; + } + } + private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln, NodeTupleSet implicitFlowTupleSet) { @@ -4080,7 +4146,7 @@ public class LocationInference { newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); newImplicitTupleSet.addTupleSet(condTupleNode); - if (newImplicitTupleSet.size() > 1) { + if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional // locations & implicit flows NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); @@ -4135,24 +4201,42 @@ public class LocationInference { analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null, implicitFlowTupleSet, false); - // /////////// - NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); + NodeTupleSet newImplicitTupleSet = new NodeTupleSet(); + newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); + newImplicitTupleSet.addTupleSet(condTupleNode); - for (Iterator> idxIter = condTupleNode.iterator(); idxIter.hasNext();) { - NTuple tuple = idxIter.next(); - addFlowGraphEdge(md, tuple, interTuple); - } + if (needToGenerateInterLoc(newImplicitTupleSet)) { + // need to create an intermediate node for the GLB of conditional + // locations & implicit flows + NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); + for (Iterator> idxIter = newImplicitTupleSet.iterator(); idxIter + .hasNext();) { + NTuple tuple = idxIter.next(); + addFlowGraphEdge(md, tuple, interTuple); + } + newImplicitTupleSet.clear(); + newImplicitTupleSet.addTuple(interTuple); - for (Iterator> idxIter = implicitFlowTupleSet.iterator(); idxIter - .hasNext();) { - NTuple tuple = idxIter.next(); - addFlowGraphEdge(md, tuple, interTuple); } - NodeTupleSet newImplicitSet = new NodeTupleSet(); - newImplicitSet.addTuple(interTuple); - analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitSet); - analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitSet); + // /////////// + // NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); + // + // for (Iterator> idxIter = condTupleNode.iterator(); idxIter.hasNext();) { + // NTuple tuple = idxIter.next(); + // addFlowGraphEdge(md, tuple, interTuple); + // } + // + // for (Iterator> idxIter = implicitFlowTupleSet.iterator(); idxIter + // .hasNext();) { + // NTuple tuple = idxIter.next(); + // addFlowGraphEdge(md, tuple, interTuple); + // } + // + // NodeTupleSet newImplicitSet = new NodeTupleSet(); + // newImplicitSet.addTuple(interTuple); + analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitTupleSet); + analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitTupleSet); // /////////// // condTupleNode.addTupleSet(implicitFlowTupleSet); @@ -4184,7 +4268,7 @@ public class LocationInference { // System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet); // System.out.println("newImplicitTupleSet=" + newImplicitTupleSet); - if (newImplicitTupleSet.size() > 1) { + if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional locations & implicit flows NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); @@ -4222,7 +4306,7 @@ public class LocationInference { // creates edges from RHS to LHS NTuple interTuple = null; - if (nodeSetRHS.size() > 1) { + if (needToGenerateInterLoc(nodeSetRHS)) { interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); } @@ -4300,7 +4384,7 @@ public class LocationInference { break; case Kind.LiteralNode: - analyzeLiteralNode(md, nametable, (LiteralNode) en); + analyzeFlowLiteralNode(md, nametable, (LiteralNode) en, nodeSet); break; case Kind.MethodInvokeNode: @@ -4477,7 +4561,7 @@ public class LocationInference { // if argument is liternal node, argTuple is set to NULL NTuple argTuple = new NTuple(); - if (argTupleSet.size() > 1) { + if (needToGenerateInterLoc(argTupleSet)) { NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); for (Iterator> idxIter = argTupleSet.iterator(); idxIter.hasNext();) { @@ -4542,8 +4626,11 @@ public class LocationInference { mapIdxToTuple.put(new Integer(idx), argTuple); } - private void analyzeLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en) { - + private void analyzeFlowLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en, + NodeTupleSet nodeSet) { + NTuple tuple = new NTuple(); + tuple.add(LITERALDESC); + nodeSet.addTuple(tuple); } private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable, @@ -4568,8 +4655,24 @@ public class LocationInference { nodeSet.addTupleSet(expNodeTupleSet); } else { - nodeSet.addTupleSet(expNodeTupleSet); - nodeSet.addTupleSet(idxNodeTupleSet); + + NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet(); + + nodeSetArrayAccessExp.addTupleSet(expNodeTupleSet); + nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet); + + if (needToGenerateInterLoc(nodeSetArrayAccessExp)) { + NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); + + for (Iterator> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) { + NTuple higherTuple = iter.next(); + addFlowGraphEdge(md, higherTuple, interTuple); + } + nodeSetArrayAccessExp.clear(); + nodeSetArrayAccessExp.addTuple(interTuple); + } + + nodeSet.addTupleSet(nodeSetArrayAccessExp); } } @@ -4642,7 +4745,7 @@ public class LocationInference { private NTuple analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable, NameNode nn, NodeTupleSet nodeSet, NTuple base, NodeTupleSet implicitFlowTupleSet) { - // System.out.println("analyzeFlowNameNode=" + nn.printNode(0)); + System.out.println("analyzeFlowNameNode=" + nn.printNode(0)); if (base == null) { base = new NTuple(); @@ -4678,6 +4781,7 @@ public class LocationInference { if (fd.isFinal()) { // if it is 'static final', no need to have flow node for the TOP // location + System.out.println("STATIC FINAL"); return null; } else { // if 'static', assign the default GLOBAL LOCATION to the first @@ -4835,7 +4939,7 @@ public class LocationInference { // creates edges from RHS to LHS NTuple interTuple = null; - if (nodeSetRHS.size() > 1) { + if (needToGenerateInterLoc(nodeSetRHS)) { interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); } @@ -4916,7 +5020,7 @@ public class LocationInference { String fileName = "lattice_"; if (md != null) { fileName += - cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", ""); + /* cd.getSymbol().replaceAll("[\\W_]", "") + "_" + */md.toString().replaceAll("[\\W_]", ""); } else { fileName += cd.getSymbol().replaceAll("[\\W_]", ""); } @@ -4999,7 +5103,7 @@ public class LocationInference { bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n"); } - public void _debug_printGraph() { + public void _debug_writeFlowGraph() { Set keySet = mapMethodDescriptorToFlowGraph.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {