Stable compile finally, but system crashing in mid-conversion
[IRC.git] / Robust / src / Analysis / Disjoint / HeapRegionNode.java
1 package Analysis.Disjoint;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6
7 public class HeapRegionNode extends RefSrcNode {
8
9   protected Integer id;
10
11   protected boolean isSingleObject;
12   protected boolean isFlagged;
13   protected boolean isNewSummary;
14
15   protected HashSet<RefEdge> referencers;
16
17   protected TypeDescriptor type;
18
19   protected AllocSite allocSite;
20
21   protected ReachSet alpha;
22   protected ReachSet alphaNew;
23
24   protected String description;
25
26
27   public HeapRegionNode( Integer        id,
28                          boolean        isSingleObject,
29                          boolean        isFlagged,
30                          boolean        isNewSummary,
31                          TypeDescriptor type,
32                          AllocSite      allocSite,
33                          ReachSet       alpha,
34                          String         description
35                          ) {
36     this.id             = id;
37     this.isSingleObject = isSingleObject;
38     this.isFlagged      = isFlagged;
39     this.isNewSummary   = isNewSummary;
40     this.type           = type;
41     this.allocSite      = allocSite;
42     this.alpha          = alpha;
43     this.description    = description;
44
45     referencers = new HashSet<RefEdge>();
46     alphaNew    = new ReachSet().makeCanonical();
47   }
48
49   public HeapRegionNode copy() {
50     return new HeapRegionNode( id,
51                                isSingleObject,
52                                isFlagged,
53                                isNewSummary,
54                                type,
55                                allocSite,
56                                alpha,
57                                description );
58   }
59
60
61   public Integer getID() {
62     return id;
63   }
64
65
66   public boolean equalsIncludingAlpha( HeapRegionNode hrn ) {
67     return equals( hrn ) && alpha.equals( hrn.alpha );
68   }
69
70
71   public boolean equals( Object o ) {
72     if( o == null ) {
73       return false;
74     }
75
76     if( !(o instanceof HeapRegionNode) ) {
77       return false;
78     }
79
80     HeapRegionNode hrn = (HeapRegionNode) o;
81
82     if( !id.equals( hrn.getID() ) ) {
83       return false;
84     }
85
86     assert isSingleObject == hrn.isSingleObject();
87     assert isFlagged      == hrn.isFlagged();
88     assert isNewSummary   == hrn.isNewSummary();
89     assert description.equals( hrn.getDescription() );
90
91     return true;
92   }
93
94   public int hashCode() {
95     return id.intValue()*17;
96   }
97
98
99   public boolean isSingleObject() {
100     return isSingleObject;
101   }
102
103   public boolean isFlagged() {
104     return isFlagged;
105   }
106
107   public boolean isNewSummary() {
108     return isNewSummary;
109   }
110
111
112   public Iterator<RefEdge> iteratorToReferencers() {
113     return referencers.iterator();
114   }
115
116   public Iterator<RefEdge> iteratorToReferencersClone() {
117     HashSet<RefEdge> clone = (HashSet<RefEdge>)referencers.clone();
118     return clone.iterator();
119   }
120
121   public int getNumReferencers() {
122     return referencers.size();
123   }
124
125   public void addReferencer( RefEdge edge ) {
126     assert edge != null;
127
128     referencers.add( edge );
129   }
130
131   public void removeReferencer( RefEdge edge ) {
132     assert edge != null;
133     assert referencers.contains( edge );
134
135     referencers.remove( edge );
136   }
137
138   public RefEdge getReferenceFrom( RefSrcNode     rsn,
139                                    TypeDescriptor type,
140                                    String         field
141                                    ) {
142     assert rsn != null;
143
144     Iterator<RefEdge> itrEdge = referencers.iterator();
145     while( itrEdge.hasNext() ) {
146       RefEdge edge = itrEdge.next();
147
148       if( edge.getSrc().equals( rsn ) &&
149           edge.typeEquals( type )     &&
150           edge.fieldEquals( field ) 
151           ) {
152         return edge;
153       }
154     }
155
156     return null;
157   }
158
159
160   public TypeDescriptor getType() {
161     return type;
162   }  
163
164   public AllocSite getAllocSite() {
165     return allocSite;
166   }
167
168   public ReachSet getAlpha() {
169     return alpha;
170   }
171
172   public void setAlpha( ReachSet alpha ) {
173     this.alpha = alpha;
174   }
175
176   public ReachSet getAlphaNew() {
177     return alphaNew;
178   }
179
180   public void setAlphaNew( ReachSet alpha ) {
181     this.alphaNew = alpha;
182   }
183
184   public void applyAlphaNew() {
185     assert alphaNew != null;
186     alpha = alphaNew;
187     alphaNew = new ReachSet().makeCanonical();
188   }
189
190
191   public String getIDString() {
192     String s;
193
194     if( id < 0 ) {
195       s = "minus" + new Integer(-id).toString();
196     } else {
197       s = id.toString();
198     }
199
200     return s;
201   }
202
203   public String getAlphaString( boolean hideSubsetReachability ) {
204     return alpha.toStringEscapeNewline( hideSubsetReachability );
205   }
206
207   public String toString() {
208     return "HRN"+getIDString();
209   }
210
211   public String getDescription() {
212     //return new String(description);
213     return description;
214   }  
215 }