4e0b0458a8483e2331ca3733de47250df15f91f4
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ReferenceEdgeProperties.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5
6
7 public class ReferenceEdgeProperties {
8
9     // a null field descriptor means "any field"
10     protected FieldDescriptor fieldDesc;
11
12     protected boolean isInitialParamReflexive;
13
14     protected ReachabilitySet beta;
15     protected ReachabilitySet betaNew;
16
17     protected OwnershipNode  src;
18     protected HeapRegionNode dst;
19
20     public ReferenceEdgeProperties() {
21         this( null, false, null );
22     }    
23
24     public ReferenceEdgeProperties( FieldDescriptor fieldDesc, 
25                                     boolean         isInitialParamReflexive,
26                                     ReachabilitySet beta ) {
27
28         this.fieldDesc               = fieldDesc;
29         this.isInitialParamReflexive = isInitialParamReflexive; 
30
31         if( beta != null ) {
32             this.beta = beta;
33         } else {
34             this.beta = new ReachabilitySet();
35             this.beta = this.beta.makeCanonical();
36         }
37
38         // these members are set by higher-level code
39         // when this ReferenceEdgeProperties object is
40         // applied to an edge
41         this.src = null;
42         this.dst = null;
43
44         // when edges are not undergoing a transitional operation
45         // that is changing beta info, betaNew is always empty
46         betaNew = new ReachabilitySet();
47         betaNew = betaNew.makeCanonical();
48     }
49
50
51     public OwnershipNode getSrc() {
52         return src;
53     }
54
55     public void setSrc( OwnershipNode on ) {
56         assert on != null;
57         src = on;
58     }
59
60     public HeapRegionNode getDst() {
61         return dst;
62     }
63
64     public void setDst( HeapRegionNode hrn ) {
65         assert hrn != null;
66         dst = hrn;
67     }
68
69
70     // copying does not copy source and destination members! or betaNew
71     public ReferenceEdgeProperties copy() {
72         return new ReferenceEdgeProperties( fieldDesc,
73                                             isInitialParamReflexive,
74                                             beta );
75     }
76
77
78     public FieldDescriptor getFieldDesc() {
79         return fieldDesc;
80     }
81
82     public void setFieldDesc( FieldDescriptor fieldDesc ) {
83         this.fieldDesc = fieldDesc;
84     }
85
86
87
88     public boolean isInitialParamReflexive() {
89         return isInitialParamReflexive;
90     }
91     public void setIsInitialParamReflexive( boolean isInitialParamReflexive ) {
92         this.isInitialParamReflexive = isInitialParamReflexive;
93     }
94
95
96     public ReachabilitySet getBeta() {
97         return beta;
98     }
99
100     public void setBeta( ReachabilitySet beta ) {
101         assert beta != null;
102         this.beta = beta;
103     }
104
105     public ReachabilitySet getBetaNew() {
106         return betaNew;
107     }
108
109     public void setBetaNew( ReachabilitySet beta ) {
110         assert beta != null;
111         this.betaNew = beta;
112     }
113
114     public void applyBetaNew() {
115         assert betaNew != null;
116
117         beta = betaNew;
118
119         betaNew = new ReachabilitySet();
120         betaNew = betaNew.makeCanonical();
121     }
122
123
124     public boolean equals( Object o ) {
125         if( o == null ) {
126             return false;
127         }
128
129         if( !(o instanceof ReferenceEdgeProperties) ) {
130             return false;
131         }
132         
133         ReferenceEdgeProperties rep = (ReferenceEdgeProperties) o;
134
135         // field descriptors maintain the invariant that they are reference comparable
136         return fieldDesc               == rep.fieldDesc               &&
137                isInitialParamReflexive == rep.isInitialParamReflexive &&
138                beta.equals( rep.beta );
139     }
140
141     public int hashCode() {
142         int hash = 0;
143         if( fieldDesc != null ) {
144             hash += fieldDesc.getType().hashCode();
145         }
146         hash += beta.hashCode();
147         return hash;
148     }
149
150
151     public String getBetaString() {
152         return beta.toStringEscapeNewline();
153     }
154     
155     public String toEdgeLabelString() {
156         String edgeLabel = "";
157         if( fieldDesc != null ) {
158             edgeLabel += fieldDesc.toStringBrief() + "\\n";
159         }
160         if( isInitialParamReflexive ) {
161             edgeLabel += "Rflx\\n";
162         }
163         edgeLabel += getBetaString();
164         return edgeLabel;
165     }
166 }