use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class IfRegionVisitor method simplifyIfCondition.
private static void simplifyIfCondition(IfRegion ifRegion) {
if (ifRegion.simplifyCondition()) {
IfCondition condition = ifRegion.getCondition();
if (condition.getMode() == Mode.NOT) {
invertIfRegion(ifRegion);
}
}
IContainer elseRegion = ifRegion.getElseRegion();
if (elseRegion == null || RegionUtils.isEmpty(elseRegion)) {
return;
}
boolean thenIsEmpty = RegionUtils.isEmpty(ifRegion.getThenRegion());
if (thenIsEmpty || hasSimpleReturnBlock(ifRegion.getThenRegion())) {
invertIfRegion(ifRegion);
}
if (!thenIsEmpty) {
// move 'if' from then to make 'else if' chain
if (isIfRegion(ifRegion.getThenRegion()) && !isIfRegion(elseRegion)) {
invertIfRegion(ifRegion);
}
}
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class IfMakerHelper method makeIfInfo.
static IfInfo makeIfInfo(BlockNode ifBlock) {
IfNode ifNode = (IfNode) ifBlock.getInstructions().get(0);
IfCondition condition = IfCondition.fromIfNode(ifNode);
IfInfo info = new IfInfo(condition, ifNode.getThenBlock(), ifNode.getElseBlock());
info.setIfBlock(ifBlock);
info.getMergedBlocks().add(ifBlock);
return info;
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testSimplify.
@Test
public void testSimplify() {
// '!(!a || !b)' => 'a && b'
IfCondition a = makeSimpleCondition();
IfCondition b = makeSimpleCondition();
IfCondition c = not(merge(Mode.OR, not(a), not(b)));
IfCondition simp = simplify(c);
assertEquals(simp.getMode(), Mode.AND);
assertEquals(simp.first(), a);
assertEquals(simp.second(), b);
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testSimplifyNot.
@Test
public void testSimplifyNot() {
// !(!a) => a
IfCondition a = not(not(makeSimpleCondition()));
assertEquals(simplify(a), a);
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testSimplify2.
@Test
public void testSimplify2() {
// '(!a || !b) && !c' => '!((a && b) || c)'
IfCondition a = makeSimpleCondition();
IfCondition b = makeSimpleCondition();
IfCondition c = makeSimpleCondition();
IfCondition cond = merge(Mode.AND, merge(Mode.OR, not(a), not(b)), not(c));
IfCondition simp = simplify(cond);
assertEquals(simp.getMode(), Mode.NOT);
IfCondition f = simp.first();
assertEquals(f.getMode(), Mode.OR);
assertEquals(f.first().getMode(), Mode.AND);
assertEquals(f.first().first(), a);
assertEquals(f.first().second(), b);
assertEquals(f.second(), c);
}
Aggregations