changes: 1) fixes problems in the original EyeTracking benchmark 2) fix a bug in...
[IRC.git] / Robust / src / Analysis / SSJava / FlowNode.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import IR.ClassDescriptor;
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   protected NTuple<Descriptor> descTuple;
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   private boolean isFormHolder = false;
32
33   public boolean isIntermediate() {
34     return isIntermediate;
35   }
36
37   public void setIntermediate(boolean isIntermediate) {
38     this.isIntermediate = isIntermediate;
39   }
40
41   public void setFormHolder(boolean in) {
42     isFormHolder = in;
43   }
44
45   public boolean isFromHolder() {
46     return isFormHolder;
47   }
48
49   public Set<FlowNode> getFieldNodeSet() {
50     return fieldNodeSet;
51   }
52
53   public FlowNode(NTuple<Descriptor> tuple) {
54
55     this.isSkeleton = false;
56     this.isIntermediate = false;
57
58     NTuple<Descriptor> base = null;
59     Descriptor desc = null;
60     if (tuple.size() > 1) {
61       base = tuple.subList(0, tuple.size() - 1);
62       desc = tuple.get(tuple.size() - 1);
63     } else {
64       base = tuple;
65     }
66     fieldNodeSet = new HashSet<FlowNode>();
67     descTuple = new NTuple<Descriptor>();
68     if (base != null) {
69       descTuple.addAll(base);
70     }
71     if (desc != null) {
72       descTuple.add(desc);
73     }
74
75   }
76
77   public void setCompositeLocation(CompositeLocation in) {
78     System.out.println("$$$set compLoc=" + in);
79     compLoc = in;
80   }
81
82   public CompositeLocation getCompositeLocation() {
83     return compLoc;
84   }
85
86   public void addFieldNode(FlowNode node) {
87     fieldNodeSet.add(node);
88   }
89
90   public NTuple<Descriptor> getDescTuple() {
91     return descTuple;
92   }
93
94   public Descriptor getOwnDescriptor() {
95     return descTuple.get(descTuple.size() - 1);
96   }
97
98   public boolean isPrimitiveType() {
99     Descriptor desc = descTuple.get(descTuple.size() - 1);
100     if (desc instanceof VarDescriptor) {
101       return ((VarDescriptor) desc).getType().isPrimitive();
102     } else if (desc instanceof FieldDescriptor) {
103       return ((FieldDescriptor) desc).getType().isPrimitive();
104     }
105     return false;
106   }
107
108   public String toString() {
109     String rtr = "[FlowNode]:";
110     if (isSkeleton()) {
111       rtr += "SKELETON:";
112     }
113     rtr += ":" + descTuple;
114     return rtr;
115   }
116
117   public int hashCode() {
118     return 7 + descTuple.hashCode();
119   }
120
121   public boolean equals(Object obj) {
122
123     if (obj instanceof FlowNode) {
124       FlowNode in = (FlowNode) obj;
125       if (descTuple.equals(in.getDescTuple())) {
126         return true;
127       }
128     }
129
130     return false;
131
132   }
133
134   public String getID() {
135     String id = "";
136     for (int i = 0; i < descTuple.size(); i++) {
137       id += descTuple.get(i).getSymbol();
138     }
139     return id;
140   }
141
142   public String getPrettyID() {
143     String id = "<";
144     String property = "";
145     for (int i = 0; i < descTuple.size(); i++) {
146       if (i != 0) {
147         id += ",";
148       }
149       id += descTuple.get(i).getSymbol();
150     }
151     id += ">";
152
153     if (compLoc != null) {
154       id += " " + compLoc;
155     }
156
157     // if (isReturn()) {
158     // property += "R";
159     // }
160     //
161     // if (isSkeleton()) {
162     // property += "S";
163     // }
164
165     if (property.length() > 0) {
166       property = " [" + property + "]";
167     }
168
169     return id + property;
170   }
171
172   public void setDeclarationNode() {
173     isDeclarationNode = true;
174   }
175
176   public boolean isDeclaratonNode() {
177     return isDeclarationNode;
178   }
179
180   public NTuple<Descriptor> getCurrentDescTuple() {
181
182     if (compLoc == null) {
183       return descTuple;
184     }
185
186     NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
187     for (int i = 0; i < compLoc.getSize(); i++) {
188       Location locElement = compLoc.get(i);
189       curDescTuple.add(locElement.getLocDescriptor());
190     }
191     return curDescTuple;
192   }
193
194   public boolean isSkeleton() {
195     return isSkeleton;
196   }
197
198   public void setSkeleton(boolean isSkeleton) {
199     this.isSkeleton = isSkeleton;
200   }
201
202 }