1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import java.util.*; 23 import soot.*; 24 import soot.jimple.*; 25 import soot.dava.*; 26 import soot.dava.internal.asg.*; 27 import soot.dava.internal.AST.*; 28 import soot.dava.toolkits.base.AST.analysis.*; 29 30 31 public class VoidReturnRemover extends DepthFirstAdapter{ 32 DavaBody davaBody; 33 34 public VoidReturnRemover(DavaBody davaBody){ 35 this.davaBody=davaBody; 36 } 37 38 public VoidReturnRemover(DavaBody davaBody,boolean verbose){ 39 super(verbose); 40 this.davaBody=davaBody; 41 } 42 43 public void caseASTMethodNode(ASTMethodNode node){ 44 45 SootMethod method = davaBody.getMethod(); 47 Type type = method.getReturnType(); 48 if(type instanceof VoidType){ 49 51 List subBodies = node.get_SubBodies(); 52 if(subBodies.size()==1){ 53 List subBody = (List)subBodies.get(0); 54 if(subBody.size()==0){ 56 return; 58 } 59 60 ASTNode last = (ASTNode)subBody.get(subBody.size()-1); 61 if(last instanceof ASTStatementSequenceNode){ 62 64 List stmts = ((ASTStatementSequenceNode)last).getStatements(); 65 if(stmts.size()==0){ 66 subBody.remove(subBody.size()-1); 68 return; 69 } 70 AugmentedStmt lastas = (AugmentedStmt)stmts.get(stmts.size()-1); 71 Stmt lastStmt = lastas.get_Stmt(); 72 if(lastStmt instanceof ReturnVoidStmt){ 73 74 stmts.remove(stmts.size()-1); 76 80 if(stmts.size()==0){ 81 subBody.remove(subBody.size()-1); 82 } 83 84 } 85 } 86 } 87 } 88 } 89 } | Popular Tags |