1 19 25 26 package soot.dava.toolkits.base.AST; 27 28 import soot.*; 29 import soot.jimple.*; 30 31 public class ASTWalker 32 { 33 public ASTWalker( Singletons.Global g ) {} 34 public static ASTWalker v() { return G.v().soot_dava_toolkits_base_AST_ASTWalker(); } 35 36 public void walk_stmt( ASTAnalysis a, Stmt s) 37 { 38 if (a.getAnalysisDepth() < ASTAnalysis.ANALYSE_STMTS) 39 return; 40 41 if (s instanceof DefinitionStmt) { 42 DefinitionStmt ds = (DefinitionStmt) s; 43 44 walk_value( a, ds.getRightOp()); 45 walk_value( a, ds.getLeftOp()); 46 a.analyseDefinitionStmt( ds); 47 } 48 else if (s instanceof ReturnStmt) { 49 ReturnStmt rs = (ReturnStmt) s; 50 51 walk_value( a, rs.getOp()); 52 a.analyseReturnStmt( rs); 53 } 54 else if (s instanceof InvokeStmt) { 55 InvokeStmt is = (InvokeStmt) s; 56 57 walk_value( a, is.getInvokeExpr()); 58 a.analyseInvokeStmt( is); 59 } 60 else if (s instanceof ThrowStmt) { 61 ThrowStmt ts = (ThrowStmt) s; 62 63 walk_value( a, ts.getOp()); 64 a.analyseThrowStmt( ts); 65 } 66 else 67 a.analyseStmt( s); 68 } 69 70 public void walk_value( ASTAnalysis a, Value v) 71 { 72 if (a.getAnalysisDepth() < ASTAnalysis.ANALYSE_VALUES) 73 return; 74 75 if (v instanceof Expr) { 76 Expr e = (Expr) v; 77 78 if (e instanceof BinopExpr) { 79 BinopExpr be = (BinopExpr) e; 80 81 walk_value( a, be.getOp1()); 82 walk_value( a, be.getOp2()); 83 a.analyseBinopExpr( be); 84 } 85 else if (e instanceof UnopExpr) { 86 UnopExpr ue = (UnopExpr) e; 87 88 walk_value( a, ue.getOp()); 89 a.analyseUnopExpr( ue); 90 } 91 else if (e instanceof NewArrayExpr) { 92 NewArrayExpr nae = (NewArrayExpr) e; 93 94 walk_value( a, nae.getSize()); 95 a.analyseNewArrayExpr( nae); 96 } 97 else if (e instanceof NewMultiArrayExpr) { 98 NewMultiArrayExpr nmae = (NewMultiArrayExpr) e; 99 100 for (int i=0; i<nmae.getSizeCount(); i++) 101 walk_value( a, nmae.getSize( i)); 102 a.analyseNewMultiArrayExpr( nmae); 103 } 104 else if (e instanceof InstanceOfExpr) { 105 InstanceOfExpr ioe = (InstanceOfExpr) e; 106 107 walk_value( a, ioe.getOp()); 108 a.analyseInstanceOfExpr( ioe); 109 } 110 else if (e instanceof InvokeExpr) { 111 InvokeExpr ie = (InvokeExpr) e; 112 113 for (int i=0; i<ie.getArgCount(); i++) 114 walk_value( a, ie.getArg( i)); 115 116 if (ie instanceof InstanceInvokeExpr) { 117 InstanceInvokeExpr iie = (InstanceInvokeExpr) ie; 118 119 walk_value( a, iie.getBase()); 120 a.analyseInstanceInvokeExpr( iie); 121 } 122 else 123 a.analyseInvokeExpr( ie); 124 } 125 else 126 a.analyseExpr( e); 127 } 128 else if (v instanceof Ref) { 129 Ref r = (Ref) v; 130 131 if (r instanceof ArrayRef) { 132 ArrayRef ar = (ArrayRef) r; 133 134 walk_value( a, ar.getBase()); 135 walk_value( a, ar.getIndex()); 136 a.analyseArrayRef( ar); 137 } 138 else if (r instanceof InstanceFieldRef) { 139 InstanceFieldRef ifr = (InstanceFieldRef) r; 140 141 walk_value( a, ifr.getBase()); 142 a.analyseInstanceFieldRef( ifr); 143 } 144 else 145 a.analyseRef( r); 146 } 147 else 148 a.analyseValue( v); 149 } 150 } 151 | Popular Tags |