refactor: better place for removing parenthesis (PR #627)
This commit is contained in:
@@ -24,11 +24,4 @@ public enum ArithOp {
|
||||
public String getSymbol() {
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public boolean noWrapWith(ArithOp other) {
|
||||
return (this == ADD && other == ADD)
|
||||
|| (this == MUL && other == MUL)
|
||||
|| (this == AND && other == AND)
|
||||
|| (this == OR && other == OR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jadx.core.dex.attributes.AFlag;
|
||||
import jadx.core.dex.instructions.ArithNode;
|
||||
import jadx.core.dex.instructions.InsnType;
|
||||
import jadx.core.dex.nodes.InsnNode;
|
||||
import jadx.core.utils.InsnUtils;
|
||||
|
||||
@@ -113,12 +111,6 @@ public abstract class InsnArg extends Typed {
|
||||
insn.add(AFlag.WRAPPED);
|
||||
InsnArg arg = wrapArg(insn);
|
||||
parent.setArg(i, arg);
|
||||
|
||||
if (insn.getType() == InsnType.ARITH && parent.getType() == InsnType.ARITH
|
||||
&& ((ArithNode) insn).getOp().noWrapWith(((ArithNode) parent).getOp())) {
|
||||
insn.add(AFlag.DONT_WRAP);
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
|
||||
}
|
||||
removeInstructions(block);
|
||||
checkInline(block);
|
||||
// removeParenthesis(block);
|
||||
removeParenthesis(block);
|
||||
modifyArith(block);
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
|
||||
|
||||
private static void removeParenthesis(BlockNode block) {
|
||||
for (InsnNode insn : block.getInstructions()) {
|
||||
checkInsn(insn);
|
||||
removeParenthesis(insn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,17 +107,19 @@ public class PrepareForCodeGen extends AbstractVisitor {
|
||||
* Remove parenthesis for wrapped insn in arith '+' or '-'
|
||||
* ('(a + b) +c' => 'a + b + c')
|
||||
*/
|
||||
private static void checkInsn(InsnNode insn) {
|
||||
private static void removeParenthesis(InsnNode insn) {
|
||||
if (insn.getType() == InsnType.ARITH) {
|
||||
ArithNode arith = (ArithNode) insn;
|
||||
ArithOp op = arith.getOp();
|
||||
if (op == ArithOp.ADD || op == ArithOp.SUB) {
|
||||
if (op == ArithOp.ADD || op == ArithOp.MUL || op == ArithOp.AND || op == ArithOp.OR) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
InsnArg arg = arith.getArg(i);
|
||||
if (arg.isInsnWrap()) {
|
||||
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
|
||||
wrapInsn.add(AFlag.DONT_WRAP);
|
||||
checkInsn(wrapInsn);
|
||||
if (wrapInsn.getType() == InsnType.ARITH && ((ArithNode) wrapInsn).getOp() == op) {
|
||||
wrapInsn.add(AFlag.DONT_WRAP);
|
||||
}
|
||||
removeParenthesis(wrapInsn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,7 +127,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
|
||||
for (InsnArg arg : insn.getArguments()) {
|
||||
if (arg.isInsnWrap()) {
|
||||
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
|
||||
checkInsn(wrapInsn);
|
||||
removeParenthesis(wrapInsn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user