From 2b3ce36d11b84601c058b1f3e37fb0e9d089bf01 Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 11 Aug 2012 23:29:57 +0000 Subject: [PATCH] changes. --- .../Analysis/SSJava/LocationInference.java | 114 ++++-------------- Robust/src/Analysis/SSJava/LocationInfo.java | 6 +- Robust/src/Analysis/SSJava/NTuple.java | 6 + 3 files changed, 35 insertions(+), 91 deletions(-) diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 1294cf85..03cf57f7 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -716,9 +716,6 @@ public class LocationInference { private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo, NTuple tuple) { - // System.out.println("@@@@@generateInferredCompositeLocation=" + tuple); - // System.out.println("generateInferredCompositeLocation=" + tuple + " 0=" - // + tuple.get(0).getLocDescriptor()); // first, retrieve inferred location by the local var descriptor CompositeLocation inferLoc = new CompositeLocation(); @@ -753,7 +750,8 @@ public class LocationInference { inferLoc.addLocation(inferLocElement); } - // System.out.println("@@@@@inferLoc=" + inferLoc); + + assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier()); return inferLoc; } @@ -936,12 +934,6 @@ public class LocationInference { Map, Set>> mapPrefixToIncomingLocTupleSet = new HashMap, Set>>(); - Set localInNodeSet = new HashSet(); - Set localOutNodeSet = new HashSet(); - - CompositeLocation flowNodeInferLoc = - generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(flowNode)); - List> prefixList = new ArrayList>(); for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) { @@ -953,16 +945,12 @@ public class LocationInference { NTuple inNodeInferredLocTuple = inNodeInferredLoc.getTuple(); - if (inNodeTuple.size() > 1) { - for (int i = 1; i < inNodeInferredLocTuple.size(); i++) { - NTuple prefix = inNodeInferredLocTuple.subList(0, i); - if (!prefixList.contains(prefix)) { - prefixList.add(prefix); - } - addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inNodeInferredLocTuple); + for (int i = 1; i < inNodeInferredLocTuple.size(); i++) { + NTuple prefix = inNodeInferredLocTuple.subList(0, i); + if (!prefixList.contains(prefix)) { + prefixList.add(prefix); } - } else { - localInNodeSet.add(inNode); + addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inNodeInferredLocTuple); } } @@ -980,13 +968,6 @@ public class LocationInference { } }); - for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) { - FlowNode reachableNode = (FlowNode) iterator2.next(); - if (reachableNode.getDescTuple().size() == 1) { - localOutNodeSet.add(reachableNode); - } - } - // find out reachable nodes that have the longest common prefix for (int i = 0; i < prefixList.size(); i++) { NTuple curPrefix = prefixList.get(i); @@ -1002,13 +983,6 @@ public class LocationInference { } } - // check if the lattice has the relation in which higher prefix is - // actually lower than the current node - CompositeLocation prefixInferLoc = generateInferredCompositeLocation(methodInfo, curPrefix); - if (isGreaterThan(methodLattice, flowNodeInferLoc, prefixInferLoc)) { - reachableCommonPrefixSet.add(curPrefix); - } - if (!reachableCommonPrefixSet.isEmpty()) { // found reachable nodes that start with the prefix curPrefix // need to assign a composite location @@ -1034,8 +1008,6 @@ public class LocationInference { // methodInfo.getInferLocation(localVarDesc); CompositeLocation newInferLocation = new CompositeLocation(); - System.out.println("PREV INFER LOCATION=" + inferLocation + " curPrefix=" - + curPrefix); if (inferLocation.getTuple().startsWith(curPrefix)) { // the same infer location is already existed. no need to do // anything @@ -1052,10 +1024,8 @@ public class LocationInference { Location newLocationElement = new Location(desc, newLocSymbol); newInferLocation.addLocation(newLocationElement); - // if (flowNode.getDescTuple().size() == 1) { // maps local variable to location types of the common prefix methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone()); - // } // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation); addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc, @@ -1063,12 +1033,20 @@ public class LocationInference { methodInfo.removeMaplocalVarToLocSet(localVarDesc); // add the field/var descriptor to the set of the location symbol - int flowNodeTupleSize = flowNode.getDescTuple().size(); - Descriptor lastFlowNodeDesc = flowNode.getDescTuple().get(flowNodeTupleSize - 1); - int inferLocSize = newInferLocation.getSize(); - Location lastLoc = newInferLocation.get(inferLocSize - 1); - Descriptor enclosingDesc = lastLoc.getDescriptor(); - getLocationInfo(enclosingDesc).addMapLocSymbolToDescSet(lastLoc.getLocIdentifier(), + int lastIdx = flowNode.getDescTuple().size() - 1; + Descriptor lastFlowNodeDesc = flowNode.getDescTuple().get(lastIdx); + Descriptor enclosinglastLastFlowNodeDesc = flowNodelocTuple.get(lastIdx).getDescriptor(); + + CompositeLocation newlyInferredLocForFlowNode = + generateInferredCompositeLocation(methodInfo, flowNodelocTuple); + Location lastInferLocElement = + newlyInferredLocForFlowNode.get(newlyInferredLocForFlowNode.getSize() - 1); + Descriptor enclosingLastInferLocElement = lastInferLocElement.getDescriptor(); + + // getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToDescSet( + // lastInferLocElement.getLocIdentifier(), lastFlowNodeDesc); + getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToRelatedInferLoc( + lastInferLocElement.getLocIdentifier(), enclosinglastLastFlowNodeDesc, lastFlowNodeDesc); // clean up the previous location @@ -1106,65 +1084,23 @@ public class LocationInference { System.out.println("-- add in-flow"); for (Iterator iterator = incomingCommonPrefixSet.iterator(); iterator.hasNext();) { NTuple tuple = (NTuple) iterator.next(); - System.out.println("--in-flow tuple=" + tuple); Location loc = tuple.get(idx); - String higher = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier(); + String higher = loc.getLocIdentifier(); addRelationHigherToLower(lattice, locInfo, higher, newlyInsertedLocName); } - System.out.println("-- add local in-flow"); - for (Iterator iterator = localInNodeSet.iterator(); iterator.hasNext();) { - FlowNode localNode = (FlowNode) iterator.next(); - - if (localNode.equals(flowNode)) { - continue; - } - - CompositeLocation inNodeInferLoc = - generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(localNode)); - - if (isCompositeLocation(inNodeInferLoc)) { - // need to make sure that newLocSymbol is lower than the infernode - // location in the field lattice - System.out.println("----srcNode=" + localNode + " dstNode=" + flowNode); - addRelationToLattice(methodInfo.getMethodDesc(), methodLattice, methodInfo, localNode, - flowNode); - - } - - } - System.out.println("-- add out flow"); for (Iterator iterator = reachableCommonPrefixSet.iterator(); iterator.hasNext();) { NTuple tuple = (NTuple) iterator.next(); if (tuple.size() > idx) { Location loc = tuple.get(idx); - String lower = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier(); + String lower = loc.getLocIdentifier(); + // String lower = + // locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier(); addRelationHigherToLower(lattice, locInfo, newlyInsertedLocName, lower); } } - System.out.println("-- add local out flow"); - for (Iterator iterator = localOutNodeSet.iterator(); iterator.hasNext();) { - FlowNode localOutNode = (FlowNode) iterator.next(); - - if (localOutNode.equals(flowNode)) { - continue; - } - - CompositeLocation outNodeInferLoc = - generateInferredCompositeLocation(methodInfo, - flowGraph.getLocationTuple(localOutNode)); - - if (isCompositeLocation(outNodeInferLoc)) { - System.out.println("--- srcNode=" + flowNode + " dstNode=" + localOutNode); - addRelationToLattice(methodInfo.getMethodDesc(), methodLattice, methodInfo, flowNode, - localOutNode); - - } - } - System.out.println("-- end of add local out flow"); - return true; } diff --git a/Robust/src/Analysis/SSJava/LocationInfo.java b/Robust/src/Analysis/SSJava/LocationInfo.java index 12f8d38b..ed90ed50 100644 --- a/Robust/src/Analysis/SSJava/LocationInfo.java +++ b/Robust/src/Analysis/SSJava/LocationInfo.java @@ -45,7 +45,7 @@ public class LocationInfo { public Map getMapDescToInferLocation() { return mapDescToInferCompositeLocation; } - + public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc, Descriptor desc) { if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) { @@ -53,6 +53,8 @@ public class LocationInfo { } mapLocSymbolToRelatedInferLocSet.get(locSymbol).add( new Pair(enclosingDesc, desc)); + + addMapLocSymbolToDescSet(locSymbol, desc); } public Set> getRelatedInferLocSet(String locSymbol) { @@ -78,7 +80,7 @@ public class LocationInfo { newInferLoc.addLocation(loc); mapDescToInferCompositeLocation.put(desc, newInferLoc); - addMapLocSymbolToDescSet(desc.getSymbol(), desc); +// addMapLocSymbolToDescSet(desc.getSymbol(), desc); addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc); } return mapDescToInferCompositeLocation.get(desc); diff --git a/Robust/src/Analysis/SSJava/NTuple.java b/Robust/src/Analysis/SSJava/NTuple.java index 513d7a50..396b4b72 100644 --- a/Robust/src/Analysis/SSJava/NTuple.java +++ b/Robust/src/Analysis/SSJava/NTuple.java @@ -109,4 +109,10 @@ public class NTuple { return elements.get(elements.size() - 1); } + public NTuple clone() { + NTuple clone = new NTuple(); + clone.addAll(this); + return clone; + } + } -- 2.34.1