Set<FlowNode> returnNodeSet;
FlowNode thisVarNode;
+ Map<NTuple<Location>, FlowNode> mapLocTupleToFlowNode;
+ Map<FlowNode, NTuple<Location>> mapFlowNodeToLocTuple;
+
// maps the composite representation of field/var descriptors to infer nodes
Map<NTuple<Descriptor>, FlowNode> mapDescTupleToInferNode;
public FlowGraph(MethodDescriptor md, Map<Descriptor, Integer> mapParamDescToIdx) {
this.md = md;
+ this.mapFlowNodeToLocTuple = new HashMap<FlowNode, NTuple<Location>>();
+ this.mapLocTupleToFlowNode = new HashMap<NTuple<Location>, FlowNode>();
this.nodeSet = new HashSet<FlowNode>();
this.mapDescTupleToInferNode = new HashMap<NTuple<Descriptor>, FlowNode>();
this.mapNodeToNeighborSet = new HashMap<NTuple<Descriptor>, Set<FlowNode>>();
this.mapParamDescToIdx.putAll(mapParamDescToIdx);
this.returnNodeSet = new HashSet<FlowNode>();
- // create a node for 'this' varialbe
- NTuple<Descriptor> thisDescTuple = new NTuple<Descriptor>();
- thisDescTuple.add(md.getThis());
- FlowNode thisNode = new FlowNode(thisDescTuple, true);
- NTuple<Descriptor> thisVarTuple = new NTuple<Descriptor>();
- thisVarTuple.add(md.getThis());
- createNewFlowNode(thisVarTuple);
- thisVarNode = thisNode;
+ if (!md.isStatic()) {
+ // create a node for 'this' varialbe
+ NTuple<Descriptor> thisDescTuple = new NTuple<Descriptor>();
+ thisDescTuple.add(md.getThis());
+ FlowNode thisNode = new FlowNode(thisDescTuple, true);
+ NTuple<Descriptor> thisVarTuple = new NTuple<Descriptor>();
+ thisVarTuple.add(md.getThis());
+ createNewFlowNode(thisVarTuple);
+ thisVarNode = thisNode;
+ }
}
}
set.add(neighbor);
- System.out.println("add a new neighbor " + neighbor + " to " + node);
+ // System.out.println("add a new neighbor " + neighbor + " to " + node);
}
public boolean hasEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
public void addValueFlowEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
- FlowNode fromNode = mapDescTupleToInferNode.get(fromDescTuple);
- FlowNode toNode = mapDescTupleToInferNode.get(toDescTuple);
+ FlowNode fromNode = getFlowNode(fromDescTuple);
+ FlowNode toNode = getFlowNode(toDescTuple);
- System.out.println("create an edge from " + fromNode + " to " + toNode);
+ // System.out.println("create an edge from " + fromNode + " to " + toNode);
int fromTupleSize = fromDescTuple.size();
NTuple<Descriptor> curTuple = new NTuple<Descriptor>();
FlowEdge edge = new FlowEdge(fromNode, toNode, initTuple, endTuple);
fromNode.addOutEdge(edge);
- System.out.println("add a new edge=" + edge);
+ // System.out.println("add a new edge=" + edge);
}
if (!mapDescTupleToInferNode.containsKey(tuple)) {
- FlowNode node = new FlowNode(tuple, isParamter(tuple));
+ FlowNode node = new FlowNode(tuple, isParameter(tuple));
mapDescTupleToInferNode.put(tuple, node);
nodeSet.add(node);
+ mapLocTupleToFlowNode.put(getLocationTuple(node), node);
+
if (tuple.size() > 1) {
NTuple<Descriptor> baseTuple = tuple.subList(0, tuple.size() - 1);
getFlowNode(baseTuple).addFieldNode(node);
}
- System.out.println("Creating new node=" + node);
+ // System.out.println("Creating new node=" + node);
return node;
} else {
return mapDescTupleToInferNode.get(tuple);
return visited;
}
- public NTuple<Location> getLocationTuple(FlowNode fn) {
-
- NTuple<Descriptor> descTuple = fn.getDescTuple();
-
- NTuple<Location> locTuple = new NTuple<Location>();
+ public NTuple<Location> getLocationTuple(NTuple<Descriptor> descTuple) {
+ return getLocationTuple(getFlowNode(descTuple));
+ }
- ClassDescriptor cd = null;
+ public NTuple<Location> getLocationTuple(FlowNode fn) {
- for (int i = 0; i < descTuple.size(); i++) {
- Descriptor d = descTuple.get(i);
- Location loc;
- if (i == 0) {
- loc = new Location(md, d.getSymbol());
- cd = ((VarDescriptor) d).getType().getClassDesc();
+ 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 (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 {
- loc = new Location(cd, d.getSymbol());
- cd = ((FieldDescriptor) d).getType().getClassDesc();
+ // 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);
+ cd = ((FieldDescriptor) curDesc).getType().getClassDesc();
+ }
+ locTuple.add(loc);
+ }
}
- locTuple.add(loc);
- }
- return locTuple;
+ mapFlowNodeToLocTuple.put(fn, locTuple);
+ }
+ return mapFlowNodeToLocTuple.get(fn);
}
public Set<FlowNode> getIncomingFlowNodeSet(FlowNode node) {
return set;
}
- public boolean isParamter(NTuple<Descriptor> tuple) {
+ public boolean isParameter(NTuple<Descriptor> tuple) {
// return true if a descriptor tuple is started with a parameter descriptor
Descriptor firstIdxDesc = tuple.get(0);
return mapParamDescToIdx.containsKey(firstIdxDesc);