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 private NTuple<Location> locTuple;
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<Location> tuple) {
45 this.isSkeleton = false;
46 this.isIntermediate = false;
48 NTuple<Location> base = null;
50 if (tuple.size() > 1) {
51 base = tuple.subList(0, tuple.size() - 1);
52 loc = tuple.get(tuple.size() - 1);
56 fieldNodeSet = new HashSet<FlowNode>();
57 locTuple = new NTuple<Location>();
59 locTuple.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<Location> getLocTuple() {
83 public boolean isReturn() {
87 public void setReturn(boolean isReturn) {
88 this.isReturn = isReturn;
91 public String toString() {
92 String rtr = "[FlowNode]:";
96 rtr += ":" + locTuple;
100 public int hashCode() {
101 return 7 + locTuple.hashCode();
104 public boolean equals(Object obj) {
106 if (obj instanceof FlowNode) {
107 FlowNode in = (FlowNode) obj;
108 if (locTuple.equals(in.getLocTuple())) {
117 public String getID() {
119 for (int i = 0; i < locTuple.size(); i++) {
120 id += locTuple.get(i).getSymbol();
125 public String getPrettyID() {
127 String property = "";
128 for (int i = 0; i < locTuple.size(); i++) {
132 id += locTuple.get(i).getSymbol();
136 if (compLoc != null) {
144 // if (isSkeleton()) {
148 if (property.length() > 0) {
149 property = " [" + property + "]";
152 return id + property;
155 public void setDeclarationNode() {
156 isDeclarationNode = true;
159 public boolean isDeclaratonNode() {
160 return isDeclarationNode;
163 public NTuple<Location> getCurrentLocTuple() {
164 if (compLoc == null) {
167 NTuple<Location> curLocTuple = new NTuple<Location>();
168 for (int i = 0; i < compLoc.getSize(); i++) {
169 Location locElement = compLoc.get(i);
170 curLocTuple.add(locElement);
175 public NTuple<Descriptor> getCurrentDescTuple() {
177 if (compLoc == null) {
178 return getDescTuple();
181 NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
182 for (int i = 0; i < compLoc.getSize(); i++) {
183 Location locElement = compLoc.get(i);
184 curDescTuple.add(locElement.getLocDescriptor());
189 public boolean isSkeleton() {
193 public void setSkeleton(boolean isSkeleton) {
194 this.isSkeleton = isSkeleton;
197 public NTuple<Descriptor> getDescTuple() {
198 NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
199 for (int i = 0; i < locTuple.size(); i++) {
200 descTuple.add(locTuple.get(i).getLocDescriptor());