Skip to content

Commit b004de9

Browse files
author
Jennifer Lhoták
committedJun 20, 2004
- fixed deeply nested local class problem with final locals
- fixed verify problems for ushr, shr and shl - improved speed
1 parent 246ab05 commit b004de9

File tree

4 files changed

+85
-22
lines changed

4 files changed

+85
-22
lines changed
 

‎src/soot/javaToJimple/ClassDeclFinder.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33

44
public class ClassDeclFinder extends polyglot.visit.NodeVisitor {
55

6-
private polyglot.types.ClassType typeToFind;
7-
private polyglot.ast.ClassDecl declFound;
6+
//private polyglot.types.ClassType typeToFind;
7+
private ArrayList typesToFind;
8+
private ArrayList declsFound;
89

910

10-
public void typeToFind(polyglot.types.ClassType type){
11-
typeToFind = type;
11+
public void typesToFind(ArrayList types){
12+
typesToFind = types;
1213
}
1314

14-
public polyglot.ast.ClassDecl declFound(){
15-
return declFound;
15+
public ArrayList declsFound(){
16+
return declsFound;
1617
}
1718

1819

1920
public ClassDeclFinder(){
20-
declFound = null;
21+
declsFound = new ArrayList();
2122
}
2223

2324
public polyglot.visit.NodeVisitor enter(polyglot.ast.Node parent, polyglot.ast.Node n) {
2425

2526
if (n instanceof polyglot.ast.ClassDecl) {
26-
if (((polyglot.ast.ClassDecl)n).type().equals(typeToFind)){
27-
declFound = (polyglot.ast.ClassDecl)n;
27+
if (typesToFind.contains(((polyglot.ast.ClassDecl)n).type())){
28+
declsFound.add((polyglot.ast.ClassDecl)n);
2829
}
2930
}
3031
return enter(n);

‎src/soot/javaToJimple/InitialResolver.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,30 @@ private void resolveClassType(polyglot.types.ClassType classType){
161161

162162
sootClassType = Util.getSootType(classType);
163163

164+
if (classTypesFound == null){
165+
classTypesFound = new ArrayList();
166+
}
167+
classTypesFound.add(classType);
164168
// saves classnames mapped to AST
165-
ClassDeclFinder finder = new ClassDeclFinder();
169+
/*ClassDeclFinder finder = new ClassDeclFinder();
166170
finder.typeToFind(classType);
167171
astNode.visit(finder);
168172
if (finder.declFound() != null){
169173
addNameToAST(((soot.RefType)sootClassType).getClassName());
170-
}
174+
}*/
171175
SootResolver.v().assertResolvedClassForType(sootClassType);
172176
}
177+
178+
private ArrayList classTypesFound;
179+
private void makeASTMap(){
180+
ClassDeclFinder finder = new ClassDeclFinder();
181+
finder.typesToFind(classTypesFound);
182+
astNode.visit(finder);
183+
Iterator it = finder.declsFound().iterator();
184+
while (it.hasNext()){
185+
addNameToAST(Util.getSootType(((polyglot.ast.ClassDecl)it.next()).type()).toString());
186+
}
187+
}
173188

174189
/**
175190
* add name to AST to map - used mostly for inner and non public
@@ -192,6 +207,7 @@ public void resolveFromJavaFile(soot.SootClass sc) {
192207
// get types and resolve them in the Scene
193208
resolveTypes();
194209

210+
makeASTMap();
195211
// determine is ".class" literal is used
196212
ClassLiteralChecker classLitChecker = new ClassLiteralChecker();
197213
astNode.visit(classLitChecker);

‎src/soot/javaToJimple/JimpleBodyBuilder.java

+39-7
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,12 @@ private void createFormal(polyglot.ast.Formal formal, int counter){
326326
* Literal Creation
327327
*/
328328
private soot.Value createLiteral(polyglot.ast.Lit lit) {
329+
//System.out.println("lit: "+lit+" type: "+lit.getClass());
329330
if (lit instanceof polyglot.ast.IntLit) {
330331
polyglot.ast.IntLit intLit = (polyglot.ast.IntLit)lit;
331332
long litValue = intLit.value();
332333
if (intLit.kind() == polyglot.ast.IntLit.INT) {
333-
return soot.jimple.IntConstant.v((int)litValue);
334+
return soot.jimple.IntConstant.v((int)litValue);
334335
}
335336
else {
336337
return soot.jimple.LongConstant.v(litValue);
@@ -356,7 +357,7 @@ else if (lit instanceof polyglot.ast.FloatLit) {
356357
}
357358
else if (lit instanceof polyglot.ast.CharLit) {
358359
char litValue = ((polyglot.ast.CharLit)lit).value();
359-
return soot.jimple.IntConstant.v((int)litValue);
360+
return soot.jimple.IntConstant.v(litValue);
360361
}
361362
else if (lit instanceof polyglot.ast.BooleanLit) {
362363
boolean litValue = ((polyglot.ast.BooleanLit)lit).value();
@@ -2119,13 +2120,40 @@ else if (operator == polyglot.ast.Binary.DIV){
21192120
rValue = soot.jimple.Jimple.v().newDivExpr(lVal, rVal);
21202121
}
21212122
else if (operator == polyglot.ast.Binary.SHR){
2122-
rValue = soot.jimple.Jimple.v().newShrExpr(lVal, rVal);
2123+
if (rVal.getType().equals(soot.LongType.v())){
2124+
soot.Local intVal = lg.generateLocal(soot.IntType.v());
2125+
soot.jimple.CastExpr castExpr = soot.jimple.Jimple.v().newCastExpr(rVal, soot.IntType.v());
2126+
soot.jimple.AssignStmt assignStmt = soot.jimple.Jimple.v().newAssignStmt(intVal, castExpr);
2127+
body.getUnits().add(assignStmt);
2128+
rValue = soot.jimple.Jimple.v().newUshrExpr(lVal, intVal);
2129+
}
2130+
else {
2131+
rValue = soot.jimple.Jimple.v().newShrExpr(lVal, rVal);
2132+
}
21232133
}
21242134
else if (operator == polyglot.ast.Binary.USHR){
2125-
rValue = soot.jimple.Jimple.v().newUshrExpr(lVal, rVal);
2135+
if (rVal.getType().equals(soot.LongType.v())){
2136+
soot.Local intVal = lg.generateLocal(soot.IntType.v());
2137+
soot.jimple.CastExpr castExpr = soot.jimple.Jimple.v().newCastExpr(rVal, soot.IntType.v());
2138+
soot.jimple.AssignStmt assignStmt = soot.jimple.Jimple.v().newAssignStmt(intVal, castExpr);
2139+
body.getUnits().add(assignStmt);
2140+
rValue = soot.jimple.Jimple.v().newUshrExpr(lVal, intVal);
2141+
}
2142+
else {
2143+
rValue = soot.jimple.Jimple.v().newUshrExpr(lVal, rVal);
2144+
}
21262145
}
21272146
else if (operator == polyglot.ast.Binary.SHL){
2128-
rValue = soot.jimple.Jimple.v().newShlExpr(lVal, rVal);
2147+
if (rVal.getType().equals(soot.LongType.v())){
2148+
soot.Local intVal = lg.generateLocal(soot.IntType.v());
2149+
soot.jimple.CastExpr castExpr = soot.jimple.Jimple.v().newCastExpr(rVal, soot.IntType.v());
2150+
soot.jimple.AssignStmt assignStmt = soot.jimple.Jimple.v().newAssignStmt(intVal, castExpr);
2151+
body.getUnits().add(assignStmt);
2152+
rValue = soot.jimple.Jimple.v().newUshrExpr(lVal, intVal);
2153+
}
2154+
else {
2155+
rValue = soot.jimple.Jimple.v().newShlExpr(lVal, rVal);
2156+
}
21292157
}
21302158
else if (operator == polyglot.ast.Binary.BIT_AND){
21312159
rValue = soot.jimple.Jimple.v().newAndExpr(lVal, rVal);
@@ -2814,7 +2842,8 @@ else if (type instanceof soot.LongType) {
28142842
* Cast Expression Creation
28152843
*/
28162844
private soot.Value getCastLocal(polyglot.ast.Cast castExpr){
2817-
2845+
2846+
//System.out.println("castExpr: "+castExpr);
28182847

28192848
// if its already the right type
28202849
if (castExpr.expr().type().equals(castExpr.type())) {
@@ -2831,10 +2860,13 @@ private soot.Value getCastLocal(polyglot.ast.Cast castExpr){
28312860
}
28322861
soot.Type type = Util.getSootType(castExpr.type());
28332862

2863+
/*if (type.equals(soot.CharType.v())) {
2864+
return val;
2865+
}*/
28342866
soot.jimple.CastExpr cast = soot.jimple.Jimple.v().newCastExpr(val, type);
28352867
Util.addLnPosTags(cast.getOpBox(), castExpr.position().line(), castExpr.position().line(), castExpr.position().column() + castExpr.toString().indexOf(')') , castExpr.position().endColumn());
28362868
soot.Local retLocal = lg.generateLocal(cast.getCastType());
2837-
2869+
//System.out.println("cast ret type: "+retLocal.getType());
28382870
soot.jimple.Stmt castAssign = soot.jimple.Jimple.v().newAssignStmt(retLocal, cast);
28392871
body.getUnits().add(castAssign);
28402872
Util.addLnPosTags(castAssign, castExpr.position());

‎src/soot/javaToJimple/MethodFinalsChecker.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public MethodFinalsChecker(){
4747
inners = new ArrayList();
4848
}
4949

50+
public polyglot.ast.Node override(polyglot.ast.Node parent, polyglot.ast.Node n){
51+
if (n instanceof polyglot.ast.LocalClassDecl){
52+
inners.add(new polyglot.util.IdentityKey(((polyglot.ast.LocalClassDecl)n).decl().type()));
53+
return n;
54+
}
55+
else if (n instanceof polyglot.ast.New) {
56+
if (((polyglot.ast.New)n).anonType() != null) {
57+
inners.add(new polyglot.util.IdentityKey(((polyglot.ast.New)n).anonType()));
58+
return n;
59+
}
60+
}
61+
return null;
62+
}
63+
5064
public polyglot.visit.NodeVisitor enter(polyglot.ast.Node parent, polyglot.ast.Node n) {
5165

5266

@@ -70,19 +84,19 @@ public polyglot.visit.NodeVisitor enter(polyglot.ast.Node parent, polyglot.ast.N
7084
}
7185
}
7286
}
73-
if (n instanceof polyglot.ast.New) {
87+
/*if (n instanceof polyglot.ast.New) {
7488
//System.out.println("in mfc and parent is: "+parent+" parent type: "+parent.getClass());
7589
//System.out.println("in mfc and n is: "+n);
7690
//System.out.println("current outer class name is: "+currentSootClass);
7791
if (((polyglot.ast.New)n).anonType() != null){
7892
//inners.add(n);
7993
inners.add(new polyglot.util.IdentityKey(((polyglot.ast.New)n).anonType()));
8094
}
81-
}
95+
}*/
8296

83-
if (n instanceof polyglot.ast.LocalClassDecl){
97+
/*if (n instanceof polyglot.ast.LocalClassDecl){
8498
inners.add(new polyglot.util.IdentityKey(((polyglot.ast.LocalClassDecl)n).decl().type()));
85-
}
99+
}*/
86100
/* polyglot.types.ClassType outerType = ((polyglot.ast.New)n).anonType().outer();
87101
while (outerType.isNested()) {
88102
outerType = outerType.outer();

0 commit comments

Comments
 (0)
Please sign in to comment.