1 19 20 23 24 29 30 31 package soot.dava.toolkits.base.AST.traversals; 32 33 34 import java.util.*; 35 import soot.jimple.*; 36 import soot.dava.internal.AST.*; 37 import soot.dava.internal.javaRep.*; 38 import soot.dava.toolkits.base.AST.analysis.*; 39 40 41 51 52 public class ASTParentNodeFinder extends DepthFirstAdapter{ 53 54 HashMap parentOf; 55 Stack parentStack; 56 57 public ASTParentNodeFinder(){ 58 parentOf = new HashMap(); 59 parentStack = new Stack(); 60 } 61 62 public ASTParentNodeFinder(boolean verbose){ 63 super(verbose); 64 parentOf = new HashMap(); 65 parentStack = new Stack(); 66 } 67 68 public void inASTMethodNode(ASTMethodNode node){ 69 parentOf.put(node,null); 70 parentStack.push(node); 71 } 72 73 public void outASTMethodNode(ASTMethodNode node){ 74 parentStack.pop(); 75 } 76 77 78 public void inASTSynchronizedBlockNode(ASTSynchronizedBlockNode node){ 79 parentOf.put(node,parentStack.peek()); 80 parentStack.push(node); 81 } 82 public void outASTSynchronizedBlockNode(ASTSynchronizedBlockNode node){ 83 parentStack.pop(); 84 } 85 86 87 public void inASTLabeledBlockNode (ASTLabeledBlockNode node){ 88 parentOf.put(node,parentStack.peek()); 89 parentStack.push(node); 90 } 91 public void outASTLabeledBlockNode (ASTLabeledBlockNode node){ 92 parentStack.pop(); 93 } 94 95 96 97 public void inASTUnconditionalLoopNode (ASTUnconditionalLoopNode node){ 98 parentOf.put(node,parentStack.peek()); 99 parentStack.push(node); 100 } 101 public void outASTUnconditionalLoopNode (ASTUnconditionalLoopNode node){ 102 parentStack.pop(); 103 } 104 105 106 107 public void inASTSwitchNode(ASTSwitchNode node){ 108 parentOf.put(node,parentStack.peek()); 109 parentStack.push(node); 110 } 111 public void outASTSwitchNode(ASTSwitchNode node){ 112 parentStack.pop(); 113 } 114 115 116 117 118 public void inASTIfNode(ASTIfNode node){ 119 parentOf.put(node,parentStack.peek()); 120 parentStack.push(node); 121 } 122 public void outASTIfNode(ASTIfNode node){ 123 parentStack.pop(); 124 } 125 126 127 128 129 public void inASTIfElseNode(ASTIfElseNode node){ 130 parentOf.put(node,parentStack.peek()); 131 parentStack.push(node); 132 } 133 public void outASTIfElseNode(ASTIfElseNode node){ 134 parentStack.pop(); 135 } 136 137 138 139 140 public void inASTWhileNode(ASTWhileNode node){ 141 parentOf.put(node,parentStack.peek()); 142 parentStack.push(node); 143 } 144 public void outASTWhileNode(ASTWhileNode node){ 145 parentStack.pop(); 146 } 147 148 149 150 151 152 153 154 public void inASTForLoopNode(ASTForLoopNode node){ 155 parentOf.put(node,parentStack.peek()); 156 parentStack.push(node); 157 } 158 public void outASTForLoopNode(ASTForLoopNode node){ 159 parentStack.pop(); 160 } 161 162 163 164 165 public void inASTDoWhileNode(ASTDoWhileNode node){ 166 parentOf.put(node,parentStack.peek()); 167 parentStack.push(node); 168 } 169 public void outASTDoWhileNode(ASTDoWhileNode node){ 170 parentStack.pop(); 171 } 172 173 174 175 176 177 178 179 public void inASTTryNode(ASTTryNode node){ 180 parentOf.put(node,parentStack.peek()); 181 parentStack.push(node); 182 } 183 public void outASTTryNode(ASTTryNode node){ 184 parentStack.pop(); 185 } 186 187 188 189 190 191 192 public void inASTStatementSequenceNode(ASTStatementSequenceNode node){ 193 parentOf.put(node,parentStack.peek()); 194 parentStack.push(node); 195 } 196 public void outASTStatementSequenceNode(ASTStatementSequenceNode node){ 197 parentStack.pop(); 198 } 199 200 201 202 203 public void inDefinitionStmt(DefinitionStmt s){ 204 parentOf.put(s,parentStack.peek()); 205 } 206 207 public void inReturnStmt(ReturnStmt s){ 208 parentOf.put(s,parentStack.peek()); 209 } 210 211 public void inInvokeStmt(InvokeStmt s){ 212 parentOf.put(s,parentStack.peek()); 213 } 214 215 216 217 218 public void inThrowStmt(ThrowStmt s){ 219 parentOf.put(s,parentStack.peek()); 220 } 221 222 public void inDVariableDeclarationStmt(DVariableDeclarationStmt s){ 223 parentOf.put(s,parentStack.peek()); 224 } 225 226 227 public void inStmt(Stmt s){ 228 parentOf.put(s,parentStack.peek()); 229 } 230 231 232 238 public Object getParentOf(Object statementOrNode){ 239 return parentOf.get(statementOrNode); 240 } 241 } | Popular Tags |