changes + add two more benchmarks without annotations
[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   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   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<Descriptor> tuple) {
44
45     this.isSkeleton = false;
46     this.isIntermediate = false;
47
48     NTuple<Descriptor> base = null;
49     Descriptor desc = null;
50     if (tuple.size() > 1) {
51       base = tuple.subList(0, tuple.size() - 1);
52       desc = tuple.get(tuple.size() - 1);
53     } else {
54       base = tuple;
55     }
56     fieldNodeSet = new HashSet<FlowNode>();
57     descTuple = new NTuple<Descriptor>();
58     if (base != null) {
59       descTuple.addAll(base);
60     }
61     if (desc != null) {
62       descTuple.add(desc);
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<Descriptor> getDescTuple() {
80     return descTuple;
81   }
82
83   public Descriptor getOwnDescriptor() {
84     return descTuple.get(descTuple.size() - 1);
85   }
86
87   public boolean isPrimitiveType() {
88     Descriptor desc = descTuple.get(descTuple.size() - 1);
89     if (desc instanceof VarDescriptor) {
90       return ((VarDescriptor) desc).getType().isPrimitive();
91     } else if (desc instanceof FieldDescriptor) {
92       return ((FieldDescriptor) desc).getType().isPrimitive();
93     }
94     return false;
95   }
96
97   public String toString() {
98     String rtr = "[FlowNode]:";
99     if (isSkeleton()) {
100       rtr += "SKELETON:";
101     }
102     rtr += ":" + descTuple;
103     return rtr;
104   }
105
106   public int hashCode() {
107     return 7 + descTuple.hashCode();
108   }
109
110   public boolean equals(Object obj) {
111
112     if (obj instanceof FlowNode) {
113       FlowNode in = (FlowNode) obj;
114       if (descTuple.equals(in.getDescTuple())) {
115         return true;
116       }
117     }
118
119     return false;
120
121   }
122
123   public String getID() {
124     String id = "";
125     for (int i = 0; i < descTuple.size(); i++) {
126       id += descTuple.get(i).getSymbol();
127     }
128     return id;
129   }
130
131   public String getPrettyID() {
132     String id = "<";
133     String property = "";
134     for (int i = 0; i < descTuple.size(); i++) {
135       if (i != 0) {
136         id += ",";
137       }
138       id += descTuple.get(i).getSymbol();
139     }
140     id += ">";
141
142     if (compLoc != null) {
143       id += " " + compLoc;
144     }
145
146     // if (isReturn()) {
147     // property += "R";
148     // }
149     //
150     // if (isSkeleton()) {
151     // property += "S";
152     // }
153
154     if (property.length() > 0) {
155       property = " [" + property + "]";
156     }
157
158     return id + property;
159   }
160
161   public void setDeclarationNode() {
162     isDeclarationNode = true;
163   }
164
165   public boolean isDeclaratonNode() {
166     return isDeclarationNode;
167   }
168
169   public NTuple<Descriptor> getCurrentDescTuple() {
170
171     if (compLoc == null) {
172       return descTuple;
173     }
174
175     NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
176     for (int i = 0; i < compLoc.getSize(); i++) {
177       Location locElement = compLoc.get(i);
178       curDescTuple.add(locElement.getLocDescriptor());
179     }
180     return curDescTuple;
181   }
182
183   public boolean isSkeleton() {
184     return isSkeleton;
185   }
186
187   public void setSkeleton(boolean isSkeleton) {
188     this.isSkeleton = isSkeleton;
189   }
190
191 }