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 private Set<FlowEdge> outEdgeSet;
45 public FlowNode(NTuple<Descriptor> tuple) {
47 this.isSkeleton = false;
48 this.isIntermediate = false;
50 NTuple<Descriptor> base = null;
51 Descriptor desc = null;
52 if (tuple.size() > 1) {
53 base = tuple.subList(0, tuple.size() - 1);
54 desc = tuple.get(tuple.size() - 1);
58 fieldNodeSet = new HashSet<FlowNode>();
59 descTuple = new NTuple<Descriptor>();
61 descTuple.addAll(base);
66 outEdgeSet = new HashSet<FlowEdge>();
70 public void setCompositeLocation(CompositeLocation in) {
74 public CompositeLocation getCompositeLocation() {
78 public void addFieldNode(FlowNode node) {
79 fieldNodeSet.add(node);
82 public NTuple<Descriptor> getDescTuple() {
86 public Descriptor getOwnDescriptor() {
87 return descTuple.get(descTuple.size() - 1);
90 public boolean isReturn() {
94 public void setReturn(boolean isReturn) {
95 this.isReturn = isReturn;
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 Iterator<FlowEdge> iteratorOfOutEdges() {
118 return outEdgeSet.iterator();
121 public void addOutEdge(FlowEdge out) {
125 public Set<FlowEdge> getOutEdgeSet() {
129 public int hashCode() {
130 return 7 + descTuple.hashCode();
133 public boolean equals(Object obj) {
135 if (obj instanceof FlowNode) {
136 FlowNode in = (FlowNode) obj;
137 if (descTuple.equals(in.getDescTuple())) {
146 public String getID() {
148 for (int i = 0; i < descTuple.size(); i++) {
149 id += descTuple.get(i).getSymbol();
154 public String getPrettyID() {
156 for (int i = 0; i < descTuple.size(); i++) {
160 id += descTuple.get(i).getSymbol();
164 if (compLoc != null) {
171 public void setDeclarationNode() {
172 isDeclarationNode = true;
175 public boolean isDeclaratonNode() {
176 return isDeclarationNode;
179 public NTuple<Descriptor> getCurrentDescTuple() {
181 if (compLoc == null) {
185 NTuple<Descriptor> curDescTuple = new NTuple<Descriptor>();
186 for (int i = 0; i < compLoc.getSize(); i++) {
187 Location locElement = compLoc.get(i);
188 curDescTuple.add(locElement.getLocDescriptor());
193 public boolean isSkeleton() {
197 public void setSkeleton(boolean isSkeleton) {
198 this.isSkeleton = isSkeleton;