cdd9bd472a939e1d53b3da0a1e2546805b1deb44
[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<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 isReturn() {
88     return isReturn;
89   }
90
91   public void setReturn(boolean isReturn) {
92     this.isReturn = isReturn;
93   }
94
95   public boolean isPrimitiveType() {
96     Descriptor desc = descTuple.get(descTuple.size() - 1);
97     if (desc instanceof VarDescriptor) {
98       return ((VarDescriptor) desc).getType().isPrimitive();
99     } else if (desc instanceof FieldDescriptor) {
100       return ((FieldDescriptor) desc).getType().isPrimitive();
101     }
102     return false;
103   }
104
105   public String toString() {
106     String rtr = "[FlowNode]:";
107     if (isSkeleton()) {
108       rtr += "SKELETON:";
109     }
110     rtr += ":" + descTuple;
111     return rtr;
112   }
113
114
115   public int hashCode() {
116     return 7 + descTuple.hashCode();
117   }
118
119   public boolean equals(Object obj) {
120
121     if (obj instanceof FlowNode) {
122       FlowNode in = (FlowNode) obj;
123       if (descTuple.equals(in.getDescTuple())) {
124         return true;
125       }
126     }
127
128     return false;
129
130   }
131
132   public String getID() {
133     String id = "";
134     for (int i = 0; i < descTuple.size(); i++) {
135       id += descTuple.get(i).getSymbol();
136     }
137     return id;
138   }
139
140   public String getPrettyID() {
141     String id = "<";
142     String property = "";
143     for (int i = 0; i < descTuple.size(); i++) {
144       if (i != 0) {
145         id += ",";
146       }
147       id += descTuple.get(i).getSymbol();
148     }
149     id += ">";
150
151     if (compLoc != null) {
152       id += " " + compLoc;
153     }
154
155     // if (isReturn()) {
156     // property += "R";
157     // }
158     //
159     // if (isSkeleton()) {
160     // property += "S";
161     // }
162
163     if (property.length() > 0) {
164       property = " [" + property + "]";
165     }
166
167     return id + property;
168   }
169
170   public void setDeclarationNode() {
171     isDeclarationNode = true;
172   }
173
174   public boolean isDeclaratonNode() {
175     return isDeclarationNode;
176   }
177
178   public NTuple<Descriptor> getCurrentDescTuple() {
179
180     if (compLoc == null) {
181       return descTuple;
182     }
183
184     NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
185     for (int i = 0; i < compLoc.getSize(); i++) {
186       Location locElement = compLoc.get(i);
187       curDescTuple.add(locElement.getLocDescriptor());
188     }
189     return curDescTuple;
190   }
191
192   public boolean isSkeleton() {
193     return isSkeleton;
194   }
195
196   public void setSkeleton(boolean isSkeleton) {
197     this.isSkeleton = isSkeleton;
198   }
199
200 }