0263143e26850de7f9ff128d33328666811b3498
[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 equals( Object o ) {
62         if( o == null ) {
63             return false;
64         }
65
66         if( !( o instanceof HeapRegionNode) ) {
67             return false;
68         }
69
70         HeapRegionNode hrn = (HeapRegionNode) o;
71
72         if( !id.equals( hrn.getID() ) ) {
73             return false;
74         }
75
76         assert isSingleObject == hrn.isSingleObject();
77         assert isFlagged      == hrn.isFlagged();
78         assert isNewSummary   == hrn.isNewSummary();
79         assert description.equals( hrn.getDescription() ); 
80
81         return alpha.equals( hrn.getAlpha() );
82
83         /*
84         return id.equals( hrn.getID() )            &&
85             isSingleObject == hrn.isSingleObject() &&
86             isFlagged      == hrn.isFlagged()      &&
87             isNewSummary   == hrn.isNewSummary()   &&
88             alpha.equals( hrn.getAlpha() )         &&
89             description.equals( hrn.getDescription() );
90         */
91     }
92
93     public int hashCode() {
94         return id.intValue()*17 + alpha.hashCode();
95     }
96
97
98     public boolean isSingleObject() {
99         return isSingleObject;
100     }
101
102     public boolean isFlagged() {
103         return isFlagged;
104     }
105
106     public boolean isNewSummary() {
107         return isNewSummary;
108     }
109
110
111
112     public Iterator<ReferenceEdge> iteratorToReferencers() {
113         return referencers.iterator();
114     }
115
116     public Iterator<ReferenceEdge> iteratorToReferencersClone() {
117         HashSet<ReferenceEdge> clone = (HashSet<ReferenceEdge>) referencers.clone();
118         return clone.iterator();
119     }
120
121     public void addReferencer( ReferenceEdge edge ) {
122         assert edge != null;
123
124         referencers.add( edge );
125     }
126
127     public void removeReferencer( ReferenceEdge edge ) {
128         assert edge != null;
129         assert referencers.contains( edge );
130
131         referencers.remove( edge );
132     }
133
134     public ReferenceEdge getReferenceFrom( OwnershipNode   on,
135                                            FieldDescriptor fd ) {
136         assert on != null;
137
138         Iterator<ReferenceEdge> itrEdge = referencers.iterator();
139         while( itrEdge.hasNext() ) {
140             ReferenceEdge edge = itrEdge.next();
141             if( edge.getSrc().equals( on ) &&
142                 edge.getFieldDesc() == fd     ) {
143                 return edge;
144             }
145         }
146
147         return null;
148     }
149
150
151     public AllocationSite getAllocationSite() {
152         return allocSite;
153     }
154
155
156     public void setAlpha( ReachabilitySet alpha ) {
157         this.alpha = alpha;
158     }
159
160     public ReachabilitySet getAlpha() {
161         return alpha;
162     }
163
164     public ReachabilitySet getAlphaNew() {
165         return alphaNew;
166     }
167
168     public void setAlphaNew( ReachabilitySet alpha ) {
169         this.alphaNew = alpha;
170     }
171
172     public void applyAlphaNew() {
173         assert alphaNew != null;
174
175         alpha = alphaNew;
176
177         alphaNew = new ReachabilitySet();
178         alphaNew = alphaNew.makeCanonical();
179     }
180
181
182     public String getIDString() {
183         return id.toString();
184     }
185
186     public String getAlphaString() {
187         return alpha.toStringEscapeNewline();
188     }
189
190     public String toString() {
191         return "HRN"+getIDString();
192     }
193
194     // WHY WHY WHY WHY WHY WHY?!
195     public String getDescription() {
196         return new String( description );
197         //return new String( description+" ID "+getIDString() );
198     }
199 }