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 public boolean isIntermediate() {
32 return isIntermediate;
35 public void setIntermediate(boolean isIntermediate) {
36 this.isIntermediate = isIntermediate;
39 public Set<FlowNode> getFieldNodeSet() {
43 public FlowNode(NTuple<Descriptor> tuple) {
45 this.isSkeleton = false;
46 this.isIntermediate = false;
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);
56 fieldNodeSet = new HashSet<FlowNode>();
57 descTuple = new NTuple<Descriptor>();
59 descTuple.addAll(base);
67 public void setCompositeLocation(CompositeLocation in) {
68 System.out.println("$$$set compLoc=" + in);
72 public CompositeLocation getCompositeLocation() {
76 public void addFieldNode(FlowNode node) {
77 fieldNodeSet.add(node);
80 public NTuple<Descriptor> getDescTuple() {
84 public Descriptor getOwnDescriptor() {
85 return descTuple.get(descTuple.size() - 1);
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();
98 public String toString() {
99 String rtr = "[FlowNode]:";
103 rtr += ":" + descTuple;
107 public int hashCode() {
108 return 7 + descTuple.hashCode();
111 public boolean equals(Object obj) {
113 if (obj instanceof FlowNode) {
114 FlowNode in = (FlowNode) obj;
115 if (descTuple.equals(in.getDescTuple())) {
124 public String getID() {
126 for (int i = 0; i < descTuple.size(); i++) {
127 id += descTuple.get(i).getSymbol();
132 public String getPrettyID() {
134 String property = "";
135 for (int i = 0; i < descTuple.size(); i++) {
139 id += descTuple.get(i).getSymbol();
143 if (compLoc != null) {
151 // if (isSkeleton()) {
155 if (property.length() > 0) {
156 property = " [" + property + "]";
159 return id + property;
162 public void setDeclarationNode() {
163 isDeclarationNode = true;
166 public boolean isDeclaratonNode() {
167 return isDeclarationNode;
170 public NTuple<Descriptor> getCurrentDescTuple() {
172 if (compLoc == null) {
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());
184 public boolean isSkeleton() {
188 public void setSkeleton(boolean isSkeleton) {
189 this.isSkeleton = isSkeleton;