1 19 20 25 26 27 28 29 30 package soot; 31 32 import soot.tagkit.*; 33 import soot.*; 34 import soot.util.*; 35 import java.util.*; 36 37 38 public abstract class AbstractUnit extends AbstractHost implements Unit 39 { 40 41 42 public abstract Object clone(); 43 44 49 public List getUseBoxes() 50 { 51 return emptyList; 52 } 53 54 57 public List getDefBoxes() 58 { 59 return emptyList; 60 } 61 62 63 67 public List getUnitBoxes() 68 { 69 return emptyList; 70 } 71 72 73 static final public List emptyList = Collections.EMPTY_LIST; 74 75 76 List boxesPointingToThis = null; 77 78 79 List valueBoxes = null; 80 81 82 public List getBoxesPointingToThis() 83 { 84 if( boxesPointingToThis == null ) return emptyList; 85 return Collections.unmodifiableList( boxesPointingToThis ); 86 } 87 88 public void addBoxPointingToThis( UnitBox b ) { 89 if( boxesPointingToThis == null ) boxesPointingToThis = new ArrayList(); 90 boxesPointingToThis.add( b ); 91 } 92 93 public void removeBoxPointingToThis( UnitBox b ) { 94 if( boxesPointingToThis != null ) boxesPointingToThis.remove( b ); 95 } 96 97 public void clearUnitBoxes() { 98 for( Iterator it = getUnitBoxes().iterator(); it.hasNext(); ) { 99 UnitBox ub = (UnitBox) it.next(); 100 ub.setUnit(null); 101 } 102 } 103 104 105 public List getUseAndDefBoxes() 106 { 107 List useBoxes = getUseBoxes(); 108 List defBoxes = getDefBoxes(); 109 if( useBoxes.isEmpty() ) { 110 if( defBoxes.isEmpty() ) { 111 return emptyList; 112 } else { 113 return Collections.unmodifiableList(defBoxes); 114 } 115 } else { 116 if( defBoxes.isEmpty() ) { 117 return Collections.unmodifiableList(useBoxes); 118 } else { 119 valueBoxes = new ArrayList(); 120 121 valueBoxes.addAll(defBoxes); 122 valueBoxes.addAll(useBoxes); 123 124 valueBoxes = Collections.unmodifiableList(valueBoxes); 125 126 return valueBoxes; 127 } 128 } 129 } 130 131 132 public void apply(Switch sw) 133 { 134 } 135 136 public void redirectJumpsToThisTo(Unit newLocation) 137 { 138 List boxesPointing = this.getBoxesPointingToThis(); 139 140 Object [] boxes = boxesPointing.toArray(); 141 143 for(int i = 0; i < boxes.length; i++) 144 { 145 UnitBox box = (UnitBox) boxes[i]; 146 147 if(box.getUnit() != this) 148 throw new RuntimeException ("Something weird's happening"); 149 150 if(box.isBranchTarget()) 151 box.setUnit(newLocation); 152 } 153 154 } 155 } 156 | Popular Tags |