1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Iterator;
8 import IR.FieldDescriptor;
9 import IR.VarDescriptor;
11 public class FlowNode {
13 // descriptor tuple is a unique identifier of the flow node
14 private NTuple<Descriptor> descTuple;
16 // if the infer node represents the base type of field access,
17 // this set contains fields of the base type
18 private Set<FlowNode> fieldNodeSet;
20 // set true if this node is driven from a paramter
21 private boolean isParameter;
23 // set true if this node stores a return value
24 private boolean isReturn;
26 public Set<FlowNode> getFieldNodeSet() {
30 private Set<FlowEdge> outEdgeSet;
32 public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
34 this.isParameter = isParam;
36 NTuple<Descriptor> base = null;
37 Descriptor desc = null;
38 if (tuple.size() > 1) {
39 base = tuple.subList(0, tuple.size() - 1);
40 desc = tuple.get(tuple.size() - 1);
44 fieldNodeSet = new HashSet<FlowNode>();
45 descTuple = new NTuple<Descriptor>();
47 descTuple.addAll(base);
52 outEdgeSet = new HashSet<FlowEdge>();
55 public void addFieldNode(FlowNode node) {
56 fieldNodeSet.add(node);
59 public boolean isParameter() {
63 public NTuple<Descriptor> getDescTuple() {
67 public Descriptor getOwnDescriptor() {
68 return descTuple.get(descTuple.size() - 1);
71 public boolean isReturn() {
75 public void setReturn(boolean isReturn) {
76 this.isReturn = isReturn;
79 public boolean isPrimitiveType() {
80 Descriptor desc = descTuple.get(descTuple.size() - 1);
81 if (desc instanceof VarDescriptor) {
82 return ((VarDescriptor) desc).getType().isPrimitive();
83 } else if (desc instanceof FieldDescriptor) {
84 return ((FieldDescriptor) desc).getType().isPrimitive();
89 public String toString() {
90 String rtr = "[FlowNode]:";
94 rtr += ":" + descTuple;
98 public Iterator<FlowEdge> iteratorOfOutEdges() {
99 return outEdgeSet.iterator();
102 public void addOutEdge(FlowEdge out) {
106 public Set<FlowEdge> getOutEdgeSet() {
110 public int hashCode() {
111 return 7 + descTuple.hashCode();
114 public boolean equals(Object obj) {
116 if (obj instanceof FlowNode) {
117 FlowNode in = (FlowNode) obj;
118 if (descTuple.equals(in.getDescTuple())) {
127 public String getID() {
129 for (int i = 0; i < descTuple.size(); i++) {
130 id += descTuple.get(i).getSymbol();
135 public String getPrettyID() {
137 for (int i = 0; i < descTuple.size(); i++) {
141 id += descTuple.get(i).getSymbol();