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 is driven from a paramter
21 private boolean isParameter;
23 // set true if this node stores a return value
24 private boolean isReturn;
26 private boolean isDeclarationNode = false;
28 public Set<FlowNode> getFieldNodeSet() {
32 private Set<FlowEdge> outEdgeSet;
34 public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
36 this.isParameter = isParam;
38 NTuple<Descriptor> base = null;
39 Descriptor desc = null;
40 if (tuple.size() > 1) {
41 base = tuple.subList(0, tuple.size() - 1);
42 desc = tuple.get(tuple.size() - 1);
46 fieldNodeSet = new HashSet<FlowNode>();
47 descTuple = new NTuple<Descriptor>();
49 descTuple.addAll(base);
54 outEdgeSet = new HashSet<FlowEdge>();
57 public void addFieldNode(FlowNode node) {
58 fieldNodeSet.add(node);
61 public boolean isParameter() {
65 public NTuple<Descriptor> getDescTuple() {
69 public Descriptor getOwnDescriptor() {
70 return descTuple.get(descTuple.size() - 1);
73 public boolean isReturn() {
77 public void setReturn(boolean isReturn) {
78 this.isReturn = isReturn;
81 public boolean isPrimitiveType() {
82 Descriptor desc = descTuple.get(descTuple.size() - 1);
83 if (desc instanceof VarDescriptor) {
84 return ((VarDescriptor) desc).getType().isPrimitive();
85 } else if (desc instanceof FieldDescriptor) {
86 return ((FieldDescriptor) desc).getType().isPrimitive();
91 public String toString() {
92 String rtr = "[FlowNode]:";
96 rtr += ":" + descTuple;
100 public Iterator<FlowEdge> iteratorOfOutEdges() {
101 return outEdgeSet.iterator();
104 public void addOutEdge(FlowEdge out) {
108 public Set<FlowEdge> getOutEdgeSet() {
112 public int hashCode() {
113 return 7 + descTuple.hashCode();
116 public boolean equals(Object obj) {
118 if (obj instanceof FlowNode) {
119 FlowNode in = (FlowNode) obj;
120 if (descTuple.equals(in.getDescTuple())) {
129 public String getID() {
131 for (int i = 0; i < descTuple.size(); i++) {
132 id += descTuple.get(i).getSymbol();
137 public String getPrettyID() {
139 for (int i = 0; i < descTuple.size(); i++) {
143 id += descTuple.get(i).getSymbol();
149 public void setDeclarationNode() {
150 isDeclarationNode = true;
153 public boolean isDeclaratonNode() {
154 return isDeclarationNode;