core: fix 'if' processing in 'do/while' loop

This commit is contained in:
Skylot
2014-08-12 23:00:29 +04:00
parent 4935ae6da5
commit b657b0fb1f
2 changed files with 49 additions and 0 deletions
@@ -199,9 +199,11 @@ public class RegionMaker {
BlockNode thenBlock = condInfo.getThenBlock();
out = (thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock);
loopStart.remove(AType.LOOP);
loop.getEnd().add(AFlag.SKIP);
stack.addExit(loop.getEnd());
loopRegion.setBody(makeRegion(loopStart, stack));
loopStart.addAttr(AType.LOOP, loop);
loop.getEnd().remove(AFlag.SKIP);
} else {
out = condInfo.getElseBlock();
if (outerRegion != null
@@ -0,0 +1,47 @@
package jadx.tests.internal.loops;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestLoopConditionInvoke extends InternalJadxTest {
public static class TestCls {
private static final char STOP_CHAR = 0;
private int pos;
private boolean test(char lastChar) {
int startPos = pos;
char ch;
while ((ch = next()) != STOP_CHAR) {
if (ch == lastChar) {
return true;
}
}
pos = startPos;
return false;
}
private char next() {
return 0;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("do {"));
assertThat(code, containsOne("if (ch == '\\u0000') {"));
assertThat(code, containsOne("this.pos = startPos;"));
assertThat(code, containsOne("return false;"));
assertThat(code, containsOne("} while (ch != lastChar);"));
assertThat(code, containsOne("return true;"));
}
}