1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Iterator;
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) {
71 public CompositeLocation getCompositeLocation() {
75 public void addFieldNode(FlowNode node) {
76 fieldNodeSet.add(node);
79 public NTuple<Descriptor> getDescTuple() {
83 public Descriptor getOwnDescriptor() {
84 return descTuple.get(descTuple.size() - 1);
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();
97 public String toString() {
98 String rtr = "[FlowNode]:";
102 rtr += ":" + descTuple;
106 public int hashCode() {
107 return 7 + descTuple.hashCode();
110 public boolean equals(Object obj) {
112 if (obj instanceof FlowNode) {
113 FlowNode in = (FlowNode) obj;
114 if (descTuple.equals(in.getDescTuple())) {
123 public String getID() {
125 for (int i = 0; i < descTuple.size(); i++) {
126 id += descTuple.get(i).getSymbol();
131 public String getPrettyID() {
133 String property = "";
134 for (int i = 0; i < descTuple.size(); i++) {
138 id += descTuple.get(i).getSymbol();
142 if (compLoc != null) {
150 // if (isSkeleton()) {
154 if (property.length() > 0) {
155 property = " [" + property + "]";
158 return id + property;
161 public void setDeclarationNode() {
162 isDeclarationNode = true;
165 public boolean isDeclaratonNode() {
166 return isDeclarationNode;
169 public NTuple<Descriptor> getCurrentDescTuple() {
171 if (compLoc == null) {
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());
183 public boolean isSkeleton() {
187 public void setSkeleton(boolean isSkeleton) {
188 this.isSkeleton = isSkeleton;