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