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