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<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 isReturn() {
91 public void setReturn(boolean isReturn) {
92 this.isReturn = isReturn;
95 public boolean isPrimitiveType() {
96 Descriptor desc = descTuple.get(descTuple.size() - 1);
97 if (desc instanceof VarDescriptor) {
98 return ((VarDescriptor) desc).getType().isPrimitive();
99 } else if (desc instanceof FieldDescriptor) {
100 return ((FieldDescriptor) desc).getType().isPrimitive();
105 public String toString() {
106 String rtr = "[FlowNode]:";
110 rtr += ":" + descTuple;
114 // public Iterator<FlowEdge> iteratorOfOutEdges() {
115 // return outEdgeSet.iterator();
118 // public void addOutEdge(FlowEdge out) {
119 // outEdgeSet.add(out);
122 // public Set<FlowEdge> getOutEdgeSet() {
123 // return outEdgeSet;
126 public int hashCode() {
127 return 7 + descTuple.hashCode();
130 public boolean equals(Object obj) {
132 if (obj instanceof FlowNode) {
133 FlowNode in = (FlowNode) obj;
134 if (descTuple.equals(in.getDescTuple())) {
143 public String getID() {
145 for (int i = 0; i < descTuple.size(); i++) {
146 id += descTuple.get(i).getSymbol();
151 public String getPrettyID() {
153 String property = "";
154 for (int i = 0; i < descTuple.size(); i++) {
158 id += descTuple.get(i).getSymbol();
162 if (compLoc != null) {
174 if (property.length() > 0) {
175 property = " [" + property + "]";
178 return id + property;
181 public void setDeclarationNode() {
182 isDeclarationNode = true;
185 public boolean isDeclaratonNode() {
186 return isDeclarationNode;
189 public NTuple<Descriptor> getCurrentDescTuple() {
191 if (compLoc == null) {
195 NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
196 for (int i = 0; i < compLoc.getSize(); i++) {
197 Location locElement = compLoc.get(i);
198 curDescTuple.add(locElement.getLocDescriptor());
203 public boolean isSkeleton() {
207 public void setSkeleton(boolean isSkeleton) {
208 this.isSkeleton = isSkeleton;