changes: generated annotated code but it still causes type errors + re-formatting...
[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   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     System.out.println("$$$set compLoc=" + in);
69     compLoc = in;
70   }
71
72   public CompositeLocation getCompositeLocation() {
73     return compLoc;
74   }
75
76   public void addFieldNode(FlowNode node) {
77     fieldNodeSet.add(node);
78   }
79
80   public NTuple<Descriptor> getDescTuple() {
81     return descTuple;
82   }
83
84   public Descriptor getOwnDescriptor() {
85     return descTuple.get(descTuple.size() - 1);
86   }
87
88   public boolean isPrimitiveType() {
89     Descriptor desc = descTuple.get(descTuple.size() - 1);
90     if (desc instanceof VarDescriptor) {
91       return ((VarDescriptor) desc).getType().isPrimitive();
92     } else if (desc instanceof FieldDescriptor) {
93       return ((FieldDescriptor) desc).getType().isPrimitive();
94     }
95     return false;
96   }
97
98   public String toString() {
99     String rtr = "[FlowNode]:";
100     if (isSkeleton()) {
101       rtr += "SKELETON:";
102     }
103     rtr += ":" + descTuple;
104     return rtr;
105   }
106
107   public int hashCode() {
108     return 7 + descTuple.hashCode();
109   }
110
111   public boolean equals(Object obj) {
112
113     if (obj instanceof FlowNode) {
114       FlowNode in = (FlowNode) obj;
115       if (descTuple.equals(in.getDescTuple())) {
116         return true;
117       }
118     }
119
120     return false;
121
122   }
123
124   public String getID() {
125     String id = "";
126     for (int i = 0; i < descTuple.size(); i++) {
127       id += descTuple.get(i).getSymbol();
128     }
129     return id;
130   }
131
132   public String getPrettyID() {
133     String id = "<";
134     String property = "";
135     for (int i = 0; i < descTuple.size(); i++) {
136       if (i != 0) {
137         id += ",";
138       }
139       id += descTuple.get(i).getSymbol();
140     }
141     id += ">";
142
143     if (compLoc != null) {
144       id += " " + compLoc;
145     }
146
147     // if (isReturn()) {
148     // property += "R";
149     // }
150     //
151     // if (isSkeleton()) {
152     // property += "S";
153     // }
154
155     if (property.length() > 0) {
156       property = " [" + property + "]";
157     }
158
159     return id + property;
160   }
161
162   public void setDeclarationNode() {
163     isDeclarationNode = true;
164   }
165
166   public boolean isDeclaratonNode() {
167     return isDeclarationNode;
168   }
169
170   public NTuple<Descriptor> getCurrentDescTuple() {
171
172     if (compLoc == null) {
173       return descTuple;
174     }
175
176     NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
177     for (int i = 0; i < compLoc.getSize(); i++) {
178       Location locElement = compLoc.get(i);
179       curDescTuple.add(locElement.getLocDescriptor());
180     }
181     return curDescTuple;
182   }
183
184   public boolean isSkeleton() {
185     return isSkeleton;
186   }
187
188   public void setSkeleton(boolean isSkeleton) {
189     this.isSkeleton = isSkeleton;
190   }
191
192 }