1 package Analysis.OwnershipAnalysis;
7 public class ReferenceEdge {
9 // null descriptors mean "any field"
10 protected TypeDescriptor type;
11 protected String field;
13 protected boolean isInitialParam;
15 protected ReachabilitySet beta;
16 protected ReachabilitySet betaNew;
18 protected OwnershipNode src;
19 protected HeapRegionNode dst;
20 private int taintIdentifier;
23 public ReferenceEdge(OwnershipNode src,
27 boolean isInitialParam,
28 ReachabilitySet beta) {
34 this.isInitialParam = isInitialParam;
35 this.taintIdentifier = 0;
40 this.beta = new ReachabilitySet().makeCanonical();
43 // when edges are not undergoing a transitional operation
44 // that is changing beta info, betaNew is always empty
45 betaNew = new ReachabilitySet().makeCanonical();
49 public ReferenceEdge copy() {
50 ReferenceEdge copy= new ReferenceEdge(src,
56 copy.setTaintIdentifier(this.taintIdentifier);
61 public boolean equals(Object o) {
66 if( !(o instanceof ReferenceEdge) ) {
70 ReferenceEdge edge = (ReferenceEdge) o;
72 if( !typeEquals( edge.type ) ) {
76 if( !fieldEquals( edge.field ) ) {
80 // Equality of edges is only valid within a graph, so
81 // compare src and dst by reference
82 if( !(src == edge.src) ||
83 !(dst == edge.dst) ) {
91 public boolean equalsIncludingBeta(ReferenceEdge edge) {
92 return equals(edge) && beta.equals(edge.beta);
96 public int hashCode() {
100 hash += type.hashCode()*17;
103 if( field != null ) {
104 hash += field.hashCode()*7;
107 hash += src.hashCode()*11;
108 hash += dst.hashCode();
114 public OwnershipNode getSrc() {
118 public void setSrc(OwnershipNode on) {
123 public HeapRegionNode getDst() {
127 public void setDst(HeapRegionNode hrn) {
133 public TypeDescriptor getType() {
137 public void setType( TypeDescriptor td ) {
141 public String getField() {
145 public void setField( String s ) {
150 public boolean typeEquals( TypeDescriptor td ) {
151 if( type == null && td == null ) {
157 return type.equals( td );
160 public boolean fieldEquals( String s ) {
161 if( field == null && s == null ) {
164 if( field == null ) {
167 return field.equals( s );
170 public boolean typeAndFieldEquals( ReferenceEdge e ) {
171 return typeEquals ( e.getType() ) &&
172 fieldEquals( e.getField() );
176 public boolean isInitialParam() {
177 return isInitialParam;
180 public void setIsInitialParam(boolean isInitialParam) {
181 this.isInitialParam = isInitialParam;
185 public ReachabilitySet getBeta() {
189 public void setBeta(ReachabilitySet beta) {
194 public ReachabilitySet getBetaNew() {
198 public void setBetaNew(ReachabilitySet beta) {
203 public void applyBetaNew() {
204 assert betaNew != null;
207 betaNew = new ReachabilitySet().makeCanonical();
211 public String toGraphEdgeString( boolean hideSubsetReachability ) {
212 String edgeLabel = "";
215 edgeLabel += type.toPrettyString()+"\\n";
218 if( field != null ) {
219 edgeLabel += field+"\\n";
222 if( isInitialParam ) {
223 edgeLabel += "*init*\\n";
226 edgeLabel+="*taint*="+Integer.toBinaryString(taintIdentifier)+"\\n";
228 edgeLabel += beta.toStringEscapeNewline(hideSubsetReachability);
233 public String toString() {
235 return new String("("+src+"->"+type.toPrettyString()+" "+field+"->"+dst+")");
238 return new String("("+src+"->"+type+" "+field+"->"+dst+")");
241 public void tainedBy(Integer paramIdx){
242 int newTaint=(int) Math.pow(2, paramIdx.intValue());
243 taintIdentifier=taintIdentifier | newTaint;
246 public void setTaintIdentifier(int newTaint){
247 taintIdentifier=newTaint;
250 public void unionTaintIdentifier(int newTaint){
251 taintIdentifier=taintIdentifier | newTaint;
254 public void minusTaintIdentifier(int removedTaint){
255 taintIdentifier = taintIdentifier & (~removedTaint);
258 public int getTaintIdentifier(){
259 return taintIdentifier;