*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@119 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2f94432ce8
commit 8a83b27565
  1. 4
      jode/jode/decompiler/ClassAnalyzer.java
  2. 18
      jode/jode/expr/InvokeOperator.java
  3. 78
      jode/jode/flow/TransformConstructors.java

@ -64,6 +64,10 @@ public class ClassAnalyzer implements Analyzer {
return false; return false;
} }
public Class getClazz() {
return clazz;
}
public void analyze() { public void analyze() {
int numFields = 0; int numFields = 0;
int i = 0; int i = 0;

@ -88,6 +88,20 @@ public final class InvokeOperator extends Operator {
return methodName.equals("<init>"); return methodName.equals("<init>");
} }
public boolean isThis() {
Class clazz = codeAnalyzer.method.classAnalyzer.getClazz();
return (classType.equals(Type.tType(clazz)));
}
public boolean isSuperOrThis() {
Class clazz = codeAnalyzer.method.classAnalyzer.getClazz();
while (clazz != null
&& !classType.equals(Type.tType(clazz))) {
clazz = clazz.getSuperclass();
}
return (clazz != null);
}
public String toString(String[] operands) { public String toString(String[] operands) {
String object = null; String object = null;
if (specialFlag) { if (specialFlag) {
@ -101,11 +115,11 @@ public final class InvokeOperator extends Operator {
} }
if (clazz == null) if (clazz == null)
object = "SPECIAL"; object = "NON VIRTUAL this";
} else if (classType.equals(Type.tType(clazz))) } else if (classType.equals(Type.tType(clazz)))
object = operands[0]; object = operands[0];
else else
object = "SPECIAL "+operands[0]; object = "NON VIRTUAL "+operands[0];
} }
object = (object != null) ? object object = (object != null) ? object

@ -35,29 +35,55 @@ public class TransformConstructors {
if (cons.length == 0) if (cons.length == 0)
return; return;
InstructionBlock[] superCall = new InstructionBlock[cons.length]; int constrCount = cons.length;
StructuredBlock[] start = new StructuredBlock[cons.length]; StructuredBlock[] sb = new StructuredBlock[constrCount];
StructuredBlock[] sb = new StructuredBlock[cons.length]; for (int i=0; i< constrCount; ) {
for (int i=0; i< sb.length; i++) {
sb[i] = cons[i].getMethodHeader().block; sb[i] = cons[i].getMethodHeader().block;
if (sb[i] == null) if (!isStatic) {
return; InstructionBlock ib;
if (!isStatic && if (sb[i] instanceof InstructionBlock)
sb[i] instanceof SequentialBlock ib = (InstructionBlock)sb[i];
&& sb[i].getSubBlocks()[0] instanceof InstructionBlock) { else if (sb[i] instanceof SequentialBlock
superCall[i] = (InstructionBlock) sb[i].getSubBlocks()[0]; && (sb[i].getSubBlocks()[0]
instanceof InstructionBlock))
if (!(superCall[i].getInstruction().getOperator() ib = (InstructionBlock) sb[i].getSubBlocks()[0];
instanceof InvokeOperator)
|| !((InvokeOperator)superCall[i].getInstruction()
.getOperator()).isConstructor())
superCall[i] = null;
else else
/* skip super call */ return;
Expression instr = ib.getInstruction();
if (!(instr instanceof ComplexExpression)
|| !(instr.getOperator() instanceof InvokeOperator)
|| !(((ComplexExpression)instr)
.getSubExpressions()[0].toString().equals("this")))
return;
InvokeOperator invoke = (InvokeOperator) instr.getOperator();
if (!invoke.isConstructor() || !invoke.isSuperOrThis())
return;
if (invoke.isThis()) {
/* This constructor calls another constructor, so we
* can skip it.
*/
sb[i] = sb[--constrCount];
continue;
}
/* This constructor begins with a super call, as
* expected. If the super() has no parameters, we
* can remove it as it is implicit.
*/
if (invoke.getMethodType().getParameterTypes().length == 0)
ib.removeBlock();
if (sb[i] instanceof SequentialBlock)
sb[i] = sb[i].getSubBlocks()[1]; sb[i] = sb[i].getSubBlocks()[1];
else
sb[i] = new EmptyBlock();
} }
i++;
} }
for (int i=0; i< sb.length; i++) StructuredBlock[] start = new StructuredBlock[constrCount];
for (int i=0; i< constrCount; i++)
start[i] = sb[i]; start[i] = sb[i];
big_loop: big_loop:
for (;;) { for (;;) {
@ -94,7 +120,7 @@ public class TransformConstructors {
break big_loop; break big_loop;
} }
for (int i=1; i< sb.length; i++) { for (int i=1; i< constrCount; i++) {
ib = (sb[0] instanceof SequentialBlock) ib = (sb[0] instanceof SequentialBlock)
? sb[0].getSubBlocks()[0] ? sb[0].getSubBlocks()[0]
: sb[0]; : sb[0];
@ -112,31 +138,23 @@ public class TransformConstructors {
} }
for (int i=0; i< sb.length; i++) { for (int i=0; i< constrCount; i++) {
if (sb[i] instanceof SequentialBlock) if (sb[i] instanceof SequentialBlock)
sb[i] = sb[i].getSubBlocks()[1]; sb[i] = sb[i].getSubBlocks()[1];
else else
sb[i] = null; sb[i] = null;
} }
for (int i=0; i< sb.length; i++) for (int i=0; i< constrCount; i++)
if (sb[i] == null) { if (sb[i] == null) {
// System.err.println("constr "+i+" is over"); // System.err.println("constr "+i+" is over");
break big_loop; break big_loop;
} }
} }
for (int i=0; i< superCall.length; i++) { for (int i=0; i< constrCount; i++) {
if (sb[i] == null) if (sb[i] == null)
start[i].removeBlock(); start[i].removeBlock();
else else
sb[i].replace(start[i]); sb[i].replace(start[i]);
if (superCall[i] != null) {
InvokeOperator op =
(InvokeOperator) superCall[i].getInstruction()
.getOperator();
/* super() is implicit */
if (op.getMethodType().getParameterTypes().length == 0)
superCall[i].removeBlock();
}
} }
} }
} }

Loading…
Cancel
Save