00001 package ca.mcgill.sable.soot.jimple;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 import ca.mcgill.sable.soot.*;
00083 import ca.mcgill.sable.util.*;
00084
00085 public class StmtList extends ArrayList
00086 {
00087 StmtBody body;
00088
00089 public StmtList(StmtBody body)
00090 {
00091 super();
00092
00093 this.body = body;
00094 }
00095 public StmtBody getBody()
00096 {
00097 return body;
00098 }
00099 public Object remove(int index)
00100 {
00101 Object obj = get(index);
00102 Object toReturn = null;
00103
00104 if(contains(obj))
00105 {
00106 Stmt successor;
00107
00108 if(index + 1 < size())
00109 successor = (Stmt) get(index + 1);
00110 else if(size() >= 2)
00111 successor = (Stmt) get(index - 1);
00112 else
00113 successor = null;
00114
00115 toReturn = super.remove(index);
00116
00117 body.redirectJumps((Stmt) obj, successor);
00118 body.eliminateBackPointersTo((Stmt) obj);
00119
00120 }
00121
00122 return toReturn;
00123 }
00124 public boolean remove(Object obj)
00125 {
00126 boolean toReturn = false;
00127
00128 if(contains(obj))
00129 {
00130 int index = indexOf(obj);
00131 Stmt successor;
00132
00133 if(index + 1 < size())
00134 successor = (Stmt) get(index + 1);
00135 else if(size() >= 2)
00136 successor = (Stmt) get(index - 1);
00137 else
00138 successor = null;
00139
00140 toReturn = super.remove(obj);
00141 body.redirectJumps((Stmt) obj, successor);
00142 body.eliminateBackPointersTo((Stmt) obj);
00143 }
00144
00145 return toReturn;
00146 }
00147 public boolean removeAll(Collection c)
00148 {
00149 throw new UnsupportedOperationException();
00150 }
00151 public void testIntegrity(String message)
00152 {
00153 Iterator stmtIt = iterator();
00154
00155 while(stmtIt.hasNext())
00156 {
00157 Stmt s = (Stmt) stmtIt.next();
00158 Iterator boxIt = s.getUnitBoxes().iterator();
00159
00160 while(boxIt.hasNext())
00161 {
00162 StmtBox box = (StmtBox) boxIt.next();
00163 Stmt pointed = (Stmt) box.getUnit();
00164
00165 if(!contains(pointed))
00166 throw new RuntimeException(message + "Statement no longer contained");
00167
00168 if(!pointed.getBoxesPointingToThis().contains(box))
00169 throw new RuntimeException(message + "back pointer not set");
00170 }
00171 }
00172
00173 stmtIt = iterator();
00174
00175 while(stmtIt.hasNext())
00176 {
00177 Stmt s = (Stmt) stmtIt.next();
00178 List boxes = s.getBoxesPointingToThis();
00179
00180 Iterator it = boxes.iterator();
00181
00182 while(it.hasNext())
00183 {
00184 StmtBox box = (StmtBox) it.next();
00185
00186 if(box.getUnit() != s)
00187 throw new RuntimeException(message + "back pointer still set");
00188 }
00189 }
00190
00191 stmtIt = iterator();
00192
00193 while(stmtIt.hasNext())
00194 {
00195 Stmt s = (Stmt) stmtIt.next();
00196 Iterator boxIt = s.getUnitBoxes().iterator();
00197
00198 while(boxIt.hasNext())
00199 {
00200 StmtBox box = (StmtBox) boxIt.next();
00201
00202 if(indexOf(box.getUnit()) == -1)
00203 {
00204 System.out.println("looking for: " + box.getUnit());
00205 throw new RuntimeException(message + "[failed integrity test for: " + s + "]");
00206 }
00207 }
00208 }
00209 }
00210 }