1 package Analysis.SSJava;
3 import java.util.HashSet;
6 import IR.ClassDescriptor;
8 import IR.FieldDescriptor;
9 import IR.VarDescriptor;
11 public class FlowNode {
13 // descriptor tuple is a unique identifier of the flow node
14 protected NTuple<Descriptor> descTuple;
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;
20 // set true if this node stores a return value
21 private boolean isReturn;
23 private boolean isDeclarationNode = false;
25 private boolean isIntermediate;
27 private CompositeLocation compLoc;
29 private boolean isSkeleton;
31 private boolean isFormHolder = false;
33 public boolean isIntermediate() {
34 return isIntermediate;
37 public void setIntermediate(boolean isIntermediate) {
38 this.isIntermediate = isIntermediate;
41 public void setFormHolder(boolean in) {
45 public boolean isFromHolder() {
49 public Set<FlowNode> getFieldNodeSet() {
53 public FlowNode(NTuple<Descriptor> tuple) {
55 this.isSkeleton = false;
56 this.isIntermediate = false;
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);
66 fieldNodeSet = new HashSet<FlowNode>();
67 descTuple = new NTuple<Descriptor>();
69 descTuple.addAll(base);
77 public void setCompositeLocation(CompositeLocation in) {
78 System.out.println("$$$set compLoc=" + in);
82 public CompositeLocation getCompositeLocation() {
86 public void addFieldNode(FlowNode node) {
87 fieldNodeSet.add(node);
90 public NTuple<Descriptor> getDescTuple() {
94 public Descriptor getOwnDescriptor() {
95 return descTuple.get(descTuple.size() - 1);
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();
108 public String toString() {
109 String rtr = "[FlowNode]:";
113 rtr += ":" + descTuple;
117 public int hashCode() {
118 return 7 + descTuple.hashCode();
121 public boolean equals(Object obj) {
123 if (obj instanceof FlowNode) {
124 FlowNode in = (FlowNode) obj;
125 if (descTuple.equals(in.getDescTuple())) {
134 public String getID() {
136 for (int i = 0; i < descTuple.size(); i++) {
137 id += descTuple.get(i).getSymbol();
142 public String getPrettyID() {
144 String property = "";
145 for (int i = 0; i < descTuple.size(); i++) {
149 id += descTuple.get(i).getSymbol();
153 if (compLoc != null) {
161 // if (isSkeleton()) {
165 if (property.length() > 0) {
166 property = " [" + property + "]";
169 return id + property;
172 public void setDeclarationNode() {
173 isDeclarationNode = true;
176 public boolean isDeclaratonNode() {
177 return isDeclarationNode;
180 public NTuple<Descriptor> getCurrentDescTuple() {
182 if (compLoc == null) {
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());
194 public boolean isSkeleton() {
198 public void setSkeleton(boolean isSkeleton) {
199 this.isSkeleton = isSkeleton;