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 private boolean isIntermediate;
30 public boolean isIntermediate() {
31 return isIntermediate;
34 public void setIntermediate(boolean isIntermediate) {
35 this.isIntermediate = isIntermediate;
38 public Set<FlowNode> getFieldNodeSet() {
42 private Set<FlowEdge> outEdgeSet;
44 public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
46 this.isParameter = isParam;
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);
64 outEdgeSet = new HashSet<FlowEdge>();
67 public void addFieldNode(FlowNode node) {
68 fieldNodeSet.add(node);
71 public boolean isParameter() {
75 public NTuple<Descriptor> getDescTuple() {
79 public Descriptor getOwnDescriptor() {
80 return descTuple.get(descTuple.size() - 1);
83 public boolean isReturn() {
87 public void setReturn(boolean isReturn) {
88 this.isReturn = isReturn;
91 public boolean isPrimitiveType() {
92 Descriptor desc = descTuple.get(descTuple.size() - 1);
93 if (desc instanceof VarDescriptor) {
94 return ((VarDescriptor) desc).getType().isPrimitive();
95 } else if (desc instanceof FieldDescriptor) {
96 return ((FieldDescriptor) desc).getType().isPrimitive();
101 public String toString() {
102 String rtr = "[FlowNode]:";
106 rtr += ":" + descTuple;
110 public Iterator<FlowEdge> iteratorOfOutEdges() {
111 return outEdgeSet.iterator();
114 public void addOutEdge(FlowEdge out) {
118 public Set<FlowEdge> getOutEdgeSet() {
122 public int hashCode() {
123 return 7 + descTuple.hashCode();
126 public boolean equals(Object obj) {
128 if (obj instanceof FlowNode) {
129 FlowNode in = (FlowNode) obj;
130 if (descTuple.equals(in.getDescTuple())) {
139 public String getID() {
141 for (int i = 0; i < descTuple.size(); i++) {
142 id += descTuple.get(i).getSymbol();
147 public String getPrettyID() {
149 for (int i = 0; i < descTuple.size(); i++) {
153 id += descTuple.get(i).getSymbol();
159 public void setDeclarationNode() {
160 isDeclarationNode = true;
163 public boolean isDeclaratonNode() {
164 return isDeclarationNode;