Skip to content

Commit

Permalink
Merge pull request #2050 from MarcMil/extensiblerenaming
Browse files Browse the repository at this point in the history
Allow subclasses to customize renaming
  • Loading branch information
StevenArzt authored Feb 13, 2024
2 parents 29e7437 + 166b61e commit 4afc8cf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/main/java/soot/FastHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
public class FastHierarchy {

protected static final int USE_INTERVALS_BOUNDARY = 100;
private final boolean isDotNet = Options.v().src_prec() == Options.src_prec_dotnet;

protected Table<SootClass, NumberedString, SootMethod> typeToVtbl = HashBasedTable.create();

Expand Down Expand Up @@ -904,7 +905,7 @@ private SootMethod resolveMethod(final SootClass baseType, final SootClass decla
// determining the most specific super interface
HashSet<SootClass> interfaceIgnoreList = new HashSet<>();
for (SootClass concreteType = baseType; concreteType != null;) {
Queue<SootClass> worklist = new LinkedList<>(concreteType.getInterfaces());
Queue<SootClass> worklist = new ArrayDeque<>(concreteType.getInterfaces());
// we have to determine the "most specific super interface"
while (!worklist.isEmpty()) {
SootClass iFace = worklist.poll();
Expand Down Expand Up @@ -941,7 +942,7 @@ private SootMethod resolveMethod(final SootClass baseType, final SootClass decla
return candidate;
}

private boolean isHandleDefaultMethods() {
protected boolean isHandleDefaultMethods() {
int version = Options.v().java_version();
return version == 0 || version > 7;
}
Expand Down Expand Up @@ -985,7 +986,7 @@ private SootMethod getSignaturePolymorphicMethod(SootClass concreteType, String
returnType = method.getReturnType();
}
// if dotnet structs or generics
if (Options.v().src_prec() == Options.src_prec_dotnet) {
if (isDotNet) {
if (method.getParameterCount() == parameterTypes.size() && canStoreType(returnType, method.getReturnType())) {
boolean canStore = true;
for (int i = 0; i < method.getParameterCount(); i++) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/soot/ModuleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public final ModuleClassNameWrapper makeWrapper(String className) {
* @return true, if module mode is used
*/
public static boolean module_mode() {
return G.v().soot_ModuleUtil().isInModuleMode();
}

/**
* Check if Soot is run with module mode enabled.
*
* @return true, if module mode is used
*/
public boolean isInModuleMode() {
return !Options.v().soot_modulepath().isEmpty();
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/soot/RefType.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ protected RefType(String className) {
}

public static RefType v() {
if (ModuleUtil.module_mode()) {
return G.v().soot_ModuleRefType();
G g = G.v();
if (g.soot_ModuleUtil().isInModuleMode()) {
return g.soot_ModuleRefType();
} else {
return G.v().soot_RefType();
return g.soot_RefType();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/soot/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ public Scene(Singletons.Global g) {
}

public static Scene v() {
if (ModuleUtil.module_mode()) {
return G.v().soot_ModuleScene();
G g = G.v();
if (g.soot_ModuleUtil().isInModuleMode()) {
return g.soot_ModuleScene();
} else {
return G.v().soot_Scene();
return g.soot_Scene();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/soot/SootResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public CompilationUnit parse(InputStream is, String fileName) throws IOException
}

public static SootResolver v() {
if (ModuleUtil.module_mode()) {
return G.v().soot_SootModuleResolver();
G g = G.v();
if (g.soot_ModuleUtil().isInModuleMode()) {
return g.soot_SootModuleResolver();
} else {
return G.v().soot_SootResolver();
return g.soot_SootResolver();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/soot/SourceLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ public void invalidateCaches() {
}

public static SourceLocator v() {
return ModuleUtil.module_mode() ? G.v().soot_ModulePathSourceLocator() : G.v().soot_SourceLocator();
G g = G.v();
if (g.soot_ModuleUtil().isInModuleMode()) {
return g.soot_ModulePathSourceLocator();
} else {
return g.soot_SourceLocator();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static int digits(int n) {
return (n < 0) ? len - 1 : len;
}

private static String genName(String prefix, String type, int n, int digits) {
protected String genName(String prefix, String type, int n, int digits) {
return String.format("%s%s%0" + digits + "d", prefix, type, n);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ private int getFirstOccurance(Local l) {
locals.addAll(sortedLocals);
}

if (!PhaseOptions.getBoolean(options, "only-stack-locals")) {
if (changeLocalNames(options)) {
// Change the names to the standard forms now.

final BooleanType booleanType = BooleanType.v();
Expand Down Expand Up @@ -193,4 +193,8 @@ private int getFirstOccurance(Local l) {
}
}
}

protected boolean changeLocalNames(Map<String, String> options) {
return !PhaseOptions.getBoolean(options, "only-stack-locals");
}
}

0 comments on commit 4afc8cf

Please sign in to comment.