1 19 20 package soot.dava; 21 22 23 import soot.Body; 24 import soot.G; 25 import soot.Modifier; 26 import soot.Singletons; 27 import soot.SootClass; 28 import soot.SootMethod; 29 import soot.dava.internal.AST.ASTMethodNode; 30 import soot.dava.internal.AST.ASTNode; 31 import soot.dava.internal.AST.ASTStatementSequenceNode; 32 import soot.util.Chain; 33 34 35 56 57 58 59 public class DavaStaticBlockCleaner { 60 SootClass sootClass; 61 62 63 public DavaStaticBlockCleaner(Singletons.Global g) { 64 } 65 66 public static DavaStaticBlockCleaner v() { 67 return G.v().soot_dava_DavaStaticBlockCleaner(); 68 } 69 70 71 public void staticBlockInlining(SootClass sootClass){ 73 this.sootClass=sootClass; 74 if(!sootClass.declaresMethod("void <clinit>()")){ 77 return; 79 } 80 81 SootMethod clinit = sootClass.getMethod("void <clinit>()"); 82 84 if (!clinit.hasActiveBody()) 86 throw new RuntimeException ("method "+ clinit.getName()+ " has no active body!"); 87 88 89 Body clinitBody = clinit.getActiveBody(); 90 Chain units = ((DavaBody) clinitBody).getUnits(); 91 92 if (units.size() != 1) { 93 throw new RuntimeException ("DavaBody AST doesn't have single root."); 94 } 95 96 ASTNode AST = (ASTNode) units.getFirst(); 97 if(! (AST instanceof ASTMethodNode)) 98 throw new RuntimeException ("Starting node of DavaBody AST is not an ASTMethodNode"); 99 100 AST.apply(new MethodCallFinder(this)); 102 } 103 104 105 106 107 113 public ASTMethodNode inline(SootMethod maybeInline){ 114 116 if(sootClass !=null){ 117 if(sootClass.declaresMethod(maybeInline.getSubSignature())){ 119 122 if (Modifier.isStatic(maybeInline.getModifiers())){ 123 126 if (!maybeInline.hasActiveBody()) 128 throw new RuntimeException ("method "+ maybeInline.getName()+ " has no active body!"); 129 130 131 Body bod = maybeInline.getActiveBody(); 132 133 Chain units = ((DavaBody) bod).getUnits(); 134 135 if (units.size() != 1) { 136 throw new RuntimeException ("DavaBody AST doesn't have single root."); 137 } 138 139 ASTNode ASTtemp = (ASTNode) units.getFirst(); 140 if(! (ASTtemp instanceof ASTMethodNode)) 141 throw new RuntimeException ("Starting node of DavaBody AST is not an ASTMethodNode"); 142 143 ASTMethodNode toReturn = (ASTMethodNode)ASTtemp; 145 146 ASTStatementSequenceNode declarations = toReturn.getDeclarations(); 147 if(declarations.getStatements().size() == 0){ 148 return toReturn; 151 } 152 } 153 } 154 } 155 return null; } 157 158 } | Popular Tags |