import java.util.Map;
import java.util.Set;
+import IR.ClassDescriptor;
import IR.Descriptor;
import IR.MethodDescriptor;
import IR.NameDescriptor;
private Map<HNode, TripleItem> mapSharedNodeToTripleItem;
private Map<HNode, Integer> mapHNodeToHighestIndex;
+ private Map<Descriptor, Map<TripleItem, String>> mapDescToIntermediateLocMap;
+
+ private Map<Pair<HNode, HNode>, Integer> mapItemToHighestIndex;
+
+ private Map<SSJavaLattice<String>, Set<String>> mapLatticeToLocalLocSet;
+
public BuildLattice(LocationInference infer) {
this.infer = infer;
this.mapSharedNodeToTripleItem = new HashMap<HNode, TripleItem>();
this.mapHNodeToHighestIndex = new HashMap<HNode, Integer>();
+ this.mapItemToHighestIndex = new HashMap<Pair<HNode, HNode>, Integer>();
+ this.mapDescToIntermediateLocMap = new HashMap<Descriptor, Map<TripleItem, String>>();
+ this.mapLatticeToLocalLocSet = new HashMap<SSJavaLattice<String>, Set<String>>();
}
public SSJavaLattice<String> buildLattice(Descriptor desc) {
HierarchyGraph inputGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
LocationSummary locSummary = infer.getLocationSummary(desc);
+ HierarchyGraph naiveGraph = infer.getSimpleHierarchyGraph(desc);
+
+ // I don't think we need to keep the below if statement anymore
+ // because hierarchy graph does not have any composite location
Set<HNode> nodeSetWithCompositeLocation = new HashSet<HNode>();
if (desc instanceof MethodDescriptor) {
FlowGraph flowGraph = infer.getFlowGraph((MethodDescriptor) desc);
}
+ // /////////////////////////////////////////////////////////////////////////////////////
+ // lattice generation for the native approach
+
+ if (infer.state.SSJAVA_INFER_NAIVE_WRITEDOTS) {
+ BasisSet naiveBasisSet = naiveGraph.computeBasisSet(nodeSetWithCompositeLocation);
+
+ Family naiveFamily = generateFamily(naiveBasisSet);
+ Map<Set<Integer>, Set<Set<Integer>>> naive_mapImSucc =
+ coveringGraph(naiveBasisSet, naiveFamily);
+
+ SSJavaLattice<String> naive_lattice =
+ buildLattice(desc, naiveBasisSet, naiveGraph, null, naive_mapImSucc);
+ LocationInference.numLocationsNaive += naive_lattice.getKeySet().size();
+ infer.addNaiveLattice(desc, naive_lattice);
+ }
+
+ // /////////////////////////////////////////////////////////////////////////////////////
+
+ // lattice generation for the proposed approach
BasisSet basisSet = inputGraph.computeBasisSet(nodeSetWithCompositeLocation);
- debug_print(inputGraph);
+ // debug_print(inputGraph);
Family family = generateFamily(basisSet);
Map<Set<Integer>, Set<Set<Integer>>> mapImSucc = coveringGraph(basisSet, family);
}
+ public void setIntermediateLocMap(Descriptor desc, Map<TripleItem, String> map) {
+ mapDescToIntermediateLocMap.put(desc, map);
+ }
+
+ public Map<TripleItem, String> getIntermediateLocMap(Descriptor desc) {
+ if (!mapDescToIntermediateLocMap.containsKey(desc)) {
+ mapDescToIntermediateLocMap.put(desc, new HashMap<TripleItem, String>());
+ }
+ return mapDescToIntermediateLocMap.get(desc);
+ }
+
+ private Descriptor getParent(Descriptor desc) {
+ if (desc instanceof MethodDescriptor) {
+ MethodDescriptor md = (MethodDescriptor) desc;
+ ClassDescriptor cd = md.getClassDesc();
+ return infer.getParentMethodDesc(cd, md);
+ } else {
+ return ((ClassDescriptor) desc).getSuperDesc();
+ }
+ }
+
private SSJavaLattice<String> buildLattice(Descriptor desc, BasisSet basisSet,
HierarchyGraph inputGraph, LocationSummary locSummary,
Map<Set<Integer>, Set<Set<Integer>>> mapImSucc) {
+ System.out.println("\nBuild Lattice:" + inputGraph.getName());
+
SSJavaLattice<String> lattice =
new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
Set<Descriptor> descSet = inputGraph.getDescSetOfNode(higherNode);
// System.out.println("higherName=" + higherName + " higherNode=" + higherNode + " descSet="
// + descSet);
- for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
- Descriptor d = (Descriptor) iterator2.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), higherName);
+
+ if (locSummary != null) {
+ for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
+ Descriptor d = (Descriptor) iterator2.next();
+ locSummary.addMapHNodeNameToLocationName(d.getSymbol(), higherName);
+ }
}
+
// locSummary.addMapHNodeNameToLocationName(higherName, higherName);
Set<Set<Integer>> lowerSet = mapImSucc.get(higher);
Set<Descriptor> lowerDescSet = inputGraph.getDescSetOfNode(lowerNode);
// System.out.println("lowerName=" + lowerName + " lowerNode=" + lowerNode + " descSet="
// + lowerDescSet);
- for (Iterator iterator3 = lowerDescSet.iterator(); iterator3.hasNext();) {
- Descriptor d = (Descriptor) iterator3.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), lowerName);
+ if (locSummary != null) {
+ for (Iterator iterator3 = lowerDescSet.iterator(); iterator3.hasNext();) {
+ Descriptor d = (Descriptor) iterator3.next();
+ locSummary.addMapHNodeNameToLocationName(d.getSymbol(), lowerName);
+ }
}
// locSummary.addMapHNodeNameToLocationName(lowerName, lowerName);
public SSJavaLattice<String> insertIntermediateNodesToStraightLine(Descriptor desc,
SSJavaLattice<String> skeletonLattice) {
- mapSharedNodeToTripleItem.clear();
+ SSJavaLattice<String> lattice = skeletonLattice.clone();
+ LocationSummary locSummary = infer.getLocationSummary(desc);
+
+ Descriptor parentDesc = getParent(desc);
+ if (parentDesc != null) {
+ SSJavaLattice<String> parentLattice = infer.getLattice(parentDesc);
+
+ Map<String, Set<String>> parentMap = parentLattice.getTable();
+ Set<String> parentKeySet = parentMap.keySet();
+ for (Iterator iterator = parentKeySet.iterator(); iterator.hasNext();) {
+ String parentKey = (String) iterator.next();
+ Set<String> parentValueSet = parentMap.get(parentKey);
+ for (Iterator iterator2 = parentValueSet.iterator(); iterator2.hasNext();) {
+ String value = (String) iterator2.next();
+ lattice.put(parentKey, value);
+ }
+ }
+
+ Set<String> parentSharedLocSet = parentLattice.getSharedLocSet();
+ for (Iterator iterator = parentSharedLocSet.iterator(); iterator.hasNext();) {
+ String parentSharedLoc = (String) iterator.next();
+ lattice.addSharedLoc(parentSharedLoc);
+ }
+ }
HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc);
HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
- LocationSummary locSummary = infer.getLocationSummary(desc);
- SSJavaLattice<String> lattice = skeletonLattice.clone();
- Set<HNode> visited = new HashSet<HNode>();
- Set<HNode> scNodeSet = scGraph.getNodeSet();
- Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
+ Set<HNode> hierarchyGraphNodeSet = hierarchyGraph.getNodeSet();
+ for (Iterator iterator = hierarchyGraphNodeSet.iterator(); iterator.hasNext();) {
+ HNode hNode = (HNode) iterator.next();
+ if (!hNode.isSkeleton()) {
+ // here we need to insert an intermediate node for the hNode
+ System.out.println("\n#local node=" + hNode);
- for (Iterator iterator = scNodeSet.iterator(); iterator.hasNext();) {
- HNode scNode = (HNode) iterator.next();
- Set<HNode> outHierarchyNodeSet = hierarchyGraph.getOutgoingNodeSet(scNode);
- for (Iterator iterator2 = outHierarchyNodeSet.iterator(); iterator2.hasNext();) {
- HNode outHierarchyNode = (HNode) iterator2.next();
+ // 1) find the lowest node m in the lattice that is above hnode in the lattice
+ // 2) count the number of non-shared nodes d between the hnode and the node m
+ // int numNonSharedNodes;
+ int dist;
- if (!visited.contains(outHierarchyNode)) {
+ HNode SCNode;
+ if (hNode.isDirectCombinationNode()) {
+ // this node itself is the lowest node m. it is the first node of the chain
+ Set<HNode> combineSet = hierarchyGraph.getCombineSetByCombinationNode(hNode);
- if (!outHierarchyNode.isCombinationNode() && !outHierarchyNode.isSkeleton()) {
- visited.add(outHierarchyNode);
- Set<HNode> outSCNodeSet = scGraph.getOutgoingNodeSet(scNode);
+ System.out.println(" # direct combine node::combineSkeletonNodeSet=" + combineSet);
- if (outSCNodeSet.size() > 0) {
- // follows the straight line up to another skeleton/combination node
- outSCNodeSet = removeTransitivelyReachToNode(desc, scNode, outSCNodeSet);
- } else if (outSCNodeSet.size() == 0) {
- // the outNode is (directly/transitively) connected to the bottom node
- // therefore, we just add a dummy bottom HNode to the endCombNodeSet.
- outSCNodeSet.add(LocationInference.BOTTOMHNODE);
- }
+ SCNode = scGraph.getCombinationNode(combineSet);
+ // numNonSharedNodes = -1;
+ dist = 0;
+ } else {
- recurDFVisitNormalNode(scNode, outSCNodeSet, outHierarchyNode, 1, desc, lattice,
- visited, locSummary, mapIntermediateLoc);
- } else if (outHierarchyNode.isCombinationNode()) {
- visited.add(outHierarchyNode);
- expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary,
- outHierarchyNode);
- }
+ Set<HNode> aboveSet = new HashSet<HNode>();
+ if (hNode.isCombinationNode()) {
+ // the current node is a combination node
+ Set<HNode> combineSkeletonNodeSet =
+ hierarchyGraph.getCombineSetByCombinationNode(hNode);
+ System.out.println(" combineSkeletonNodeSet=" + combineSkeletonNodeSet
+ + " combinationNode=" + scGraph.getCombinationNode(combineSkeletonNodeSet));
- }
+ scGraph.getCombinationNode(combineSkeletonNodeSet);
- }
+ System.out.println(" firstnodeOfSimpleGraph="
+ + hierarchyGraph.getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
+ aboveSet.addAll(hierarchyGraph
+ .getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
- }
+ SCNode = scGraph.getCombinationNode(combineSkeletonNodeSet);
- // add shared locations
- Set<HNode> sharedNodeSet = mapSharedNodeToTripleItem.keySet();
- for (Iterator iterator = sharedNodeSet.iterator(); iterator.hasNext();) {
- HNode sharedNode = (HNode) iterator.next();
- TripleItem item = mapSharedNodeToTripleItem.get(sharedNode);
- String nonSharedLocName = mapIntermediateLoc.get(item);
- // System.out.println("sharedNode=" + sharedNode + " locName=" + nonSharedLocName);
+ } else {
+ // the current node is not a combination node
+ // there is only one parent node which should be skeleton node.
+
+ System.out.println(" hierarchyGraph.getSkeleteNodeSetReachTo(" + hNode + ")="
+ + hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
+ aboveSet.addAll(hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
+ System.out.println(" aboveset of " + hNode + "=" + aboveSet);
+ // assert aboveSet.size() == 1;
+ SCNode = aboveSet.iterator().next();
+ }
- String newLocName;
- if (locSummary.getHNodeNameSetByLatticeLoationName(nonSharedLocName) != null
- && !lattice.isSharedLoc(nonSharedLocName)) {
- // need to generate a new shared location in the lattice, which is one level lower than the
- // 'locName' location
- newLocName = "ILOC" + (LocationInference.locSeed++);
+ // update above set w.r.t the hierarchy graph with SC nodes
+ // because the skeleton nodes in the origianl hierarchy graph may merged to a new node
+ Set<HNode> endSet = new HashSet<HNode>();
+ for (Iterator iterator2 = aboveSet.iterator(); iterator2.hasNext();) {
+ HNode aboveNode = (HNode) iterator2.next();
+ endSet.add(scGraph.getCurrentHNode(aboveNode));
+ }
+ dist = hierarchyGraph.computeDistance(hNode, endSet);
+ System.out.println("##### " + hNode + "::dist=" + dist);
- // Set<String> aboveElementSet = getAboveElementSet(lattice, locName);
- Set<String> belowElementSet = new HashSet<String>();
- belowElementSet.addAll(lattice.get(nonSharedLocName));
+ // numNonSharedNodes = hierarchyGraph.countNonSharedNode(hNode, endSet);
- // System.out.println("nonSharedLocName=" + nonSharedLocName + " belowElementSet="
- // + belowElementSet + " newLocName=" + newLocName);
+ System.out.println(" COUNT-RESULT::node=" + hNode + " above=" + endSet + " distance="
+ + dist + " SCNode=" + SCNode);
+ }
- lattice.insertNewLocationBetween(nonSharedLocName, belowElementSet, newLocName);
- } else {
- newLocName = nonSharedLocName;
- }
+ // 3) convert the node m into a chain of nodes with the last node in the chain having m’s
+ // outgoing edges.
+ Set<HNode> outgoingSCNodeSet = scGraph.getOutgoingNodeSet(SCNode);
+ System.out.println(" outgoing scnode set from " + SCNode + "=" + outgoingSCNodeSet);
+
+ // convert hnodes to location names
+ String startLocName = locSummary.getLocationName(SCNode.getName());
+ Set<String> outgoingLocNameSet = new HashSet<String>();
+ for (Iterator iterator2 = outgoingSCNodeSet.iterator(); iterator2.hasNext();) {
+ HNode outSCNode = (HNode) iterator2.next();
+ String locName = locSummary.getLocationName(outSCNode.getName());
+ if (!locName.equals(outSCNode.getName())) {
+ System.out.println(" outSCNode=" + outSCNode + " -> locName="
+ + locName);
+ }
+ outgoingLocNameSet.add(locName);
+ }
- lattice.addSharedLoc(newLocName);
- HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
- Set<Descriptor> descSet = graph.getDescSetOfNode(sharedNode);
- for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
- Descriptor d = (Descriptor) iterator2.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), newLocName);
- }
- locSummary.addMapHNodeNameToLocationName(sharedNode.getName(), newLocName);
+ if (outgoingLocNameSet.isEmpty()) {
+ outgoingLocNameSet.add(lattice.getBottomItem());
+ }
+
+ // 4) If hnode is not a shared location, check if there already exists a local variable
+ // node that has distance d below m along this chain. If such a node
+ // does not exist, insert it.
+ String locName =
+ getNewLocation(lattice, startLocName, outgoingLocNameSet, dist, hNode.isSharedNode());
+ System.out.println(" ###hNode=" + hNode + "---->locName=" + locName);
+ locSummary.addMapHNodeNameToLocationName(hNode.getName(), locName);
+ }
}
return lattice;
}
- private void recurDFVisitNormalNode(HNode scStartNode, Set<HNode> scEndNodeSet,
- HNode curHierarchyNode, int idx, Descriptor desc, SSJavaLattice<String> lattice,
- Set<HNode> visited, LocationSummary locSummary, Map<TripleItem, String> mapIntermediateLoc) {
-
- TripleItem item = new TripleItem(scStartNode, scEndNodeSet, idx);
- // System.out.println("item=" + item);
- if (!mapIntermediateLoc.containsKey(item)) {
- // need to create a new intermediate location in the lattice
- String newLocName = "ILOC" + (LocationInference.locSeed++);
- String above;
- if (idx == 1) {
- above = scStartNode.getName();
- } else {
- int prevIdx = idx - 1;
- TripleItem prevItem = new TripleItem(scStartNode, scEndNodeSet, prevIdx);
- above = mapIntermediateLoc.get(prevItem);
- }
-
- Set<String> belowSet = new HashSet<String>();
- for (Iterator iterator = scEndNodeSet.iterator(); iterator.hasNext();) {
- HNode endNode = (HNode) iterator.next();
- String locName;
- if (locSummary.getMapHNodeNameToLocationName().containsKey(endNode.getName())) {
- locName = locSummary.getLocationName(endNode.getName());
- } else {
- locName = endNode.getName();
- }
- belowSet.add(locName);
- }
- lattice.insertNewLocationBetween(above, belowSet, newLocName);
-
- mapIntermediateLoc.put(item, newLocName);
+ private void addLocalLocation(SSJavaLattice<String> lattice, String localLoc) {
+ if (!mapLatticeToLocalLocSet.containsKey(lattice)) {
+ mapLatticeToLocalLocSet.put(lattice, new HashSet<String>());
}
+ mapLatticeToLocalLocSet.get(lattice).add(localLoc);
+ }
- String curLocName = mapIntermediateLoc.get(item);
- HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc);
-
- if (curHierarchyNode.isSharedNode()) {
- // if the current node is shared location, add a shared location to the lattice later
- mapSharedNodeToTripleItem.put(curHierarchyNode, item);
- } else {
- Set<Descriptor> descSet = hierarchyGraph.getDescSetOfNode(curHierarchyNode);
- for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
- Descriptor d = (Descriptor) iterator.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), curLocName);
- }
- locSummary.addMapHNodeNameToLocationName(curHierarchyNode.getName(), curLocName);
+ private boolean isLocalLocation(SSJavaLattice<String> lattice, String localLoc) {
+ if (mapLatticeToLocalLocSet.containsKey(lattice)) {
+ return mapLatticeToLocalLocSet.get(lattice).contains(localLoc);
}
+ return false;
+ }
- System.out.println("-TripleItem normal=" + item);
- System.out.println("-curNode=" + curHierarchyNode.getName() + " S="
- + curHierarchyNode.isSharedNode() + " locName=" + curLocName + " isC="
- + curHierarchyNode.isCombinationNode());
+ public String getNewLocation(SSJavaLattice<String> lattice, String start, Set<String> endSet,
+ int dist, boolean isShared) {
+ System.out.println(" #GETNEWLOCATION:: start=" + start + " endSet=" + endSet + " dist="
+ + dist + " isShared=" + isShared);
+ // if (dist == -1) {
+ // if (isShared) {
+ // // if the node is a shared one, check if the next node is shared
+ // // if not, need to insert a new shared node
+ // return recur_getNewLocation(lattice, start, endSet, dist + 1, isShared);
+ // } else {
+ // return start;
+ // }
+ //
+ // }
+ return recur_getNewLocation(lattice, start, start, endSet, dist, isShared);
+ }
- Set<HNode> outSet = hierarchyGraph.getOutgoingNodeSet(curHierarchyNode);
- for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
- HNode outHierarchyNodeFromCurNode = (HNode) iterator2.next();
+ private String recur_getNewLocation(SSJavaLattice<String> lattice, String start, String cur,
+ Set<String> endSet, int dist, boolean isShared) {
+
+ System.out.println(" recur_getNewLocation cur=" + cur + " dist=" + dist);
+
+ if (dist == 0) {
+ if (isShared) {
+ // first check if there already exists a non-shared node at distance d
+ if (!isLocalLocation(lattice, cur) && !start.equals(cur)) {
+ // if not, need to insert a new local location at this point
+ System.out.println("if not, need to insert a new local location at this point");
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(lattice.get(cur));
+ lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ addLocalLocation(lattice, newLocName);
+
+ // assign the new local location to cur
+ cur = newLocName;
+ }
- // Set<HNode> incomingHNodeSetToOutNode = simpleHierarchyGraph.getIncomingNodeSet(outNode);
- System.out.println("outHierarchyNodeFromCurNode=" + outHierarchyNodeFromCurNode);
- // System.out.println("---incomingHNodeSetToOutNode=" + incomingHNodeSetToOutNode);
+ Set<String> connectedSet = lattice.get(cur);
+ if (connectedSet == null) {
+ connectedSet = new HashSet<String>();
+ }
+ System.out.println("cur=" + cur + " connectedSet=" + connectedSet);
- if (outHierarchyNodeFromCurNode.isSkeleton()
- || outHierarchyNodeFromCurNode.isCombinationNode()) {
- String lowerLocName = locSummary.getLocationName(outHierarchyNodeFromCurNode.getName());
- lattice.addRelationHigherToLower(curLocName, lowerLocName);
- } else {
- if (visited.containsAll(hierarchyGraph.getIncomingNodeSet(outHierarchyNodeFromCurNode))) {
- visited.add(outHierarchyNodeFromCurNode);
- int newidx = getCurrentHighestIndex(outHierarchyNodeFromCurNode, idx + 1);
- recurDFVisitNormalNode(scStartNode, scEndNodeSet, outHierarchyNodeFromCurNode, newidx,
- desc, lattice, visited, locSummary, mapIntermediateLoc);
+ // check if there already exists a shared node that has distance d + 1 on the chain
+ boolean needToInsertSharedNode = false;
+ if (connectedSet.equals(endSet)) {
+ needToInsertSharedNode = true;
} else {
- System.out.println("NOT RECUR");
- updateHighestIndex(outHierarchyNodeFromCurNode, idx + 1);
+ // in this case, the current node is in the middle of the chain
+ assert connectedSet.size() == 1;
+ String below = connectedSet.iterator().next();
+ if (lattice.isSharedLoc(below)) {
+ return below;
+ } else {
+ needToInsertSharedNode = true;
+ }
}
- }
-
- // if (!outNode.isSkeleton() && !outNode.isCombinationNode() && !visited.contains(outNode)) {
- // if (visited.containsAll(simpleHierarchyGraph.getIncomingNodeSet(outNode))) {
- // visited.add(outNode);
- // int newidx = getCurrentHighestIndex(outNode, idx + 1);
- // recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc,
- // newidx, locSummary, outNode);
- // // recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc,
- // // idx + 1, locSummary, outNode);
- // } else {
- // updateHighestIndex(outNode, idx + 1);
- // System.out.println("NOT RECUR");
- // }
- // } else if (!outNode.isSkeleton() && outNode.isCombinationNode() &&
- // !visited.contains(outNode)) {
- // if (needToExpandCombinationNode(desc, outNode)) {
- // System.out.println("NEED TO");
- // expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode);
- // } else {
- // System.out.println("NOT NEED TO");
- // }
- // }
-
- }
- }
-
- private void recurDFVisitCombinationNode(HNode scCombNode, Set<HNode> scEndNodeSet,
- HNode curHierarchyCombNode, int idx, Descriptor desc, SSJavaLattice<String> lattice,
- Set<HNode> visited, LocationSummary locSummary, Map<TripleItem, String> mapIntermediateLoc) {
-
- // Descriptor desc, SSJavaLattice<String> lattice,
- // HNode combinationNodeInSCGraph, Set<HNode> endNodeSet, Set<HNode> visited,
- // Map<TripleItem, String> mapIntermediateLoc, int idx, LocationSummary locSummary, HNode
- // curNode) {
+ if (needToInsertSharedNode) {
+ // no shared local location at d+1, need to insert it!
+ String newSharedLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(connectedSet);
+ lattice.insertNewLocationBetween(cur, lowerSet, newSharedLocName);
+ lattice.addSharedLoc(newSharedLocName);
+ addLocalLocation(lattice, newSharedLocName);
+ System.out.println(" INSERT NEW SHARED LOC=" + newSharedLocName);
+ cur = newSharedLocName;
+ }
- TripleItem item = new TripleItem(scCombNode, scEndNodeSet, idx);
+ return cur;
- if (!mapIntermediateLoc.containsKey(item)) {
- // need to create a new intermediate location in the lattice
- String above;
- if (idx == 1) {
- String newLocName = scCombNode.getName();
- mapIntermediateLoc.put(item, newLocName);
} else {
- String newLocName = "ILOC" + (LocationInference.locSeed++);
- int prevIdx = idx - 1;
- TripleItem prevItem = new TripleItem(scCombNode, scEndNodeSet, prevIdx);
- above = mapIntermediateLoc.get(prevItem);
- Set<String> belowSet = new HashSet<String>();
- for (Iterator iterator = scEndNodeSet.iterator(); iterator.hasNext();) {
- HNode endNode = (HNode) iterator.next();
- belowSet.add(endNode.getName());
- }
- lattice.insertNewLocationBetween(above, belowSet, newLocName);
- mapIntermediateLoc.put(item, newLocName);
+ return cur;
+ // if the node is not shared, check if a node at distance d is a local or combination node
+ // Set<String> connectedSet = lattice.get(cur);
+ // if (connectedSet == null) {
+ // connectedSet = new HashSet<String>();
+ // }
+ // System.out
+ // .println("if the node is not shared, check if a node at distance d is a local or combination node connectedSet="
+ // + connectedSet);
+ // // if (!start.equals(cur) && (cur.equals(lattice.getTopItem()) ||
+ // connectedSet.equals(endSet))) {
+ // // if not, need to insert a new local location at this point
+ // System.out.println("NEED TO INSERT A NEW LOCAL LOC connectedSet=" + connectedSet);
+ // String newLocName = "ILOC" + (LocationInference.locSeed++);
+ // Set<String> lowerSet = new HashSet<String>();
+ // lowerSet.addAll(connectedSet);
+ // lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ // addLocalLocation(lattice, newLocName);
+ // return newLocName;
+ // } else {
+ // return cur;
+ // }
}
+ }
+ Set<String> connectedSet = lattice.get(cur);
+ if (connectedSet == null) {
+ connectedSet = new HashSet<String>();
}
- HierarchyGraph hierarchyNode = infer.getSimpleHierarchyGraph(desc);
- String locName = mapIntermediateLoc.get(item);
- if (curHierarchyCombNode.isSharedNode()) {
- // if the current node is shared location, add a shared location to the lattice later
- mapSharedNodeToTripleItem.put(curHierarchyCombNode, item);
+ System.out.println("cur=" + cur + " connected set=" + connectedSet);
+ if (cur.equals(lattice.getTopItem()) || connectedSet.equals(endSet)) {
+ // if not, need to insert a new local location at this point
+ System.out.println("NEED TO INSERT A NEW LOCAL LOC FOR NEXT connectedSet=" + connectedSet);
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(connectedSet);
+ lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ addLocalLocation(lattice, newLocName);
+ cur = newLocName;
} else {
- Set<Descriptor> descSet = hierarchyNode.getDescSetOfNode(curHierarchyCombNode);
- for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
- Descriptor d = (Descriptor) iterator.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName);
- }
- locSummary.addMapHNodeNameToLocationName(curHierarchyCombNode.getName(), locName);
+ // in this case, the current node is in the middle of the chain
+ assert connectedSet.size() == 1;
+ cur = connectedSet.iterator().next();
}
- System.out.println("-TripleItem=" + item);
- System.out.println("-curNode=" + curHierarchyCombNode.getName() + " S="
- + curHierarchyCombNode.isSharedNode() + " locName=" + locName);
+ if (!lattice.isSharedLoc(cur)) {
+ dist--;
+ }
+ return recur_getNewLocation(lattice, start, cur, endSet, dist, isShared);
- Set<HNode> outSet = hierarchyNode.getOutgoingNodeSet(curHierarchyCombNode);
- for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
- HNode outHierarchyNode = (HNode) iterator2.next();
+ }
- System.out.println("---recurDFS outNode=" + outHierarchyNode);
- System.out.println("---outNode combinationNodeInSCGraph="
- + getCombinationNodeInSCGraph(desc, outHierarchyNode));
+ public String getNewLocation2(SSJavaLattice<String> lattice, String start, Set<String> endSet,
+ int dist, boolean isShared) {
+ System.out.println(" #GETNEWLOCATION:: start=" + start + " endSet=" + endSet + " dist="
+ + dist + " isShared=" + isShared);
+ if (dist == -1) {
+ if (isShared) {
+ // if the node is a shared one, check if the next node is shared
+ // if not, need to insert a new shared node
+ return recur_getNewLocation2(lattice, start, endSet, dist + 1, isShared);
+ } else {
+ return start;
+ }
- if (outHierarchyNode.isCombinationNode()) {
- HNode outCombinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, outHierarchyNode);
- if (outCombinationNodeInSCGraph.equals(scCombNode)) {
+ }
+ return recur_getNewLocation2(lattice, start, endSet, dist, isShared);
+ }
- Set<HNode> combineSkeletonNodeSet =
- hierarchyNode.getCombineSetByCombinationNode(outHierarchyNode);
- Set<HNode> incomingHNodeSetToOutNode = hierarchyNode.getIncomingNodeSet(outHierarchyNode);
- // extract nodes belong to the same combine node
- Set<HNode> incomingCombinedHNodeSet = new HashSet<HNode>();
- for (Iterator iterator = incomingHNodeSetToOutNode.iterator(); iterator.hasNext();) {
- HNode inNode = (HNode) iterator.next();
- if (combineSkeletonNodeSet.contains(inNode)) {
- incomingCombinedHNodeSet.add(inNode);
- }
- }
- System.out.println("incomingCombinedHNodeSet=" + incomingCombinedHNodeSet);
- if (visited.containsAll(incomingCombinedHNodeSet)) {
- visited.add(outHierarchyNode);
- System.out.println("-------curIdx=" + (idx + 1));
- int newIdx = getCurrentHighestIndex(outHierarchyNode, idx + 1);
- System.out.println("-------newIdx=" + newIdx);
- recurDFVisitCombinationNode(scCombNode, scEndNodeSet, outHierarchyNode, newIdx, desc,
- lattice, visited, locSummary, mapIntermediateLoc);
- } else {
- updateHighestIndex(outHierarchyNode, idx + 1);
- System.out.println("-----NOT RECUR!");
- }
+ private String recur_getNewLocation2(SSJavaLattice<String> lattice, String cur,
+ Set<String> endSet, int dist, boolean isShared) {
+ Set<String> connectedSet = lattice.get(cur);
+ if (connectedSet == null) {
+ connectedSet = new HashSet<String>();
+ }
+
+ System.out.println(" recur_getNewLocation::cur=" + cur + " dist=" + dist
+ + " connectedSet=" + connectedSet + " endSet=" + endSet);
+ if (dist == 0 && isShared) {
+ // if the node is shared,
+ // check if there already exists a shared node that has distance d + 1 on the chain
+ if ((cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+ || connectedSet.equals(endSet)) {
+ // need to insert a new shared location
+ // it is done after this if statement
+ } else {
+ assert connectedSet.size() == 1;
+ String below = connectedSet.iterator().next();
+ if (lattice.isSharedLoc(below)) {
+ return below;
}
}
- }
+ // need to insert a new shared location
+ Set<String> newChildSet = new HashSet<String>();
+ newChildSet.addAll(connectedSet);
- }
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ for (Iterator iterator = newChildSet.iterator(); iterator.hasNext();) {
+ String outNode = (String) iterator.next();
+ lattice.put(newLocName, outNode);
+ }
+ lattice.get(cur).clear();
+ lattice.put(cur, newLocName);
- private void expandCombinationNode(Descriptor desc, SSJavaLattice<String> lattice,
- Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
- HNode cnode) {
+ System.out.println(" INSERT NEW SHARED NODE=" + newLocName + " above=" + cur
+ + " below=" + lattice.get(newLocName));
- // expand the combination node 'outNode'
- // here we need to expand the corresponding combination location in the lattice
- HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode);
- Set<HNode> endNodeSet =
- infer.getSkeletonCombinationHierarchyGraph(desc).getOutgoingNodeSet(
- combinationNodeInSCGraph);
+ lattice.addSharedLoc(newLocName);
- System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph="
- + combinationNodeInSCGraph);
- System.out.println("endnodeset=" + endNodeSet);
+ return newLocName;
- if (combinationNodeInSCGraph == null) {
- return;
}
- // HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc);
- //
- // Set<HNode> combineSkeletonNodeSet = hierarchyGraph.getCombineSetByCombinationNode(cnode);
- //
- // // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet);
- //
- // Set<HNode> combinationNodeSet =
- // hierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet);
- //
- // // System.out.println("combinationNodeSet=" + combinationNodeSet);
- //
- // Set<HNode> endNodeSetFromSimpleGraph =
- // hierarchyGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet);
- // // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
- // Set<HNode> endCombNodeSet = new HashSet<HNode>();
- // for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) {
- // HNode endNode = (HNode) iterator3.next();
- // endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode));
- // }
+ String next;
- visited.add(cnode);
+ if (cur.equals(lattice.getTopItem()) || connectedSet.equals(endSet) /* || endSet.isEmpty() */) {
- // follows the straight line up to another skeleton/combination node
- if (endNodeSet.size() > 0) {
- // System.out.println("---endCombNodeSet=" + endCombNodeSet);
- endNodeSet = removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endNodeSet);
+ // if ( (cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+ // || connectedSet.equals(endSet)) {
+
+ // need to insert a new location
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ connectedSet.clear();
+ lattice.put(cur, newLocName);
+
+ System.out.println("#INSERT NEW RELATION cur=" + cur + " newLocName=" + newLocName + "::"
+ + lattice.get(cur));
- recurDFVisitCombinationNode(combinationNodeInSCGraph, endNodeSet, cnode, 1, desc, lattice,
- visited, locSummary, mapIntermediateLoc);
+ for (Iterator iterator = endSet.iterator(); iterator.hasNext();) {
+ String endNode = (String) iterator.next();
+ lattice.put(newLocName, endNode);
+ }
+ next = newLocName;
+ System.out.println(" INSERT NEW NODE=" + newLocName + " above=" + cur + " below="
+ + endSet);
} else {
- endNodeSet.add(LocationInference.BOTTOMHNODE);
- // System.out.println("---endCombNodeSet is zero");
- // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
- // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode));
- recurDFVisitCombinationNode(combinationNodeInSCGraph, endNodeSet, cnode, 1, desc, lattice,
- visited, locSummary, mapIntermediateLoc);
+ assert connectedSet.size() == 1;
+ next = connectedSet.iterator().next();
+ if (lattice.isSharedLoc(next)) {
+ return recur_getNewLocation2(lattice, next, endSet, dist, isShared);
+ }
+ }
+ System.out.println(" next=" + next);
+
+ if (dist == 0) {
+ return next;
+ } else {
+ if (!lattice.isSharedLoc(next)) {
+ dist--;
+ }
+ return recur_getNewLocation2(lattice, next, endSet, dist, isShared);
}
}
public SSJavaLattice<String> insertIntermediateNodesToStraightLine2(Descriptor desc,
SSJavaLattice<String> skeletonLattice) {
+ // copy nodes/edges from the parent method/class if possible
+ SSJavaLattice<String> lattice = skeletonLattice.clone();
+
+ Descriptor parentDesc = getParent(desc);
+ if (parentDesc != null) {
+ SSJavaLattice<String> parentLattice = infer.getLattice(parentDesc);
+
+ Map<String, Set<String>> parentMap = parentLattice.getTable();
+ Set<String> parentKeySet = parentMap.keySet();
+ for (Iterator iterator = parentKeySet.iterator(); iterator.hasNext();) {
+ String parentKey = (String) iterator.next();
+ Set<String> parentValueSet = parentMap.get(parentKey);
+ for (Iterator iterator2 = parentValueSet.iterator(); iterator2.hasNext();) {
+ String value = (String) iterator2.next();
+ lattice.put(parentKey, value);
+ }
+ }
+
+ Set<String> parentSharedLocSet = parentLattice.getSharedLocSet();
+ for (Iterator iterator = parentSharedLocSet.iterator(); iterator.hasNext();) {
+ String parentSharedLoc = (String) iterator.next();
+ lattice.addSharedLoc(parentSharedLoc);
+ }
+ }
+
+ // ////
// perform DFS that starts from each skeleton/combination node and ends by another
// skeleton/combination node
HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
LocationSummary locSummary = infer.getLocationSummary(desc);
- SSJavaLattice<String> lattice = skeletonLattice.clone();
-
Set<HNode> visited = new HashSet<HNode>();
Set<HNode> nodeSet = simpleGraph.getNodeSet();
- Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
+ Map<TripleItem, String> mapIntermediateLoc = getIntermediateLocMap(desc);
+ // Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
// System.out.println("*insert=" + desc);
// System.out.println("***nodeSet=" + nodeSet);
if (outNode.isCombinationNode()) {
if (visited.containsAll(simpleGraph.getIncomingNodeSet(outNode))) {
// if (needToExpandCombinationNode(desc, outNode)) {
- expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary,
+ expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary,
outNode);
// }
}
// startNode = node;
// }
- Set<HNode> endNodeSetFromSimpleGraph =
- simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(outNode, null);
+ // TODO
+ // Set<HNode> endNodeSetFromSimpleGraph =
+ // simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(outNode, null);
+ // Set<HNode> endCombNodeSet = new HashSet<HNode>();
+ // for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator();
+ // iterator3.hasNext();) {
+ // HNode endNode = (HNode) iterator3.next();
+ // endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode));
+ // }
+
+ Set<HNode> endCombNodeSet = scGraph.getOutgoingNodeSet(startNode);
- // System.out.println("endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph
- // + " from=" + outNode);
- Set<HNode> endCombNodeSet = new HashSet<HNode>();
- for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) {
- HNode endNode = (HNode) iterator3.next();
- endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode));
- }
// System.out.println("endCombNodeSet=" + endCombNodeSet);
visited.add(outNode);
if (endCombNodeSet.size() > 0) {
HNode sharedNode = (HNode) iterator.next();
TripleItem item = mapSharedNodeToTripleItem.get(sharedNode);
String nonSharedLocName = mapIntermediateLoc.get(item);
- // System.out.println("sharedNode=" + sharedNode + " locName=" + nonSharedLocName);
+
+ System.out.println("sharedNode=" + sharedNode + " locName=" + nonSharedLocName);
String newLocName;
if (locSummary.getHNodeNameSetByLatticeLoationName(nonSharedLocName) != null
Set<String> belowElementSet = new HashSet<String>();
belowElementSet.addAll(lattice.get(nonSharedLocName));
- // System.out.println("nonSharedLocName=" + nonSharedLocName + " belowElementSet="
- // + belowElementSet + " newLocName=" + newLocName);
+ System.out.println("nonSharedLocName=" + nonSharedLocName + " belowElementSet="
+ + belowElementSet + " newLocName=" + newLocName);
lattice.insertNewLocationBetween(nonSharedLocName, belowElementSet, newLocName);
} else {
return true;
}
+ private void expandCombinationNode(Descriptor desc, SSJavaLattice<String> lattice,
+ Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
+ HNode cnode) {
+
+ // expand the combination node 'outNode'
+ // here we need to expand the corresponding combination location in the lattice
+ HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode);
+
+ System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph="
+ + combinationNodeInSCGraph);
+
+ if (combinationNodeInSCGraph == null) {
+ return;
+ }
+
+ HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc);
+ HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
+
+ Set<HNode> combineSkeletonNodeSet = simpleGraph.getCombineSetByCombinationNode(cnode);
+
+ // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet);
+
+ Set<HNode> combinationNodeSet =
+ simpleGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet);
+
+ // System.out.println("combinationNodeSet=" + combinationNodeSet);
+
+ // TODO
+ // Set<HNode> endNodeSetFromSimpleGraph =
+ // simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet);
+ // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
+ // Set<HNode> endCombNodeSet = new HashSet<HNode>();
+ // for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) {
+ // HNode endNode = (HNode) iterator3.next();
+ // endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode));
+ // }
+
+ Set<HNode> endCombNodeSet = scGraph.getOutgoingNodeSet(combinationNodeInSCGraph);
+ visited.add(cnode);
+
+ // follows the straight line up to another skeleton/combination node
+ if (endCombNodeSet.size() > 0) {
+ // System.out.println("---endCombNodeSet=" + endCombNodeSet);
+ endCombNodeSet =
+ removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endCombNodeSet);
+
+ recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
+ mapIntermediateLoc, 1, locSummary, cnode);
+ } else {
+ endCombNodeSet.add(LocationInference.BOTTOMHNODE);
+ // System.out.println("---endCombNodeSet is zero");
+ // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
+ // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode));
+ recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
+ mapIntermediateLoc, 1, locSummary, cnode);
+
+ }
+
+ }
+
private Set<HNode> removeTransitivelyReachToNode(Descriptor desc, HNode startNode,
Set<HNode> endNodeSet) {
return connected.iterator().next();
}
- private void expandCombinationNode3(Descriptor desc, SSJavaLattice<String> lattice,
- Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
- HNode cnode) {
-
- // expand the combination node 'outNode'
- // here we need to expand the corresponding combination location in the lattice
- HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode);
-
- System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph="
- + combinationNodeInSCGraph);
-
- if (combinationNodeInSCGraph == null) {
- return;
- }
-
- HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc);
-
- Set<HNode> combineSkeletonNodeSet = simpleGraph.getCombineSetByCombinationNode(cnode);
-
- // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet);
-
- Set<HNode> combinationNodeSet =
- simpleGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet);
-
- // System.out.println("combinationNodeSet=" + combinationNodeSet);
-
- Set<HNode> endNodeSetFromSimpleGraph =
- simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet);
- // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
- Set<HNode> endCombNodeSet = new HashSet<HNode>();
- for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) {
- HNode endNode = (HNode) iterator3.next();
- endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode));
- }
- visited.add(cnode);
-
- // follows the straight line up to another skeleton/combination node
- if (endCombNodeSet.size() > 0) {
- // System.out.println("---endCombNodeSet=" + endCombNodeSet);
- endCombNodeSet =
- removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endCombNodeSet);
-
- recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
- mapIntermediateLoc, 1, locSummary, cnode);
- } else {
- endCombNodeSet.add(LocationInference.BOTTOMHNODE);
- // System.out.println("---endCombNodeSet is zero");
- // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
- // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode));
- recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
- mapIntermediateLoc, 1, locSummary, cnode);
-
- }
-
- }
-
private void recurDirectlyReachableNodeFromStartNodeReachToEndNode(HierarchyGraph scGraph,
HNode startNode, HNode curNode, Set<HNode> connected) {
int idx, LocationSummary locSummary, HNode curNode) {
TripleItem item = new TripleItem(startNode, endNodeSet, idx);
- // System.out.println("item=" + item);
if (!mapIntermediateLoc.containsKey(item)) {
// need to create a new intermediate location in the lattice
String newLocName = "ILOC" + (LocationInference.locSeed++);
if (curNode.isSharedNode()) {
// if the current node is shared location, add a shared location to the lattice later
+ System.out.println("###SHARED ITEM=" + item);
mapSharedNodeToTripleItem.put(curNode, item);
} else {
Set<Descriptor> descSet = simpleHierarchyGraph.getDescSetOfNode(curNode);
System.out.println("---incomingHNodeSetToOutNode=" + incomingHNodeSetToOutNode);
if (!outNode.isSkeleton() && !outNode.isCombinationNode() && !visited.contains(outNode)) {
+ Pair<HNode, HNode> pair = new Pair(startNode, outNode);
if (visited.containsAll(simpleHierarchyGraph.getIncomingNodeSet(outNode))) {
visited.add(outNode);
- int newidx = getCurrentHighestIndex(outNode, idx + 1);
+ int newidx = getCurrentHighestIndex(pair, idx + 1);
+ // int newidx = getCurrentHighestIndex(outNode, idx + 1);
recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc,
newidx, locSummary, outNode);
// recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc,
// idx + 1, locSummary, outNode);
} else {
- updateHighestIndex(outNode, idx + 1);
+ updateHighestIndex(pair, idx + 1);
+ // updateHighestIndex(outNode, idx + 1);
System.out.println("NOT RECUR");
}
} else if (!outNode.isSkeleton() && outNode.isCombinationNode() && !visited.contains(outNode)) {
if (needToExpandCombinationNode(desc, outNode)) {
System.out.println("NEED TO");
- expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode);
+ expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode);
} else {
System.out.println("NOT NEED TO");
}
String locName = mapIntermediateLoc.get(item);
if (curNode.isSharedNode()) {
// if the current node is shared location, add a shared location to the lattice later
+ System.out.println("###SHARED ITEM=" + item);
mapSharedNodeToTripleItem.put(curNode, item);
} else {
Set<Descriptor> descSet = simpleHierarchyGraph.getDescSetOfNode(curNode);
// check whether the next combination node is different from the current node
if (combinationNodeInSCGraph.equals(getCombinationNodeInSCGraph(desc, outNode))) {
+ Pair<HNode, HNode> pair = new Pair(combinationNodeInSCGraph, outNode);
if (visited.containsAll(incomingCombinedHNodeSet)) {
visited.add(outNode);
System.out.println("-------curIdx=" + (idx + 1));
- int newIdx = getCurrentHighestIndex(outNode, idx + 1);
+
+ int newIdx = getCurrentHighestIndex(pair, idx + 1);
+ // int newIdx = getCurrentHighestIndex(outNode, idx + 1);
System.out.println("-------newIdx=" + newIdx);
recurDFS(desc, lattice, combinationNodeInSCGraph, endNodeSet, visited,
mapIntermediateLoc, newIdx, locSummary, outNode);
// recurDFS(desc, lattice, combinationNodeInSCGraph, endNodeSet, visited,
// mapIntermediateLoc, idx + 1, locSummary, outNode);
} else {
- updateHighestIndex(outNode, idx + 1);
+ updateHighestIndex(pair, idx + 1);
+ // updateHighestIndex(outNode, idx + 1);
System.out.println("-----NOT RECUR!");
}
} else {
if (needToExpandCombinationNode(desc, outNode)) {
System.out.println("NEED TO");
- expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary,
- outNode);
+ expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode);
} else {
System.out.println("NOT NEED TO");
}
}
+ private int getCurrentHighestIndex(Pair<HNode, HNode> pair, int curIdx) {
+ int recordedIdx = getCurrentHighestIndex(pair);
+ if (recordedIdx > curIdx) {
+ return recordedIdx;
+ } else {
+ return curIdx;
+ }
+ }
+
private int getCurrentHighestIndex(HNode node, int curIdx) {
int recordedIdx = getCurrentHighestIndex(node);
if (recordedIdx > curIdx) {
}
}
+ private int getCurrentHighestIndex(Pair<HNode, HNode> pair) {
+ if (!mapItemToHighestIndex.containsKey(pair)) {
+ mapItemToHighestIndex.put(pair, new Integer(-1));
+ }
+ return mapItemToHighestIndex.get(pair).intValue();
+ }
+
+ private void updateHighestIndex(Pair<HNode, HNode> pair, int idx) {
+ if (idx > getCurrentHighestIndex(pair)) {
+ mapItemToHighestIndex.put(pair, new Integer(idx));
+ }
+ }
+
private int getCurrentHighestIndex(HNode node) {
if (!mapHNodeToHighestIndex.containsKey(node)) {
mapHNodeToHighestIndex.put(node, new Integer(-1));
private void debug_print(HierarchyGraph inputGraph) {
System.out.println("\nBuild Lattice:" + inputGraph.getName());
- // System.out.println("Node2Index:\n" + inputGraph.getMapHNodeToUniqueIndex());
- // System.out.println("Node2Basis:\n" + inputGraph.getMapHNodeToBasis());
+ System.out.println("Node2Index:\n" + inputGraph.getMapHNodeToUniqueIndex());
+ System.out.println("Node2Basis:\n" + inputGraph.getMapHNodeToBasis());
}
}