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