Skip to content

Commit 4afc8cf

Browse files
authored
Merge pull request #2050 from MarcMil/extensiblerenaming
Allow subclasses to customize renaming
2 parents 29e7437 + 166b61e commit 4afc8cf

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

src/main/java/soot/FastHierarchy.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
public class FastHierarchy {
5959

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

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

@@ -904,7 +905,7 @@ private SootMethod resolveMethod(final SootClass baseType, final SootClass decla
904905
// determining the most specific super interface
905906
HashSet<SootClass> interfaceIgnoreList = new HashSet<>();
906907
for (SootClass concreteType = baseType; concreteType != null;) {
907-
Queue<SootClass> worklist = new LinkedList<>(concreteType.getInterfaces());
908+
Queue<SootClass> worklist = new ArrayDeque<>(concreteType.getInterfaces());
908909
// we have to determine the "most specific super interface"
909910
while (!worklist.isEmpty()) {
910911
SootClass iFace = worklist.poll();
@@ -941,7 +942,7 @@ private SootMethod resolveMethod(final SootClass baseType, final SootClass decla
941942
return candidate;
942943
}
943944

944-
private boolean isHandleDefaultMethods() {
945+
protected boolean isHandleDefaultMethods() {
945946
int version = Options.v().java_version();
946947
return version == 0 || version > 7;
947948
}
@@ -985,7 +986,7 @@ private SootMethod getSignaturePolymorphicMethod(SootClass concreteType, String
985986
returnType = method.getReturnType();
986987
}
987988
// if dotnet structs or generics
988-
if (Options.v().src_prec() == Options.src_prec_dotnet) {
989+
if (isDotNet) {
989990
if (method.getParameterCount() == parameterTypes.size() && canStoreType(returnType, method.getReturnType())) {
990991
boolean canStore = true;
991992
for (int i = 0; i < method.getParameterCount(); i++) {

src/main/java/soot/ModuleUtil.java

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public final ModuleClassNameWrapper makeWrapper(String className) {
9595
* @return true, if module mode is used
9696
*/
9797
public static boolean module_mode() {
98+
return G.v().soot_ModuleUtil().isInModuleMode();
99+
}
100+
101+
/**
102+
* Check if Soot is run with module mode enabled.
103+
*
104+
* @return true, if module mode is used
105+
*/
106+
public boolean isInModuleMode() {
98107
return !Options.v().soot_modulepath().isEmpty();
99108
}
100109

src/main/java/soot/RefType.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ protected RefType(String className) {
6464
}
6565

6666
public static RefType v() {
67-
if (ModuleUtil.module_mode()) {
68-
return G.v().soot_ModuleRefType();
67+
G g = G.v();
68+
if (g.soot_ModuleUtil().isInModuleMode()) {
69+
return g.soot_ModuleRefType();
6970
} else {
70-
return G.v().soot_RefType();
71+
return g.soot_RefType();
7172
}
7273
}
7374

src/main/java/soot/Scene.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ public Scene(Singletons.Global g) {
149149
}
150150

151151
public static Scene v() {
152-
if (ModuleUtil.module_mode()) {
153-
return G.v().soot_ModuleScene();
152+
G g = G.v();
153+
if (g.soot_ModuleUtil().isInModuleMode()) {
154+
return g.soot_ModuleScene();
154155
} else {
155-
return G.v().soot_Scene();
156+
return g.soot_Scene();
156157
}
157158
}
158159

src/main/java/soot/SootResolver.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ public CompilationUnit parse(InputStream is, String fileName) throws IOException
101101
}
102102

103103
public static SootResolver v() {
104-
if (ModuleUtil.module_mode()) {
105-
return G.v().soot_SootModuleResolver();
104+
G g = G.v();
105+
if (g.soot_ModuleUtil().isInModuleMode()) {
106+
return g.soot_SootModuleResolver();
106107
} else {
107-
return G.v().soot_SootResolver();
108+
return g.soot_SootResolver();
108109
}
109110
}
110111

src/main/java/soot/SourceLocator.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ public void invalidateCaches() {
167167
}
168168

169169
public static SourceLocator v() {
170-
return ModuleUtil.module_mode() ? G.v().soot_ModulePathSourceLocator() : G.v().soot_SourceLocator();
170+
G g = G.v();
171+
if (g.soot_ModuleUtil().isInModuleMode()) {
172+
return g.soot_ModulePathSourceLocator();
173+
} else {
174+
return g.soot_SourceLocator();
175+
}
171176
}
172177

173178
/**

src/main/java/soot/jimple/toolkits/scalar/LocalNameStandardizer.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static int digits(int n) {
6666
return (n < 0) ? len - 1 : len;
6767
}
6868

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

@@ -135,7 +135,7 @@ private int getFirstOccurance(Local l) {
135135
locals.addAll(sortedLocals);
136136
}
137137

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

141141
final BooleanType booleanType = BooleanType.v();
@@ -193,4 +193,8 @@ private int getFirstOccurance(Local l) {
193193
}
194194
}
195195
}
196+
197+
protected boolean changeLocalNames(Map<String, String> options) {
198+
return !PhaseOptions.getBoolean(options, "only-stack-locals");
199+
}
196200
}

0 commit comments

Comments
 (0)