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 setTaints( taints != null ? taints : TaintSet.factory() );
74 public RefEdge copy() {
75 RefEdge copy = new RefEdge(src,
86 public boolean equals(Object o) {
91 if( !(o instanceof RefEdge) ) {
95 RefEdge edge = (RefEdge) o;
97 if( !typeEquals(edge.type) ) {
101 if( !fieldEquals(edge.field) ) {
105 if( src instanceof VariableNode ) {
106 VariableNode vsrc = (VariableNode) src;
107 if( !vsrc.equals( (VariableNode) edge.src ) ) {
111 HeapRegionNode hsrc = (HeapRegionNode) src;
112 if( !hsrc.equalsIncludingAlphaAndPreds( (HeapRegionNode) edge.src ) ) {
117 if( !dst.equalsIncludingAlphaAndPreds( edge.dst ) ) {
125 // beta and preds contribute towards reaching the
126 // fixed point, so use this method to determine if
127 // an edge is "equal" to some previous visit, basically
129 public boolean equalsIncludingBetaPredsTaints(RefEdge edge) {
130 return equals(edge) &&
131 beta.equals(edge.beta) &&
132 preds.equals(edge.preds) &&
133 taints.equals(edge.taints);
136 public boolean equalsPreds(RefEdge edge) {
137 return preds.equals(edge.preds);
141 // this method SPECIFICALLY does not use the
142 // beta/preds/taints in the hash code--it uses
143 // the same fields as normal equals. Again,
144 // there are two meanings of equality for edges,
145 // one is "this edge is the same edge object" like when
146 // deciding if an edge is already in a set, which
147 // is represented by this hashcode. The other
148 // meaning is "this edge equals an edge from another
149 // graph that is abstractly the same edge"
150 public int hashCode() {
153 hash += type.hashCode()*17;
155 if( field != null ) {
156 hash += field.hashCode()*7;
159 hash += src.hashCode()*11;
160 hash += dst.hashCode();
166 public RefSrcNode getSrc() {
170 public void setSrc(RefSrcNode rsn) {
175 public HeapRegionNode getDst() {
179 public void setDst(HeapRegionNode hrn) {
185 public TypeDescriptor getType() {
189 public void setType(TypeDescriptor td) {
194 public String getField() {
198 public void setField(String s) {
203 public boolean typeEquals(TypeDescriptor td) {
204 return type.equals(td);
207 public boolean fieldEquals(String s) {
208 if( field == null && s == null ) {
211 if( field == null ) {
214 return field.equals(s);
217 public boolean typeAndFieldEquals(RefEdge e) {
218 return typeEquals(e.getType() ) &&
219 fieldEquals(e.getField() );
223 public ReachSet getBeta() {
227 public void setBeta(ReachSet beta) {
232 public ReachSet getBetaNew() {
236 public void setBetaNew(ReachSet beta) {
241 public void applyBetaNew() {
242 assert betaNew != null;
244 betaNew = ReachSet.factory();
248 public ExistPredSet getPreds() {
252 public void setPreds(ExistPredSet preds) {
257 public TaintSet getTaints() {
261 public void setTaints(TaintSet taints) {
262 this.taints = taints;
266 public String toStringDOT(boolean hideReach,
267 boolean hideSubsetReach,
269 boolean hideEdgeTaints,
270 String otherAttributes) {
273 type.toPrettyString()+"\\n"+
276 s += "\\n"+beta.toStringEscNewline(hideSubsetReach, hidePreds);
280 s += "\\n"+preds.toStringEscNewline();
283 if( !hideEdgeTaints ) {
284 if( !taints.isEmpty() ) {
285 s += "\\n"+taints.toStringEscNewline( hidePreds );
289 return s+"\",decorate"+otherAttributes+"]";
292 public String toString() {
293 return new String("("+src+
294 "->"+type.toPrettyString()+
300 public String toStringAndBeta() {
301 return toString()+beta.toString();