a bunch of fixes.
[IRC.git] / Robust / src / Analysis / SSJava / FlowNode.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import IR.Descriptor;
8
9 public class FlowNode {
10
11   // descriptor tuple is a unique identifier of the flow node
12   private NTuple<Descriptor> descTuple;
13
14   // if the infer node represents the base type of field access,
15   // this set contains fields of the base type
16   private Set<FlowNode> fieldNodeSet;
17
18   // set true if this node is driven from a paramter
19   private boolean isParameter;
20
21   // set true if this node stores a return value
22   private boolean isReturn;
23
24   public Set<FlowNode> getFieldNodeSet() {
25     return fieldNodeSet;
26   }
27
28   private Set<FlowEdge> outEdgeSet;
29
30   public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
31
32     this.isParameter = isParam;
33
34     NTuple<Descriptor> base = null;
35     Descriptor desc = null;
36     if (tuple.size() > 1) {
37       base = tuple.subList(0, tuple.size() - 1);
38       desc = tuple.get(tuple.size() - 1);
39     } else {
40       base = tuple;
41     }
42     fieldNodeSet = new HashSet<FlowNode>();
43     descTuple = new NTuple<Descriptor>();
44     if (base != null) {
45       descTuple.addAll(base);
46     }
47     if (desc != null) {
48       descTuple.add(desc);
49     }
50     outEdgeSet = new HashSet<FlowEdge>();
51   }
52
53   public void addFieldNode(FlowNode node) {
54     fieldNodeSet.add(node);
55   }
56
57   public boolean isParameter() {
58     return isParameter;
59   }
60
61   public NTuple<Descriptor> getDescTuple() {
62     return descTuple;
63   }
64
65   public Descriptor getOwnDescriptor() {
66     return descTuple.get(descTuple.size() - 1);
67   }
68
69   public boolean isReturn() {
70     return isReturn;
71   }
72
73   public void setReturn(boolean isReturn) {
74     this.isReturn = isReturn;
75   }
76
77   public String toString() {
78     String rtr = "[FlowNode]:";
79     if (isParameter()) {
80       rtr += "param:";
81     }
82     rtr += ":" + descTuple;
83     return rtr;
84   }
85
86   public Iterator<FlowEdge> iteratorOfOutEdges() {
87     return outEdgeSet.iterator();
88   }
89
90   public void addOutEdge(FlowEdge out) {
91     outEdgeSet.add(out);
92   }
93
94   public Set<FlowEdge> getOutEdgeSet() {
95     return outEdgeSet;
96   }
97
98   public int hashCode() {
99     return 7 + descTuple.hashCode();
100   }
101
102   public boolean equals(Object obj) {
103
104     if (obj instanceof FlowNode) {
105       FlowNode in = (FlowNode) obj;
106       if (descTuple.equals(in.getDescTuple())) {
107         return true;
108       }
109     }
110
111     return false;
112
113   }
114
115   public String getID() {
116     String id = "";
117     for (int i = 0; i < descTuple.size(); i++) {
118       id += descTuple.get(i).getSymbol();
119     }
120     return id;
121   }
122
123   public String getPrettyID() {
124     String id = "<";
125     for (int i = 0; i < descTuple.size(); i++) {
126       if (i != 0) {
127         id += ",";
128       }
129       id += descTuple.get(i).getSymbol();
130     }
131     id += ">";
132     return id;
133   }
134 }