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