提交 bae7f1b0 编写于 作者: A Ahmed Ashour 提交者: skylot

fix: field increment (PR #550)

上级 e6e8f636
......@@ -49,12 +49,36 @@ public class SimplifyVisitor extends AbstractVisitor {
for (int i = 0; i < list.size(); i++) {
InsnNode modInsn = simplifyInsn(mth, list.get(i));
if (modInsn != null) {
if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) {
InsnNode mergedNode = simplifyOneArgConsecutive(
list.get(i - 1), list.get(i), (ArithNode) modInsn);
if (mergedNode != null) {
list.remove(i - 1);
modInsn = mergedNode;
i--;
}
}
list.set(i, modInsn);
}
}
}
}
private static InsnNode simplifyOneArgConsecutive(InsnNode insn1, InsnNode insn2, ArithNode modInsn) {
if (insn1.getType() == InsnType.IGET
&& insn2.getType() == InsnType.IPUT
&& insn1.getResult().getSVar().getUseCount() == 2
&& insn2.getArg(1).equals(insn1.getResult())) {
FieldInfo field = (FieldInfo) ((IndexInsnNode) insn2).getIndex();
FieldArg fArg = new FieldArg(field, new InsnWrapArg(insn1));
return new ArithNode(modInsn.getOp(), fArg, modInsn.getArg(1));
}
return null;
}
private static InsnNode simplifyInsn(MethodNode mth, InsnNode insn) {
if (insn.contains(AFlag.DONT_GENERATE)) {
return null;
......
......@@ -2,7 +2,6 @@ package jadx.tests.integration.arith;
import org.junit.jupiter.api.Test;
import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
......@@ -33,15 +32,6 @@ public class TestFieldIncrement2 extends IntegrationTest {
String code = cls.getCode().toString();
assertThat(code, containsString("this.a.f += n;"));
assertThat(code, containsString("a2.f *= n;"));
}
@Test
@NotYetImplemented
public void test2() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString("this.a.f *= n;"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册