1 19 20 package soot.jimple; 21 import soot.*; 22 23 public abstract class PointerStmtSwitch extends AbstractStmtSwitch { 24 Stmt statement; 25 26 27 protected abstract void caseAssignConstStmt( Value dest, Constant c ); 28 29 30 protected abstract void caseCopyStmt( Local dest, Local src ); 31 32 33 protected void caseCastStmt( Local dest, Local src, CastExpr c ) { 34 caseCopyStmt( dest, src ); 36 } 37 38 protected abstract void caseIdentityStmt( Local dest, IdentityRef src ); 39 40 41 protected abstract void caseLoadStmt( Local dest, InstanceFieldRef src ); 42 43 44 protected abstract void caseStoreStmt( InstanceFieldRef dest, Local src ); 45 46 47 protected abstract void caseArrayLoadStmt( Local dest, ArrayRef src ); 48 49 protected abstract void caseArrayStoreStmt( ArrayRef dest, Local src ); 50 51 protected abstract void caseGlobalLoadStmt( Local dest, StaticFieldRef src ); 52 53 protected abstract void caseGlobalStoreStmt( StaticFieldRef dest, Local src ); 54 55 protected abstract void caseReturnStmt( Local val ); 56 57 protected void caseReturnConstStmt( Constant val ) { 58 caseUninterestingStmt( statement ); 60 } 61 62 protected abstract void caseAnyNewStmt( Local dest, Expr e ); 63 64 protected void caseNewStmt( Local dest, NewExpr e ) { 65 caseAnyNewStmt( dest, e ); 66 } 67 68 protected void caseNewArrayStmt( Local dest, NewArrayExpr e ) { 69 caseAnyNewStmt( dest, e ); 70 } 71 72 protected void caseNewMultiArrayStmt( Local dest, NewMultiArrayExpr e ) { 73 caseAnyNewStmt( dest, e ); 74 } 75 76 protected abstract void caseInvokeStmt( Local dest, InvokeExpr e ); 77 78 protected void caseThrowStmt( Local thrownException ) { 79 caseUninterestingStmt(statement); 80 } 81 82 protected void caseCatchStmt( Local dest, CaughtExceptionRef cer ) { 83 caseUninterestingStmt(statement); 84 } 85 86 protected void caseUninterestingStmt( Stmt s ) {}; 87 88 public final void caseAssignStmt( AssignStmt s ) { 89 statement = s; 90 Value lhs = s.getLeftOp(); 91 Value rhs = s.getRightOp(); 92 if( ! (lhs.getType() instanceof RefType) 93 && ! (lhs.getType() instanceof ArrayType) ) { 94 if( rhs instanceof InvokeExpr ) { 95 caseInvokeStmt( null, (InvokeExpr) rhs ); 96 return; 97 } 98 caseUninterestingStmt( s ); 99 return; 100 } 101 if( rhs instanceof InvokeExpr ) { 102 caseInvokeStmt( (Local) lhs, (InvokeExpr) rhs ); 103 return; 104 } 105 if( lhs instanceof Local ) { 106 if( rhs instanceof Local ) { 107 caseCopyStmt( (Local) lhs, (Local) rhs ); 108 } else if( rhs instanceof InstanceFieldRef ) { 109 caseLoadStmt( (Local) lhs, (InstanceFieldRef) rhs ); 110 } else if( rhs instanceof ArrayRef ) { 111 caseArrayLoadStmt( (Local) lhs, (ArrayRef) rhs ); 112 } else if( rhs instanceof StaticFieldRef ) { 113 caseGlobalLoadStmt( (Local) lhs, (StaticFieldRef) rhs ); 114 } else if( rhs instanceof NewExpr ) { 115 caseNewStmt( (Local) lhs, (NewExpr) rhs ); 116 } else if( rhs instanceof NewArrayExpr ) { 117 caseNewArrayStmt( (Local) lhs, (NewArrayExpr) rhs ); 118 } else if( rhs instanceof NewMultiArrayExpr ) { 119 caseNewMultiArrayStmt( (Local) lhs, (NewMultiArrayExpr) rhs ); 120 } else if( rhs instanceof CastExpr ) { 121 CastExpr r = (CastExpr) rhs; 122 Value rv = r.getOp(); 123 if( rv instanceof Constant ) { 124 caseAssignConstStmt( lhs, (Constant) rv ); 125 } else { 126 caseCastStmt( (Local) lhs, (Local) rv, r ); 127 } 128 } else if( rhs instanceof Constant ) { 129 caseAssignConstStmt( lhs, (Constant) rhs ); 130 } else throw new RuntimeException ( "unhandled stmt "+s ); 131 } else if( lhs instanceof InstanceFieldRef ) { 132 if( rhs instanceof Local ) { 133 caseStoreStmt( (InstanceFieldRef) lhs, (Local) rhs ); 134 } else if( rhs instanceof Constant ) { 135 caseAssignConstStmt( lhs, (Constant) rhs ); 136 } else throw new RuntimeException ( "unhandled stmt "+s ); 137 } else if( lhs instanceof ArrayRef ) { 138 if( rhs instanceof Local ) { 139 caseArrayStoreStmt( (ArrayRef) lhs, (Local) rhs ); 140 } else if( rhs instanceof Constant ) { 141 caseAssignConstStmt( lhs, (Constant) rhs ); 142 } else throw new RuntimeException ( "unhandled stmt "+s ); 143 } else if( lhs instanceof StaticFieldRef ) { 144 if( rhs instanceof Local ) { 145 caseGlobalStoreStmt( (StaticFieldRef) lhs, (Local) rhs ); 146 } else if( rhs instanceof Constant ) { 147 caseAssignConstStmt( lhs, (Constant) rhs ); 148 } else throw new RuntimeException ( "unhandled stmt "+s ); 149 } else if( rhs instanceof Constant ) { 150 caseAssignConstStmt( lhs, (Constant) rhs ); 151 } else throw new RuntimeException ( "unhandled stmt "+s ); 152 } 153 public final void caseReturnStmt(ReturnStmt s) { 154 statement = s; 155 Value op = s.getOp(); 156 if( op.getType() instanceof RefType 157 || op.getType() instanceof ArrayType ) { 158 if( op instanceof Constant ) { 159 caseReturnConstStmt( (Constant) op ); 160 } else { 161 caseReturnStmt( (Local) op ); 162 } 163 } else { 164 caseReturnStmt( (Local) null ); 165 } 166 } 167 public final void caseReturnVoidStmt(ReturnVoidStmt s) { 168 statement = s; 169 caseReturnStmt( (Local) null ); 170 } 171 public final void caseInvokeStmt(InvokeStmt s) { 172 statement = s; 173 caseInvokeStmt( null, (InvokeExpr) s.getInvokeExpr() ); 174 } 175 public final void caseIdentityStmt(IdentityStmt s) { 176 statement = s; 177 Value lhs = s.getLeftOp(); 178 Value rhs = s.getRightOp(); 179 if( !( lhs.getType() instanceof RefType ) 180 && !(lhs.getType() instanceof ArrayType ) ) { 181 caseUninterestingStmt( s ); 182 return; 183 } 184 Local llhs = (Local) lhs; 185 if( rhs instanceof CaughtExceptionRef ) { 186 caseCatchStmt( llhs, (CaughtExceptionRef) rhs ); 187 } else { 188 IdentityRef rrhs = (IdentityRef) rhs; 189 caseIdentityStmt( llhs, rrhs ); 190 } 191 } 192 public final void caseThrowStmt( ThrowStmt s) { 193 statement = s; 194 caseThrowStmt( (Local) s.getOp() ); 195 } 196 } 197 198 | Popular Tags |