1 19 20 package soot.jimple.spark.pag; 21 import soot.*; 22 import soot.jimple.spark.*; 23 import soot.util.*; 24 import soot.Type; 25 import soot.jimple.spark.sets.PointsToSetInternal; 26 import soot.jimple.spark.sets.EmptyPointsToSet; 27 import soot.jimple.toolkits.pointer.representations.ReferenceVariable; 28 import soot.jimple.spark.internal.TypeManager; 29 30 33 public class Node implements ReferenceVariable, Numberable { 34 public final int hashCode() { return number; } 35 public final boolean equals( Object other ) { 36 return this == other; 37 } 38 39 public Type getType() { return type; } 40 41 public void setType( Type type ) { 42 if( TypeManager.isUnresolved(type) ) throw new RuntimeException ("Unresolved type "+type ); 43 this.type = type; 44 } 45 48 public Node getReplacement() { 49 if( replacement != replacement.replacement ) { 50 replacement = replacement.getReplacement(); 51 } 52 return replacement; 53 } 54 55 public void mergeWith( Node other ) { 56 if( other.replacement != other ) { 57 throw new RuntimeException ( "Shouldn't happen" ); 58 } 59 Node myRep = getReplacement(); 60 if( other == myRep ) return; 61 other.replacement = myRep; 62 if( other.p2set != p2set 63 && other.p2set != null 64 && !other.p2set.isEmpty() ) { 65 if( myRep.p2set == null || myRep.p2set.isEmpty() ) { 66 myRep.p2set = other.p2set; 67 } else { 68 myRep.p2set.mergeWith( other.p2set ); 69 } 70 } 71 other.p2set = null; 72 pag.mergedWith( myRep, other ); 73 if( (other instanceof VarNode) 74 && (myRep instanceof VarNode ) 75 && ((VarNode) other).isInterProcTarget() ) 76 ((VarNode) myRep).setInterProcTarget(); 77 } 78 79 public PointsToSetInternal getP2Set() { 80 if( p2set != null ) { 81 if( replacement != this ) throw new RuntimeException ( 82 "Node "+this+" has replacement "+replacement+" but has p2set" ); 83 return p2set; 84 } 85 Node rep = getReplacement(); 86 if( rep == this ) { 87 return EmptyPointsToSet.v(); 88 } 89 return rep.getP2Set(); 90 } 91 92 public PointsToSetInternal makeP2Set() { 93 if( p2set != null ) { 94 if( replacement != this ) throw new RuntimeException ( 95 "Node "+this+" has replacement "+replacement+" but has p2set" ); 96 return p2set; 97 } 98 Node rep = getReplacement(); 99 if( rep == this ) { 100 p2set = pag.getSetFactory().newSet( type, (PAG) pag ); 101 } 102 return rep.makeP2Set(); 103 } 104 105 public PAG getPag() { return pag; } 106 107 108 109 110 Node( PAG pag, Type type ) { 111 if( TypeManager.isUnresolved(type) ) throw new RuntimeException ("Unresolved type "+type ); 112 this.type = type; 113 this.pag = pag; 114 replacement = this; 115 } 116 117 118 119 public final int getNumber() { return number; } 120 public final void setNumber( int number ) { this.number = number; } 121 122 private int number = 0; 123 124 protected Type type; 125 protected Node replacement; 126 protected PAG pag; 127 protected PointsToSetInternal p2set; 128 } 129 | Popular Tags |