1 package Analysis.Disjoint;
10 // all edges should have a non-null
12 protected TypeDescriptor type;
14 // the field name may be null if this
15 // edge models a variable reference
16 protected String field;
18 protected ReachSet beta;
19 protected ReachSet betaNew;
21 protected RefSrcNode src;
22 protected HeapRegionNode dst;
24 // existence predicates must be true in a caller
25 // context for this edge to transfer from this
26 // callee to that context--NOTE, existence predicates
27 // do not factor into edge comparisons
28 protected ExistPredSet preds;
30 // taint sets indicate which heap roots have
31 // tainted this edge-->meaning which heap roots
32 // code must have had access to in order to
33 // read or write through this edge
34 protected TaintSet taints;
37 public RefEdge(RefSrcNode src,
57 this.preds = ExistPredSet.factory();
63 this.beta = ReachSet.factory();
66 // when edges are not undergoing an operation that
67 // is changing beta info, betaNew is always empty
68 betaNew = ReachSet.factory();
70 if( taints != null ) {
73 this.taints = TaintSet.factory();
78 public RefEdge copy() {
79 RefEdge copy = new RefEdge(src,
90 public boolean equals(Object o) {
95 if( !(o instanceof RefEdge) ) {
99 RefEdge edge = (RefEdge) o;
101 if( !typeEquals(edge.type) ) {
105 if( !fieldEquals(edge.field) ) {
109 if( src instanceof VariableNode ) {
110 VariableNode vsrc = (VariableNode) src;
111 if( !vsrc.equals( (VariableNode) edge.src ) ) {
115 HeapRegionNode hsrc = (HeapRegionNode) src;
116 if( !hsrc.equalsIncludingAlphaAndPreds( (HeapRegionNode) edge.src ) ) {
121 if( !dst.equalsIncludingAlphaAndPreds( edge.dst ) ) {
129 // beta and preds contribute towards reaching the
130 // fixed point, so use this method to determine if
131 // an edge is "equal" to some previous visit, basically
133 public boolean equalsIncludingBetaPredsTaints(RefEdge edge) {
134 return equals(edge) &&
135 beta.equals(edge.beta) &&
136 preds.equals(edge.preds) &&
137 taints.equals(edge.taints);
140 public boolean equalsPreds(RefEdge edge) {
141 return preds.equals(edge.preds);
145 // this method SPECIFICALLY does not use the
146 // beta/preds/taints in the hash code--it uses
147 // the same fields as normal equals. Again,
148 // there are two meanings of equality for edges,
149 // one is "this edge is the same edge object" like when
150 // deciding if an edge is already in a set, which
151 // is represented by this hashcode. The other
152 // meaning is "this edge equals an edge from another
153 // graph that is abstractly the same edge"
154 public int hashCode() {
157 hash += type.hashCode()*17;
159 if( field != null ) {
160 hash += field.hashCode()*7;
163 hash += src.hashCode()*11;
164 hash += dst.hashCode();
170 public RefSrcNode getSrc() {
174 public void setSrc(RefSrcNode rsn) {
179 public HeapRegionNode getDst() {
183 public void setDst(HeapRegionNode hrn) {
189 public TypeDescriptor getType() {
193 public void setType(TypeDescriptor td) {
198 public String getField() {
202 public void setField(String s) {
207 public boolean typeEquals(TypeDescriptor td) {
208 return type.equals(td);
211 public boolean fieldEquals(String s) {
212 if( field == null && s == null ) {
215 if( field == null ) {
218 return field.equals(s);
221 public boolean typeAndFieldEquals(RefEdge e) {
222 return typeEquals(e.getType() ) &&
223 fieldEquals(e.getField() );
227 public ReachSet getBeta() {
231 public void setBeta(ReachSet beta) {
236 public ReachSet getBetaNew() {
240 public void setBetaNew(ReachSet beta) {
245 public void applyBetaNew() {
246 assert betaNew != null;
248 betaNew = ReachSet.factory();
252 public ExistPredSet getPreds() {
256 public void setPreds(ExistPredSet preds) {
261 public TaintSet getTaints() {
265 public void setTaints(TaintSet taints) {
266 this.taints = taints;
270 public String toStringDOT(boolean hideReach,
271 boolean hideSubsetReach,
273 boolean hideEdgeTaints,
274 String otherAttributes) {
277 type.toPrettyString()+"\\n"+
280 s += "\\n"+beta.toStringEscNewline(hideSubsetReach, hidePreds);
284 s += "\\n"+preds.toStringEscNewline();
287 if( !hideEdgeTaints ) {
288 if( !taints.isEmpty() ) {
289 s += "\\n"+taints.toStringEscNewline( hidePreds );
293 return s+"\",decorate"+otherAttributes+"]";
296 public String toString() {
297 return new String("("+src+
298 "->"+type.toPrettyString()+
304 public String toStringAndBeta() {
305 return toString()+beta.toString();