Commit a55f4c59 authored by Skylot's avatar Skylot

Fix self constructor call

parent 4e7ef9f4
...@@ -211,15 +211,12 @@ public class RegionGen extends InsnGen { ...@@ -211,15 +211,12 @@ public class RegionGen extends InsnGen {
private void makeCaseBlock(IContainer c, CodeWriter code) throws CodegenException { private void makeCaseBlock(IContainer c, CodeWriter code) throws CodegenException {
if (RegionUtils.notEmpty(c)) { if (RegionUtils.notEmpty(c)) {
boolean closeBlock = RegionUtils.hasExitEdge(c); code.add(" {");
if (closeBlock) {
code.add(" {");
}
makeRegionIndent(code, c); makeRegionIndent(code, c);
if (closeBlock) { if (RegionUtils.hasExitEdge(c)) {
code.startLine(1, "break;"); code.startLine(1, "break;");
code.startLine('}');
} }
code.startLine('}');
} else { } else {
code.startLine(1, "break;"); code.startLine(1, "break;");
} }
......
...@@ -19,7 +19,7 @@ public class ConstructorInsn extends InsnNode { ...@@ -19,7 +19,7 @@ public class ConstructorInsn extends InsnNode {
SELF // call itself SELF // call itself
} }
private final CallType callType; private CallType callType;
public ConstructorInsn(MethodNode mth, InvokeNode invoke) { public ConstructorInsn(MethodNode mth, InvokeNode invoke) {
super(InsnType.CONSTRUCTOR, invoke.getArgsCount() - 1); super(InsnType.CONSTRUCTOR, invoke.getArgsCount() - 1);
...@@ -28,16 +28,17 @@ public class ConstructorInsn extends InsnNode { ...@@ -28,16 +28,17 @@ public class ConstructorInsn extends InsnNode {
if (invoke.getArg(0).isThis()) { if (invoke.getArg(0).isThis()) {
if (classType.equals(mth.getParentClass().getClassInfo())) { if (classType.equals(mth.getParentClass().getClassInfo())) {
// self constructor
if (callMth.getShortId().equals(mth.getMethodInfo().getShortId())) { if (callMth.getShortId().equals(mth.getMethodInfo().getShortId())) {
// self constructor
callType = CallType.SELF; callType = CallType.SELF;
} else { } else if (mth.getMethodInfo().isConstructor()) {
callType = CallType.THIS; callType = CallType.THIS;
} }
} else { } else {
callType = CallType.SUPER; callType = CallType.SUPER;
} }
} else { }
if (callType == null) {
callType = CallType.CONSTRUCTOR; callType = CallType.CONSTRUCTOR;
setResult((RegisterArg) invoke.getArg(0)); setResult((RegisterArg) invoke.getArg(0));
} }
......
...@@ -207,7 +207,10 @@ public class RegionMaker { ...@@ -207,7 +207,10 @@ public class RegionMaker {
// found cross // found cross
if (next.getCleanSuccessors().size() == 1) { if (next.getCleanSuccessors().size() == 1) {
BlockNode r = BlockUtils.getNextBlock(next); BlockNode r = BlockUtils.getNextBlock(next);
if (r != null && r.getAttributes().contains(AttributeFlag.RETURN)) { if (r != null
&& r.getAttributes().contains(AttributeFlag.RETURN)
&& r.getInstructions().size() > 0
&& r.getInstructions().get(0).getType() == InsnType.RETURN) {
next.getAttributes().add(new ForceReturnAttr(r.getInstructions().get(0))); next.getAttributes().add(new ForceReturnAttr(r.getInstructions().get(0)));
} else { } else {
next.getAttributes().add(AttributeFlag.BREAK); next.getAttributes().add(AttributeFlag.BREAK);
......
...@@ -3,9 +3,16 @@ package jadx.samples; ...@@ -3,9 +3,16 @@ package jadx.samples;
import java.util.Arrays; import java.util.Arrays;
public class TestInvoke extends AbstractTest { public class TestInvoke extends AbstractTest {
private int f; private int f;
public TestInvoke() {
this(-1);
}
public TestInvoke(int f) {
this.f = f;
}
private void parse(String[] args) { private void parse(String[] args) {
if (args.length > 0) if (args.length > 0)
f = Integer.parseInt(args[0]); f = Integer.parseInt(args[0]);
...@@ -30,6 +37,13 @@ public class TestInvoke extends AbstractTest { ...@@ -30,6 +37,13 @@ public class TestInvoke extends AbstractTest {
return s; return s;
} }
public TestInvoke testConstructor(int flag) {
if (getF() == flag)
return new TestInvoke(flag);
else
return this;
}
@Override @Override
public boolean testRun() throws Exception { public boolean testRun() throws Exception {
TestInvoke inv = new TestInvoke(); TestInvoke inv = new TestInvoke();
...@@ -41,6 +55,8 @@ public class TestInvoke extends AbstractTest { ...@@ -41,6 +55,8 @@ public class TestInvoke extends AbstractTest {
assertTrue(inv.testVarArgs("a", "2", "III")); assertTrue(inv.testVarArgs("a", "2", "III"));
assertTrue(inv.testVarArgs2("a".toCharArray(), new char[] { '1', '2' }).equals("a12")); assertTrue(inv.testVarArgs2("a".toCharArray(), new char[] { '1', '2' }).equals("a12"));
assertTrue(testConstructor(f) != this);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment