1 19 20 package soot.dava.internal.SET; 21 22 import soot.*; 23 import java.util.*; 24 import soot.util.*; 25 import soot.dava.*; 26 import soot.jimple.*; 27 import soot.dava.internal.asg.*; 28 import soot.dava.internal.AST.*; 29 import soot.dava.internal.javaRep.*; 30 import soot.dava.toolkits.base.misc.*; 31 import soot.dava.toolkits.base.finders.*; 32 33 public class SETTryNode extends SETNode 34 { 35 private ExceptionNode en; 36 private DavaBody davaBody; 37 private AugmentedStmtGraph asg; 38 private HashMap cb2clone; 39 private AugmentedStmt entgryStmt; 40 41 public SETTryNode( IterableSet body, ExceptionNode en, AugmentedStmtGraph asg, DavaBody davaBody) 42 { 43 super( body); 44 this.en = en; 45 this.asg = asg; 46 this.davaBody = davaBody; 47 48 add_SubBody( en.get_TryBody()); 49 50 cb2clone = new HashMap(); 51 52 Iterator it = en.get_CatchList().iterator(); 53 while (it.hasNext()) { 54 IterableSet catchBody = (IterableSet) it.next(); 55 IterableSet clone = (IterableSet) catchBody.clone(); 56 57 cb2clone.put( catchBody, clone); 58 add_SubBody( clone); 59 } 60 61 getEntryStmt: 62 { 63 entryStmt = null; 64 65 it = body.iterator(); 66 while (it.hasNext()) { 67 AugmentedStmt as = (AugmentedStmt) it.next(); 68 69 Iterator pit = as.cpreds.iterator(); 70 while (pit.hasNext()) 71 if (body.contains( pit.next()) == false) { 72 entryStmt = as; 73 break getEntryStmt; 74 } 75 } 76 } 77 } 78 79 public AugmentedStmt get_EntryStmt() 80 { 81 if (entryStmt != null) 82 return entryStmt; 83 else 84 return (AugmentedStmt) ((IterableSet) en.get_TryBody()).getFirst(); 85 86 } 88 89 public IterableSet get_NaturalExits() 90 { 91 IterableSet c = new IterableSet(); 92 93 Iterator it = subBodies.iterator(); 94 while (it.hasNext()) { 95 96 Iterator eit = ((SETNode) ((IterableSet) body2childChain.get( it.next())).getLast()).get_NaturalExits().iterator(); 97 while (eit.hasNext()) { 98 Object o = eit.next(); 99 100 if (c.contains( o) == false) 101 c.add( o); 102 } 103 } 104 105 return c; 106 } 107 108 public ASTNode emit_AST() 109 { 110 LinkedList catchList = new LinkedList(); 111 HashMap 112 exceptionMap = new HashMap(), 113 paramMap = new HashMap(); 114 115 Iterator it = en.get_CatchList().iterator(); 116 while (it.hasNext()) { 117 IterableSet originalCatchBody = (IterableSet) it.next(); 118 IterableSet catchBody = (IterableSet) cb2clone.get( originalCatchBody); 119 120 List astBody = emit_ASTBody( (IterableSet) body2childChain.get( catchBody)); 121 exceptionMap.put( astBody, en.get_Exception( originalCatchBody)); 122 catchList.addLast( astBody); 123 124 Iterator bit = catchBody.iterator(); 125 while (bit.hasNext()) { 126 Stmt s = ((AugmentedStmt) bit.next()).get_Stmt(); 127 128 if (s instanceof IdentityStmt) { 129 IdentityStmt ids = (IdentityStmt) s; 130 131 Value 132 rightOp = ids.getRightOp(), 133 leftOp = ids.getLeftOp(); 134 135 if (rightOp instanceof CaughtExceptionRef) { 136 paramMap.put( astBody, leftOp); 137 break; 138 } 139 } 140 } 141 } 142 143 return new ASTTryNode( get_Label(), emit_ASTBody( (IterableSet) body2childChain.get( en.get_TryBody())), catchList, exceptionMap, paramMap); 144 } 145 146 protected boolean resolve( SETNode parent) 147 { 148 Iterator sbit = parent.get_SubBodies().iterator(); 149 while (sbit.hasNext()) { 150 151 IterableSet subBody = (IterableSet) sbit.next(); 152 if (subBody.intersects( en.get_TryBody())) { 153 154 IterableSet childChain = (IterableSet) parent.get_Body2ChildChain().get( subBody); 155 Iterator ccit = childChain.iterator(); 156 while (ccit.hasNext()) { 157 158 SETNode child = (SETNode) ccit.next(); 159 IterableSet childBody = child.get_Body(); 160 161 if ((childBody.intersects( en.get_TryBody()) == false) || (childBody.isSubsetOf( en.get_TryBody()))) 162 continue; 163 164 if (childBody.isSupersetOf( get_Body())) 165 return true; 166 167 IterableSet newTryBody = childBody.intersection( en.get_TryBody()); 168 if (newTryBody.isStrictSubsetOf( en.get_TryBody())) { 169 en.splitOff_ExceptionNode( newTryBody, asg, davaBody.get_ExceptionFacts()); 170 171 Iterator enlit = davaBody.get_ExceptionFacts().iterator(); 172 while (enlit.hasNext()) 173 ((ExceptionNode) enlit.next()).refresh_CatchBody( ExceptionFinder.v()); 174 175 return false; 176 } 177 178 Iterator cit = en.get_CatchList().iterator(); 179 while (cit.hasNext()) { 180 181 Iterator bit = ((IterableSet) cb2clone.get( cit.next())).snapshotIterator(); 182 while (bit.hasNext()) { 183 AugmentedStmt as = (AugmentedStmt) bit.next(); 184 185 if (childBody.contains( as) == false) 186 remove_AugmentedStmt( as); 187 188 else if ((child instanceof SETControlFlowNode) && ((child instanceof SETUnconditionalWhileNode) == false)) { 189 SETControlFlowNode scfn = (SETControlFlowNode) child; 190 191 if ((scfn.get_CharacterizingStmt() == as) || 192 ((as.cpreds.size() == 1) && (as.get_Stmt() instanceof GotoStmt) && (scfn.get_CharacterizingStmt() == as.cpreds.get(0)))) 193 194 remove_AugmentedStmt( as); 195 } 196 } 197 } 198 199 return true; 200 } 201 } 202 } 203 return true; 204 } 205 } 206 207 208 | Popular Tags |