Set<FlowNode> returnNodeSet;
FlowNode thisVarNode;
+ Map<FlowNode, Set<FlowEdge>> mapFlowNodeToInEdgeSet;
Map<FlowNode, Set<FlowEdge>> mapFlowNodeToOutEdgeSet;
Map<NTuple<Location>, FlowNode> mapLocTupleToFlowNode;
this.returnNodeSet = new HashSet<FlowNode>();
this.mapIdxToFlowNode = new HashMap<Integer, FlowNode>();
this.mapFlowNodeToOutEdgeSet = new HashMap<FlowNode, Set<FlowEdge>>();
+ this.mapFlowNodeToInEdgeSet = new HashMap<FlowNode, Set<FlowEdge>>();
if (!md.isStatic()) {
// create a node for 'this' varialbe
return mapFlowNodeToOutEdgeSet.get(node);
}
+ public Set<FlowEdge> getInEdgeSet(FlowNode node) {
+ if (!mapFlowNodeToInEdgeSet.containsKey(node)) {
+ mapFlowNodeToInEdgeSet.put(node, new HashSet<FlowEdge>());
+ }
+ return mapFlowNodeToInEdgeSet.get(node);
+ }
+
public void addValueFlowEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
FlowNode fromNode = getFlowNode(fromDescTuple);
FlowNode toNode = getFlowNode(toDescTuple);
+ if (toNode.getDescTuple().get(0).equals(LocationInference.LITERALDESC)) {
+ return;
+ }
+
// System.out.println("create an edge from " + fromNode + " to " + toNode);
int fromTupleSize = fromDescTuple.size();
FlowEdge edge = new FlowEdge(fromNode, toNode, initTuple, endTuple);
addOutEdge(fromNode, edge);
+ addInEdge(toNode, edge);
// System.out.println("add a new edge=" + edge);
}
+ private void addInEdge(FlowNode toNode, FlowEdge edge) {
+ getInEdgeSet(toNode).add(edge);
+ }
+
private void addOutEdge(FlowNode fromNode, FlowEdge edge) {
if (!mapFlowNodeToOutEdgeSet.containsKey(fromNode)) {
mapFlowNodeToOutEdgeSet.put(fromNode, new HashSet<FlowEdge>());
mapFlowNodeToOutEdgeSet.get(fromNode).add(edge);
}
+ public boolean contains(NTuple<Descriptor> descTuple) {
+ return mapDescTupleToInferNode.containsKey(descTuple);
+ }
+
public FlowNode getFlowNode(NTuple<Descriptor> descTuple) {
if (!mapDescTupleToInferNode.containsKey(descTuple)) {
FlowNode node = createNewFlowNode(descTuple);
}
FlowNode node = mapDescTupleToInferNode.get(tuple);
- node.setReturn(true);
-
returnNodeSet.add(node);
}
Descriptor localDesc = fn.getDescTuple().get(0);
+ System.out.println("descTuple=" + descTuple);
+
if (fn.isIntermediate()) {
Location interLoc = new Location(md, localDesc.getSymbol());
interLoc.setLocDescriptor(localDesc);
locTuple.add(interLoc);
- } else if (localDesc.getSymbol().equals(LocationInference.TOPLOC)) {
+ } else if (localDesc.getSymbol().equals(SSJavaAnalysis.TOP)) {
Location topLoc = new Location(md, Location.TOP);
topLoc.setLocDescriptor(LocationInference.TOPDESC);
locTuple.add(topLoc);
if (i == 0) {
loc = new Location(md, curDesc.getSymbol());
loc.setLocDescriptor(curDesc);
- cd = ((VarDescriptor) curDesc).getType().getClassDesc();
+ if (curDesc instanceof VarDescriptor) {
+ cd = ((VarDescriptor) curDesc).getType().getClassDesc();
+ } else {
+ // otherwise it should be the last element
+ cd = null;
+ }
} else {
loc = new Location(cd, curDesc.getSymbol());
loc.setLocDescriptor(curDesc);
if (curDesc instanceof FieldDescriptor) {
cd = ((FieldDescriptor) curDesc).getType().getClassDesc();
- } else {
+ } else if (curDesc instanceof LocationDescriptor) {
cd = ((LocationDescriptor) curDesc).getEnclosingClassDesc();
+ } else {
+ // otherwise it should be the last element of the tuple
+ cd = null;
}
}
return mapFlowNodeToOutEdgeSet;
}
+ public Set<FlowNode> getIncomingNodeSetByPrefix(Descriptor prefix) {
+
+ Set<FlowNode> incomingNodeSet = new HashSet<FlowNode>();
+
+ for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+ FlowNode curNode = (FlowNode) iterator.next();
+ Set<FlowEdge> outEdgeSet = getOutEdgeSet(curNode);
+
+ for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
+ FlowEdge outEdge = (FlowEdge) iterator2.next();
+
+ if (outEdge.getEndTuple().startsWith(prefix)) {
+ incomingNodeSet.add(curNode);
+ recurIncomingNodeSetByPrefix(prefix, curNode, incomingNodeSet);
+
+ }
+
+ }
+ }
+
+ return incomingNodeSet;
+
+ }
+
+ private void recurIncomingNodeSetByPrefix(Descriptor prefix, FlowNode node, Set<FlowNode> visited) {
+
+ Set<FlowEdge> inEdgeSet = getInEdgeSet(node);
+
+ for (Iterator iterator = inEdgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge inEdge = (FlowEdge) iterator.next();
+
+ FlowNode inNode = getFlowNode(inEdge.getInitTuple());
+ if (!inEdge.getInitTuple().startsWith(prefix) && !visited.contains(inNode)) {
+ visited.add(inNode);
+ recurIncomingNodeSetByPrefix(prefix, inNode, visited);
+ }
+ }
+
+ }
+
public void setMapFlowNodeToOutEdgeSet(Map<FlowNode, Set<FlowEdge>> inMap) {
Set<FlowNode> keySet = inMap.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
bw.write("}\n");
}
+
}
\ No newline at end of file