helpful progress reporting
[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 edge = (ReferenceEdge) o;
64
65     if( fieldDesc != edge.fieldDesc ) {
66       return false;
67     }
68
69     // Equality of edges is only valid within a graph, so
70     // compare src and dst by reference
71     if( !(src == edge.src) ||
72         !(dst == edge.dst)   ) {
73       return false;
74     }
75
76     return true;
77   }
78
79
80   public boolean equalsIncludingBeta(ReferenceEdge edge) {
81     return equals(edge) && beta.equals(edge.beta);
82   }
83
84
85   public int hashCode() {
86     int hash = 0;
87
88     if( fieldDesc != null ) {
89       hash += fieldDesc.hashCode();
90     }
91
92     hash += src.hashCode()*11;
93     hash += dst.hashCode();
94
95     return hash;
96   }
97
98
99   public OwnershipNode getSrc() {
100     return src;
101   }
102
103   public void setSrc(OwnershipNode on) {
104     assert on != null;
105     src = on;
106   }
107
108   public HeapRegionNode getDst() {
109     return dst;
110   }
111
112   public void setDst(HeapRegionNode hrn) {
113     assert hrn != null;
114     dst = hrn;
115   }
116
117
118   public FieldDescriptor getFieldDesc() {
119     return fieldDesc;
120   }
121
122   public void setFieldDesc(FieldDescriptor fieldDesc) {
123     this.fieldDesc = fieldDesc;
124   }
125
126
127   public boolean isInitialParamReflexive() {
128     return isInitialParamReflexive;
129   }
130   public void setIsInitialParamReflexive(boolean isInitialParamReflexive) {
131     this.isInitialParamReflexive = isInitialParamReflexive;
132   }
133
134
135   public ReachabilitySet getBeta() {
136     return beta;
137   }
138
139   public void setBeta(ReachabilitySet beta) {
140     assert beta != null;
141     this.beta = beta;
142   }
143
144   public ReachabilitySet getBetaNew() {
145     return betaNew;
146   }
147
148   public void setBetaNew(ReachabilitySet beta) {
149     assert beta != null;
150     this.betaNew = beta;
151   }
152
153   public void applyBetaNew() {
154     assert betaNew != null;
155
156     beta    = betaNew;
157     betaNew = new ReachabilitySet().makeCanonical();
158   }
159
160
161   public String toGraphEdgeString() {
162     String edgeLabel = "";
163
164     if( fieldDesc != null ) {
165       edgeLabel += fieldDesc.toStringBrief() + "\\n";
166     }
167
168     if( isInitialParamReflexive ) {
169       edgeLabel += "Rflx\\n";
170     }
171
172     edgeLabel += beta.toStringEscapeNewline();
173
174     return edgeLabel;
175   }
176
177   public String toString() {
178     return new String("("+src+" "+fieldDesc+" "+dst+")");
179   }
180 }