1 19 20 package soot.dava.toolkits.base.finders; 21 import soot.*; 22 23 import soot.dava.*; 24 import soot.util.*; 25 import java.util.*; 26 import soot.jimple.*; 27 import soot.dava.internal.asg.*; 28 import soot.dava.internal.SET.*; 29 import soot.dava.internal.AST.*; 30 import soot.dava.toolkits.base.misc.*; 31 32 public class IfFinder implements FactFinder 33 { 34 public IfFinder( Singletons.Global g ) {} 35 public static IfFinder v() { return G.v().soot_dava_toolkits_base_finders_IfFinder(); } 36 37 public void find( DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException 38 { 39 Dava.v().log( "IfFinder::find()"); 40 41 Iterator asgit = asg.iterator(); 42 while (asgit.hasNext()) { 43 AugmentedStmt as = (AugmentedStmt) asgit.next(); 44 45 Stmt s = as.get_Stmt(); 46 47 if (s instanceof IfStmt) { 48 IfStmt ifs = (IfStmt) s; 49 50 if (body.get_ConsumedConditions().contains( as)) 51 continue; 52 53 body.consume_Condition( as); 54 55 AugmentedStmt 56 succIf = asg.get_AugStmt( ifs.getTarget()), 57 succElse = (AugmentedStmt) as.bsuccs.get(0); 58 59 if (succIf == succElse) 60 succElse = (AugmentedStmt) as.bsuccs.get(1); 61 62 63 asg.calculate_Reachability( succIf, succElse, as); 64 asg.calculate_Reachability( succElse, succIf, as); 65 66 IterableSet 67 fullBody = new IterableSet(), 68 ifBody = find_Body( succIf, succElse), 69 elseBody = find_Body( succElse, succIf); 70 71 fullBody.add( as); 72 fullBody.addAll( ifBody); 73 fullBody.addAll( elseBody); 74 75 Iterator enlit = body.get_ExceptionFacts().iterator(); 76 while (enlit.hasNext()) { 77 ExceptionNode en = (ExceptionNode) enlit.next(); 78 IterableSet tryBody = en.get_TryBody(); 79 80 if (tryBody.contains( as)) { 81 Iterator fbit = fullBody.snapshotIterator(); 82 83 while (fbit.hasNext()) { 84 AugmentedStmt fbas = (AugmentedStmt) fbit.next(); 85 86 if (tryBody.contains( fbas) == false) { 87 fullBody.remove( fbas); 88 89 if (ifBody.contains( fbas)) 90 ifBody.remove( fbas); 91 92 if (elseBody.contains( fbas)) 93 elseBody.remove( fbas); 94 } 95 } 96 } 97 } 98 99 SET.nest( new SETIfElseNode( as, fullBody, ifBody, elseBody)); 100 } 101 } 102 } 103 104 private IterableSet find_Body( AugmentedStmt targetBranch, AugmentedStmt otherBranch) 105 { 106 IterableSet body = new IterableSet(); 107 108 if (targetBranch.get_Reachers().contains( otherBranch)) 109 return body; 110 111 LinkedList worklist = new LinkedList(); 112 worklist.addLast( targetBranch); 113 114 while (worklist.isEmpty() == false) { 115 AugmentedStmt as = (AugmentedStmt) worklist.removeFirst(); 116 117 if (body.contains( as) == false) { 118 body.add( as); 119 120 Iterator sit = as.csuccs.iterator(); 121 while (sit.hasNext()) { 122 AugmentedStmt sas = (AugmentedStmt) sit.next(); 123 124 if ((sas.get_Reachers().contains( otherBranch) == false) && (sas.get_Dominators().contains( targetBranch) == true)) 125 worklist.addLast( sas); 126 } 127 } 128 } 129 130 return body; 131 } 132 } 133 | Popular Tags |