Skip to content

Commit d6b6158

Browse files
committed
extensibility improvements
1 parent be5ef55 commit d6b6158

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

src/main/java/soot/LambdaMetaFactory.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ public synchronized SootMethodRef makeLambdaHelper(List<? extends Value> bootstr
165165
final boolean readableClassnames = true;
166166
if (readableClassnames) {
167167
// class names cannot contain <>
168-
String implMethodName = implMethod.getMethodRef().name();
168+
String implMethodName = implMethod.getMethodRef().getName();
169169
String dummyName = "<init>".equals(implMethodName) ? "init" : implMethodName;
170170
// XXX: $ causes confusion in inner class inference; remove for now
171171
dummyName = dummyName.replaceAll("\\$", "_");
172172
className = enclosingClassnamePrefix + dummyName + "__" + uniqSupply();
173173
} else {
174174
className = "soot.dummy.lambda" + uniqSupply();
175175
}
176-
SootClass tclass = new SootClass(className);
176+
SootClass tclass = Scene.v().makeSootClass(className);
177177
tclass.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
178178
tclass.setSuperclass(Scene.v().getObjectType().getSootClass());
179179
tclass.addInterface(functionalInterfaceToImplement);
@@ -189,17 +189,17 @@ public synchronized SootMethodRef makeLambdaHelper(List<? extends Value> bootstr
189189
// It contains fields for all the captures in the lambda
190190
List<SootField> capFields = new ArrayList<SootField>(capTypes.size());
191191
for (int i = 0; i < capTypes.size(); i++) {
192-
SootField f = new SootField("cap" + i, capTypes.get(i), 0);
192+
SootField f = Scene.v().makeSootField("cap" + i, capTypes.get(i), 0);
193193
capFields.add(f);
194194
tclass.addField(f);
195195
}
196196

197197
// if the implMethod is a new private static in the enclosing class, make it public access so
198198
// it can be invoked from the thunk class
199199
if (MethodHandle.Kind.REF_INVOKE_STATIC.getValue() == implMethod.getKind()) {
200-
if (implMethod.getMethodRef().declaringClass().getName().equals(enclosingClassname)) {
201-
SootMethod method
202-
= implMethod.getMethodRef().declaringClass().getMethod(implMethod.getMethodRef().getSubSignature());
200+
SootClass declClass = implMethod.getMethodRef().getDeclaringClass();
201+
if (declClass.getName().equals(enclosingClassname)) {
202+
SootMethod method = declClass.getMethod(implMethod.getMethodRef().getSubSignature());
203203
int modifiers = method.getModifiers() & ~Modifier.PRIVATE;
204204
modifiers = modifiers | Modifier.PUBLIC;
205205
method.setModifiers(modifiers);
@@ -209,13 +209,13 @@ public synchronized SootMethodRef makeLambdaHelper(List<? extends Value> bootstr
209209
MethodSource ms = new ThunkMethodSource(capFields, samMethodType, implMethod, instantiatedMethodType);
210210

211211
// Bootstrap method creates a new instance of this class
212-
SootMethod tboot = new SootMethod("bootstrap$", capTypes, functionalInterfaceToImplement.getType(),
212+
SootMethod tboot = Scene.v().makeSootMethod("bootstrap$", capTypes, functionalInterfaceToImplement.getType(),
213213
Modifier.PUBLIC | Modifier.STATIC);
214214
tclass.addMethod(tboot);
215215
tboot.setSource(ms);
216216

217217
// Constructor just copies the captures
218-
SootMethod tctor = new SootMethod("<init>", capTypes, VoidType.v(), Modifier.PUBLIC);
218+
SootMethod tctor = Scene.v().makeSootMethod("<init>", capTypes, VoidType.v(), Modifier.PUBLIC);
219219
tclass.addMethod(tctor);
220220
tctor.setSource(ms);
221221

@@ -251,7 +251,8 @@ public synchronized SootMethodRef makeLambdaHelper(List<? extends Value> bootstr
251251
private void addDispatch(String name, SootClass tclass, MethodType implMethodType, MethodType instantiatedMethodType,
252252
List<SootField> capFields, MethodHandle implMethod) {
253253
ThunkMethodSource ms = new ThunkMethodSource(capFields, implMethodType, implMethod, instantiatedMethodType);
254-
SootMethod m = new SootMethod(name, implMethodType.getParameterTypes(), implMethodType.getReturnType(), Modifier.PUBLIC);
254+
SootMethod m = Scene.v().makeSootMethod(name, implMethodType.getParameterTypes(), implMethodType.getReturnType(),
255+
Modifier.PUBLIC);
255256
tclass.addMethod(m);
256257
m.setSource(ms);
257258
}
@@ -294,10 +295,6 @@ public Wrapper() {
294295

295296
}
296297

297-
private boolean isWrapper(Type t) {
298-
return wrapperTypes.containsKey(t);
299-
}
300-
301298
}
302299

303300
private class ThunkMethodSource implements MethodSource {
@@ -463,7 +460,7 @@ private void getInvokeBody(SootClass tclass, JimpleBody jb) {
463460
}
464461
Iterator<Local> iplItr = instParamLocals.iterator();
465462
if (capFields.size() == 0 && iplItr.hasNext() && needsReceiver) {
466-
RefType receiverType = implMethod.getMethodRef().declaringClass().getType();
463+
RefType receiverType = implMethod.getMethodRef().getDeclaringClass().getType();
467464
Local l = adapt(iplItr.next(), receiverType, jb, us, lc);
468465
args.add(l);
469466
}
@@ -476,7 +473,7 @@ private void getInvokeBody(SootClass tclass, JimpleBody jb) {
476473
while (iplItr.hasNext()) {
477474
Local pl = iplItr.next();
478475

479-
Type to = implMethod.getMethodRef().parameterType(j);
476+
Type to = implMethod.getMethodRef().getParameterType(j);
480477

481478
Local l = adapt(pl, to, jb, us, lc);
482479
args.add(l);
@@ -648,7 +645,7 @@ private Local wideningPrimitiveConversion(Local fromLocal, Type to, JimpleBody j
648645
private void invokeImplMethod(JimpleBody jb, PatchingChain<Unit> us, LocalGenerator lc, List<Local> args) {
649646
Value value = _invokeImplMethod(jb, us, lc, args);
650647

651-
if (value instanceof InvokeExpr && soot.VoidType.v().equals(implMethod.getMethodRef().returnType())) {
648+
if (value instanceof InvokeExpr && soot.VoidType.v().equals(implMethod.getMethodRef().getReturnType())) {
652649
// implementation method is void
653650
us.add(Jimple.v().newInvokeStmt(value));
654651
us.add(Jimple.v().newReturnVoidStmt());
@@ -702,7 +699,7 @@ private Value _invokeImplMethod(JimpleBody jb, PatchingChain<Unit> us, LocalGene
702699
return Jimple.v().newVirtualInvokeExpr(args.get(0), methodRef, rest(args));
703700
}
704701
case REF_INVOKE_CONSTRUCTOR:
705-
RefType type = methodRef.declaringClass().getType();
702+
RefType type = methodRef.getDeclaringClass().getType();
706703
NewExpr newRef = Jimple.v().newNewExpr(type);
707704
Local newLocal = lc.generateLocal(type);
708705
us.add(Jimple.v().newAssignStmt(newLocal, newRef));

src/main/java/soot/asm/AsmClassSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
*
3838
* @author Aaloan Miftah
3939
*/
40-
class AsmClassSource extends ClassSource {
40+
public class AsmClassSource extends ClassSource {
4141

42-
private FoundFile foundFile;
42+
protected FoundFile foundFile;
4343

4444
/**
4545
* Constructs a new ASM class source.
@@ -49,7 +49,7 @@ class AsmClassSource extends ClassSource {
4949
* @param data
5050
* stream containing data for class.
5151
*/
52-
AsmClassSource(String cls, FoundFile foundFile) {
52+
protected AsmClassSource(String cls, FoundFile foundFile) {
5353
super(cls);
5454
if (foundFile == null) {
5555
throw new IllegalStateException("Error: The FoundFile must not be null.");

src/main/java/soot/asm/SootClassBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@
5959
* @author Aaloan Miftah
6060
*/
6161
@SuppressWarnings({ "unchecked", "rawtypes" })
62-
class SootClassBuilder extends ClassVisitor {
62+
public class SootClassBuilder extends ClassVisitor {
6363

64-
private TagBuilder tb;
65-
private final SootClass klass;
66-
final Set<soot.Type> deps;
64+
protected TagBuilder tb;
65+
protected final SootClass klass;
66+
protected final Set<soot.Type> deps;
6767

6868
/**
6969
* Constructs a new Soot class builder.
7070
*
7171
* @param klass
7272
* Soot class to build.
7373
*/
74-
SootClassBuilder(SootClass klass) {
74+
protected SootClassBuilder(SootClass klass) {
7575
super(Opcodes.ASM5);
7676
this.klass = klass;
7777
this.deps = new HashSet();

src/main/java/soot/javaToJimple/IInitialResolver.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ public class Dependencies {
3939
public final Set<Type> typesToHierarchy, typesToSignature;
4040

4141
public Dependencies() {
42-
typesToHierarchy = new HashSet<Type>();
43-
typesToSignature = new HashSet<Type>();
42+
typesToHierarchy = new HashSet<>();
43+
typesToSignature = new HashSet<>();
44+
}
45+
46+
public Dependencies(Set<Type> typesToHierarchy, Set<Type> typesToSignature) {
47+
this.typesToHierarchy = typesToHierarchy == null ? new HashSet<>() : typesToHierarchy;
48+
this.typesToSignature = typesToSignature == null ? new HashSet<>() : typesToSignature;
4449
}
4550
}
4651

0 commit comments

Comments
 (0)