more implementation for the inference: propagating relations of callee parameters...
[IRC.git] / Robust / src / Analysis / SSJava / FlowNode.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import IR.Descriptor;
8
9 public class FlowNode {
10
11   // descriptor tuple is a unique identifier of the flow node
12   private NTuple<Descriptor> descTuple;
13
14   // if the infer node represents the base type of field access,
15   // this set contains fields of the base type
16   private Set<FlowNode> fieldNodeSet;
17
18   // set true if this node is driven from a paramter
19   private boolean isParameter;
20
21   public Set<FlowNode> getFieldNodeSet() {
22     return fieldNodeSet;
23   }
24
25   private Set<FlowEdge> outEdgeSet;
26
27   public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
28
29     this.isParameter = isParam;
30
31     NTuple<Descriptor> base = null;
32     Descriptor desc = null;
33     if (tuple.size() > 1) {
34       base = tuple.subList(0, tuple.size() - 1);
35       desc = tuple.get(tuple.size() - 1);
36     } else {
37       base = tuple;
38     }
39     fieldNodeSet = new HashSet<FlowNode>();
40     descTuple = new NTuple<Descriptor>();
41     if (base != null) {
42       descTuple.addAll(base);
43     }
44     if (desc != null) {
45       descTuple.add(desc);
46     }
47     outEdgeSet = new HashSet<FlowEdge>();
48   }
49
50   public void addFieldNode(FlowNode node) {
51     fieldNodeSet.add(node);
52   }
53
54   public boolean isParameter() {
55     return isParameter;
56   }
57
58   public NTuple<Descriptor> getDescTuple() {
59     return descTuple;
60   }
61
62   public Descriptor getOwnDescriptor() {
63     return descTuple.get(descTuple.size() - 1);
64   }
65
66   public String toString() {
67     String rtr = "[FlowNode]:";
68     if (isParameter()) {
69       rtr += "param:";
70     }
71     rtr += ":" + descTuple;
72     return rtr;
73   }
74
75   public Iterator<FlowEdge> iteratorOfOutEdges() {
76     return outEdgeSet.iterator();
77   }
78
79   public void addOutEdge(FlowEdge out) {
80     outEdgeSet.add(out);
81   }
82
83   public Set<FlowEdge> getOutEdgeSet() {
84     return outEdgeSet;
85   }
86
87   public int hashCode() {
88     return 7 + descTuple.hashCode();
89   }
90
91   public boolean equals(Object obj) {
92
93     if (obj instanceof FlowNode) {
94       FlowNode in = (FlowNode) obj;
95       if (descTuple.equals(in.getDescTuple())) {
96         return true;
97       }
98     }
99
100     return false;
101
102   }
103
104   public String getID() {
105     String id = "";
106     for (int i = 0; i < descTuple.size(); i++) {
107       id += descTuple.get(i).getSymbol();
108     }
109     return id;
110   }
111
112   public String getPrettyID() {
113     String id = "<";
114     for (int i = 0; i < descTuple.size(); i++) {
115       if (i != 0) {
116         id += ",";
117       }
118       id += descTuple.get(i).getSymbol();
119     }
120     id += ">";
121     return id;
122   }
123 }