1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import soot.*; 23 import java.util.*; 24 import soot.jimple.*; 25 import soot.dava.internal.asg.*; 26 import soot.dava.internal.SET.*; 27 import soot.dava.internal.AST.*; 28 import soot.dava.internal.javaRep.*; 29 30 public class UselessLabelFinder{ 31 public UselessLabelFinder( Singletons.Global g ) {} 32 public static UselessLabelFinder v() { return G.v().soot_dava_toolkits_base_AST_transformations_UselessLabelFinder(); } 33 34 35 public void findAndKill(ASTNode node){ 37 if(!(node instanceof ASTLabeledNode)){ 38 return; 39 } 40 String label = ((ASTLabeledNode)node).get_Label().toString(); 41 List subBodies = (List)node.get_SubBodies(); 42 Iterator it = subBodies.iterator(); 43 while(it.hasNext()){ 44 if(node instanceof ASTTryNode){ 45 ASTTryNode.container subBody = (ASTTryNode.container)it.next(); 46 if(checkForBreak((List)subBody.o,label)){ 47 } 49 else{ 50 ((ASTLabeledNode)node).set_Label(new SETNodeLabel()); 51 break; 53 } 54 } 55 else{ if(checkForBreak((List)it.next(),label)){ 57 } 59 else{ 60 ((ASTLabeledNode)node).set_Label(new SETNodeLabel()); 61 break; 63 } 64 } 65 } 66 } 67 68 71 private boolean checkForBreak(List ASTNodeBody,String outerLabel){ 72 Iterator it = ASTNodeBody.iterator(); 73 while(it.hasNext()){ 74 ASTNode temp = (ASTNode)it.next(); 75 if(temp instanceof ASTStatementSequenceNode){ 77 ASTStatementSequenceNode stmtSeq = (ASTStatementSequenceNode)temp; 78 List statements = stmtSeq.getStatements(); 79 Iterator stmtIt = statements.iterator(); 80 while(stmtIt.hasNext()){ 81 AugmentedStmt as = (AugmentedStmt)stmtIt.next(); 82 Stmt s = as.get_Stmt(); 83 String labelBroken = breaksLabel(s); 84 if(labelBroken != null && outerLabel!=null){ if(labelBroken.compareTo(outerLabel)==0){ 86 return true; 88 } 89 } 90 } 91 } else{ 93 List subBodies=(List)temp.get_SubBodies(); 96 Iterator subIt = subBodies.iterator(); 97 while(subIt.hasNext()){ 98 if(temp instanceof ASTTryNode){ 99 ASTTryNode.container subBody = (ASTTryNode.container) subIt.next(); 100 if(checkForBreak((List)subBody.o,outerLabel)){ 101 return true; 103 } 104 } 105 else{ 106 if(checkForBreak((List)subIt.next(),outerLabel)){ 107 return true; 109 } 110 } 111 } 112 } 113 } 114 115 return false; 116 } 117 118 119 124 private String breaksLabel(Stmt stmt){ 125 if(!(stmt instanceof DAbruptStmt)){ 126 return null; 128 } 129 DAbruptStmt abStmt = (DAbruptStmt)stmt; 130 if(abStmt.is_Break() || abStmt.is_Continue()){ 131 SETNodeLabel label = abStmt.getLabel(); 132 return label.toString(); 133 } 134 else 135 return null; 136 } 137 } | Popular Tags |