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