Token propagation implemented, stable but incorrect. This is just a capture.
[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<TempDescriptor> memberFields;
16     protected HashSet<OwnershipNode>  referencers;
17
18     protected AllocationSite allocSite;
19
20     protected ReachabilitySet alpha;
21     protected ReachabilitySet alphaNew;
22
23     protected String description;
24
25
26
27     public HeapRegionNode( Integer         id,
28                            boolean         isSingleObject,
29                            boolean         isFlagged,
30                            boolean         isNewSummary,
31                            AllocationSite  allocSite,
32                            ReachabilitySet alpha,
33                            String          description ) {
34         this.id = id;
35         this.isSingleObject = isSingleObject;
36         this.isFlagged      = isFlagged;
37         this.isNewSummary   = isNewSummary;
38         this.allocSite      = allocSite;
39         this.alpha          = alpha;
40         this.description    = description;
41
42         alphaNew = new ReachabilitySet();
43         alphaNew = alphaNew.makeCanonical();
44
45         referencers  = new HashSet<OwnershipNode>();
46         memberFields = new HashSet<TempDescriptor>();
47     }
48
49     public HeapRegionNode copy() {
50         return new HeapRegionNode( id,
51                                    isSingleObject,
52                                    isFlagged,
53                                    isNewSummary,
54                                    allocSite,
55                                    alpha,
56                                    description );
57     }
58
59
60     public Integer getID() {
61         return id;
62     }
63
64
65     public boolean equals( HeapRegionNode hrn ) {
66         assert hrn != null;
67
68         return id.equals( hrn.getID() )            &&
69             isSingleObject == hrn.isSingleObject() &&
70             isFlagged      == hrn.isFlagged()      &&
71             isNewSummary   == hrn.isNewSummary()   &&
72             alpha.equals( hrn.getAlpha() )         &&
73             description.equals( hrn.getDescription() );
74     }
75
76
77
78     public boolean isSingleObject() {
79         return isSingleObject;
80     }
81
82     public boolean isFlagged() {
83         return isFlagged;
84     }
85
86     public boolean isNewSummary() {
87         return isNewSummary;
88     }
89
90
91
92     public Iterator iteratorToReferencers() {
93         return referencers.iterator();
94     }
95
96     public Iterator iteratorToReferencersClone() {
97         HashSet hs = (HashSet) referencers.clone();
98         return hs.iterator();
99     }
100
101     public void addReferencer( OwnershipNode on ) {
102         assert on != null;
103
104         referencers.add( on );
105     }
106
107     public void removeReferencer( OwnershipNode on ) {
108         assert on != null;
109         assert referencers.contains( on );
110
111         referencers.remove( on );
112     }
113
114     public boolean isReferencedBy( OwnershipNode on ) {
115         assert on != null;
116         return referencers.contains( on );
117     }
118
119
120     public AllocationSite getAllocationSite() {
121         return allocSite;
122     }
123
124
125     public void setAlpha( ReachabilitySet alpha ) {
126         this.alpha = alpha;
127     }
128
129     public ReachabilitySet getAlpha() {
130         return alpha;
131     }
132
133     public ReachabilitySet getAlphaNew() {
134         return alphaNew;
135     }
136
137     public void setAlphaNew( ReachabilitySet alpha ) {
138         this.alphaNew = alpha;
139     }
140
141     public void applyAlphaNew() {
142         assert alphaNew != null;
143
144         alpha = alphaNew;
145
146         alphaNew = new ReachabilitySet();
147         alphaNew = alphaNew.makeCanonical();
148     }
149
150
151     public String getIDString() {
152         return id.toString();
153     }
154
155     public String getAlphaString() {
156         return alpha.toStringEscapeNewline();
157     }
158
159     public String toString() {
160         return "HRN"+getIDString();
161     }
162
163     // WHY WHY WHY WHY WHY WHY?!
164     public String getDescription() {
165         return new String( description );
166         //return new String( description+" ID "+getIDString() );
167     }
168 }