core: don't remove synthetic methods with some logic beside casts (#336)

This commit is contained in:
Skylot
2018-08-20 22:47:48 +03:00
parent eaaeb2c843
commit d7ce41e724
@@ -216,6 +216,12 @@ public class ClassModifier extends AbstractVisitor {
MethodInfo callMth = ((InvokeNode) insn).getCallMth();
MethodNode wrappedMth = mth.root().deepResolveMethod(callMth);
if (wrappedMth != null) {
// all args must be registers passed from method args (allow only casts insns)
for (InsnArg arg : insn.getArguments()) {
if (!registersAndCastsOnly(arg)) {
return false;
}
}
String alias = mth.getAlias();
if (!wrappedMth.getAlias().equals(alias) && wrappedMth.isVirtual()) {
wrappedMth.getMethodInfo().setAlias(alias);
@@ -226,6 +232,19 @@ public class ClassModifier extends AbstractVisitor {
return false;
}
private static boolean registersAndCastsOnly(InsnArg arg) {
if (arg.isRegister()) {
return true;
}
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
if (wrapInsn.getType() == InsnType.CHECK_CAST) {
return registersAndCastsOnly(wrapInsn.getArg(0));
}
}
return false;
}
private static boolean isMethodUnique(ClassNode cls, MethodNode mth) {
MethodInfo mi = mth.getMethodInfo();
for (MethodNode otherMth : cls.getMethods()) {