use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testSimplifyNot2.
@Test
public void testSimplifyNot2() {
// !(!a) => a
IfCondition a = not(makeNegCondition());
assertEquals(simplify(a), a);
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testMerge.
@Test
public void testMerge() {
IfCondition a = makeSimpleCondition();
IfCondition b = makeSimpleCondition();
IfCondition c = merge(Mode.OR, a, b);
assertEquals(c.getMode(), Mode.OR);
assertEquals(c.first(), a);
assertEquals(c.second(), b);
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class TestIfCondition method testNormalize.
@Test
public void testNormalize() {
// 'a != false' => 'a == true'
InsnArg a = mockArg();
IfCondition c = makeCondition(IfOp.NE, a, LiteralArg.FALSE);
IfCondition simp = simplify(c);
assertEquals(simp.getMode(), Mode.COMPARE);
Compare compare = simp.getCompare();
assertEquals(compare.getA(), a);
assertEquals(compare.getB(), LiteralArg.TRUE);
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class RegionGen method makeLoop.
private CodeWriter makeLoop(LoopRegion region, CodeWriter code) throws CodegenException {
BlockNode header = region.getHeader();
if (header != null) {
List<InsnNode> headerInsns = header.getInstructions();
if (headerInsns.size() > 1) {
ErrorsCounter.methodError(mth, "Found not inlined instructions from loop header");
int last = headerInsns.size() - 1;
for (int i = 0; i < last; i++) {
InsnNode insn = headerInsns.get(i);
makeInsn(insn, code);
}
}
}
LoopLabelAttr labelAttr = region.getInfo().getStart().get(AType.LOOP_LABEL);
if (labelAttr != null) {
code.startLine(mgen.getNameGen().getLoopLabel(labelAttr)).add(':');
}
IfCondition condition = region.getCondition();
if (condition == null) {
// infinite loop
code.startLine("while (true) {");
makeRegionIndent(code, region.getBody());
code.startLine('}');
return code;
}
ConditionGen conditionGen = new ConditionGen(this);
LoopType type = region.getType();
if (type != null) {
if (type instanceof ForLoop) {
ForLoop forLoop = (ForLoop) type;
code.startLine("for (");
makeInsn(forLoop.getInitInsn(), code, Flags.INLINE);
code.add("; ");
conditionGen.add(code, condition);
code.add("; ");
makeInsn(forLoop.getIncrInsn(), code, Flags.INLINE);
code.add(") {");
makeRegionIndent(code, region.getBody());
code.startLine('}');
return code;
}
if (type instanceof ForEachLoop) {
ForEachLoop forEachLoop = (ForEachLoop) type;
code.startLine("for (");
declareVar(code, forEachLoop.getVarArg());
code.add(" : ");
addArg(code, forEachLoop.getIterableArg(), false);
code.add(") {");
makeRegionIndent(code, region.getBody());
code.startLine('}');
return code;
}
throw new JadxRuntimeException("Unknown loop type: " + type.getClass());
}
if (region.isConditionAtEnd()) {
code.startLine("do {");
makeRegionIndent(code, region.getBody());
code.startLine("} while (");
conditionGen.add(code, condition);
code.add(");");
} else {
code.startLine("while (");
conditionGen.add(code, condition);
code.add(") {");
makeRegionIndent(code, region.getBody());
code.startLine('}');
}
return code;
}
use of jadx.core.dex.regions.conditions.IfCondition in project jadx by skylot.
the class IfMakerHelper method mergeTernaryConditions.
private static IfInfo mergeTernaryConditions(IfInfo currentIf, IfInfo nextThen, IfInfo nextElse) {
IfCondition newCondition = IfCondition.ternary(currentIf.getCondition(), nextThen.getCondition(), nextElse.getCondition());
IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock());
result.setIfBlock(currentIf.getIfBlock());
result.merge(currentIf, nextThen, nextElse);
confirmMerge(result);
return result;
}
Aggregations