major revisions on FlowGraph to have more precise information
[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 import IR.FieldDescriptor;
9 import IR.VarDescriptor;
10
11 public class FlowNode {
12
13   // descriptor tuple is a unique identifier of the flow node
14   private NTuple<Location> locTuple;
15
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;
19
20   // set true if this node stores a return value
21   private boolean isReturn;
22
23   private boolean isDeclarationNode = false;
24
25   private boolean isIntermediate;
26
27   private CompositeLocation compLoc;
28
29   private boolean isSkeleton;
30
31   public boolean isIntermediate() {
32     return isIntermediate;
33   }
34
35   public void setIntermediate(boolean isIntermediate) {
36     this.isIntermediate = isIntermediate;
37   }
38
39   public Set<FlowNode> getFieldNodeSet() {
40     return fieldNodeSet;
41   }
42
43   public FlowNode(NTuple<Location> tuple) {
44
45     this.isSkeleton = false;
46     this.isIntermediate = false;
47
48     NTuple<Location> base = null;
49     Location loc = null;
50     if (tuple.size() > 1) {
51       base = tuple.subList(0, tuple.size() - 1);
52       loc = tuple.get(tuple.size() - 1);
53     } else {
54       base = tuple;
55     }
56     fieldNodeSet = new HashSet<FlowNode>();
57     locTuple = new NTuple<Location>();
58     if (base != null) {
59       locTuple.addAll(base);
60     }
61     if (loc != null) {
62       locTuple.add(loc);
63     }
64
65   }
66
67   public void setCompositeLocation(CompositeLocation in) {
68     compLoc = in;
69   }
70
71   public CompositeLocation getCompositeLocation() {
72     return compLoc;
73   }
74
75   public void addFieldNode(FlowNode node) {
76     fieldNodeSet.add(node);
77   }
78
79   public NTuple<Location> getLocTuple() {
80     return locTuple;
81   }
82
83   public boolean isReturn() {
84     return isReturn;
85   }
86
87   public void setReturn(boolean isReturn) {
88     this.isReturn = isReturn;
89   }
90
91   public String toString() {
92     String rtr = "[FlowNode]:";
93     if (isSkeleton()) {
94       rtr += "SKELETON:";
95     }
96     rtr += ":" + locTuple;
97     return rtr;
98   }
99
100   public int hashCode() {
101     return 7 + locTuple.hashCode();
102   }
103
104   public boolean equals(Object obj) {
105
106     if (obj instanceof FlowNode) {
107       FlowNode in = (FlowNode) obj;
108       if (locTuple.equals(in.getLocTuple())) {
109         return true;
110       }
111     }
112
113     return false;
114
115   }
116
117   public String getID() {
118     String id = "";
119     for (int i = 0; i < locTuple.size(); i++) {
120       id += locTuple.get(i).getSymbol();
121     }
122     return id;
123   }
124
125   public String getPrettyID() {
126     String id = "<";
127     String property = "";
128     for (int i = 0; i < locTuple.size(); i++) {
129       if (i != 0) {
130         id += ",";
131       }
132       id += locTuple.get(i).getSymbol();
133     }
134     id += ">";
135
136     if (compLoc != null) {
137       id += " " + compLoc;
138     }
139
140     // if (isReturn()) {
141     // property += "R";
142     // }
143     //
144     // if (isSkeleton()) {
145     // property += "S";
146     // }
147
148     if (property.length() > 0) {
149       property = " [" + property + "]";
150     }
151
152     return id + property;
153   }
154
155   public void setDeclarationNode() {
156     isDeclarationNode = true;
157   }
158
159   public boolean isDeclaratonNode() {
160     return isDeclarationNode;
161   }
162
163   public NTuple<Location> getCurrentLocTuple() {
164     if (compLoc == null) {
165       return locTuple;
166     }
167     NTuple<Location> curLocTuple = new NTuple<Location>();
168     for (int i = 0; i < compLoc.getSize(); i++) {
169       Location locElement = compLoc.get(i);
170       curLocTuple.add(locElement);
171     }
172     return curLocTuple;
173   }
174
175   public NTuple<Descriptor> getCurrentDescTuple() {
176
177     if (compLoc == null) {
178       return getDescTuple();
179     }
180
181     NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
182     for (int i = 0; i < compLoc.getSize(); i++) {
183       Location locElement = compLoc.get(i);
184       curDescTuple.add(locElement.getLocDescriptor());
185     }
186     return curDescTuple;
187   }
188
189   public boolean isSkeleton() {
190     return isSkeleton;
191   }
192
193   public void setSkeleton(boolean isSkeleton) {
194     this.isSkeleton = isSkeleton;
195   }
196
197   public NTuple<Descriptor> getDescTuple() {
198     NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
199     for (int i = 0; i < locTuple.size(); i++) {
200       descTuple.add(locTuple.get(i).getLocDescriptor());
201     }
202     return descTuple;
203   }
204
205 }