1 19 20 package soot.toolkits.scalar; 21 22 import soot.*; 23 import soot.jimple.Jimple; 24 25 30 public class ValueUnitPair extends AbstractValueBox implements UnitBox, EquivTo 31 { 32 protected Unit unit; 39 40 46 public ValueUnitPair(Value value, Unit unit) 47 { 48 setValue(value); 49 setUnit(unit); 50 } 51 52 public boolean canContainValue(Value value) 53 { 54 return true; 55 } 56 57 60 public void setUnit(Unit unit) 61 { 62 63 64 if(!canContainUnit(unit)) 65 throw new RuntimeException ("Cannot put " + unit + " in this box"); 66 67 if(this.unit != null){ 69 this.unit.removeBoxPointingToThis(this); 70 } 71 72 this.unit = unit; 74 75 if(this.unit != null){ 77 this.unit.addBoxPointingToThis(this); 78 } 79 } 80 81 84 public Unit getUnit() 85 { 86 return unit; 87 } 88 89 92 public boolean canContainUnit(Unit u) 93 { 94 return true; 95 } 96 97 100 public boolean isBranchTarget() 101 { 102 return true; 103 } 104 105 public String toString() 106 { 107 return "Value = " + getValue() + ", Unit = " + getUnit(); 108 } 109 110 public void toString(UnitPrinter up) 111 { 112 super.toString(up); 113 114 if(isBranchTarget()) 115 up.literal(", "); 116 else 117 up.literal(" #"); 118 119 up.startUnitBox(this); 120 up.unitRef(unit, isBranchTarget()); 121 up.endUnitBox(this); 122 } 123 124 public int hashCode() 125 { 126 return super.hashCode(); 130 } 131 132 public boolean equals(Object other) 133 { 134 return super.equals(other); 138 } 139 140 147 public boolean equivTo(Object other) 148 { 149 return 150 (other instanceof ValueUnitPair) && 151 ((ValueUnitPair) other).getValue().equivTo(this.getValue()) && 152 ((ValueUnitPair) other).getUnit().equals(getUnit()); 153 } 154 155 166 public int equivHashCode() 167 { 168 return 171 (getUnit().hashCode() * 17) + 172 (getValue().equivHashCode() * 101); 173 } 174 175 public Object clone() 176 { 177 Value cv = Jimple.cloneIfNecessary((Value) getValue()); 183 Unit cu = (Unit) getUnit(); 184 return new ValueUnitPair(cv, cu); 185 } 186 } 187 | Popular Tags |