*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@37 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 27 years ago
parent 704a534731
commit d5131c70be
  1. 4
      jode/jode/decompiler/LocalVariableRangeList.java
  2. 2
      jode/jode/decompiler/LocalVariableTable.java
  3. 56
      jode/jode/flow/CatchBlock.java
  4. 9
      jode/jode/flow/FlowBlock.java
  5. 31
      jode/jode/flow/InstructionBlock.java
  6. 54
      jode/jode/flow/RawTryCatchBlock.java
  7. 24
      jode/jode/flow/StructuredBlock.java
  8. 94
      jode/jode/flow/jode.ppl
  9. 8
      jode/jode/type/ClassRangeType.java
  10. 5
      jode/jode/type/MyType.java

@ -62,9 +62,9 @@ public class LocalVariableRangeList implements LocalVariable {
private LocalInfo find(int addr) { private LocalInfo find(int addr) {
MyLocalInfo li = list; MyLocalInfo li = list;
while (li != null && addr > li.start+li.length) while (li != null && addr >= li.start+li.length)
li = li.next; li = li.next;
if (li == null || li.start > addr) { if (li == null || li.start > addr+2/*XXX*/) {
LocalInfo temp = new LocalInfo(slot); LocalInfo temp = new LocalInfo(slot);
return temp; return temp;
} }

@ -43,7 +43,7 @@ public class LocalVariableTable {
{ {
int count = stream.readUnsignedShort(); int count = stream.readUnsignedShort();
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {
int start = stream.readUnsignedShort()-2; /*XXX*/ int start = stream.readUnsignedShort();
int length = stream.readUnsignedShort(); int length = stream.readUnsignedShort();
int name_i = stream.readUnsignedShort(); int name_i = stream.readUnsignedShort();
int desc_i = stream.readUnsignedShort(); int desc_i = stream.readUnsignedShort();

@ -59,28 +59,43 @@ public class CatchBlock extends StructuredBlock {
* @param catchBlock the catch block. * @param catchBlock the catch block.
*/ */
public void setCatchBlock(StructuredBlock catchBlock) { public void setCatchBlock(StructuredBlock catchBlock) {
if (catchBlock instanceof SequentialBlock if ((catchBlock instanceof SequentialBlock
&& catchBlock.getSubBlocks()[0] instanceof InstructionBlock) { && catchBlock.getSubBlocks()[0] instanceof InstructionBlock)
|| catchBlock instanceof InstructionBlock) {
InstructionBlock localBlock = jode.Instruction instr =
(InstructionBlock) catchBlock.getSubBlocks()[0]; ((InstructionBlock) (catchBlock instanceof InstructionBlock
jode.Instruction instr = localBlock.getInstruction(); ? catchBlock
: catchBlock.getSubBlocks()[0])
).getInstruction();
if (instr instanceof jode.PopOperator) { if (instr instanceof jode.PopOperator) {
exceptionLocal = new LocalInfo(99); exceptionLocal = new LocalInfo(-1);
exceptionLocal.setName exceptionLocal.setName
(Identifier.lookup("exception_"+(serialno++)+"_")); (Identifier.lookup("exception_"+(serialno++)+"_"));
catchBlock = catchBlock.getSubBlocks()[1]; exceptionLocal.setType(exceptionType);
} else if (instr instanceof jode.LocalStoreOperator) { } else if (instr instanceof jode.LocalStoreOperator) {
exceptionLocal = exceptionLocal =
((jode.LocalStoreOperator) instr).getLocalInfo(); ((jode.LocalStoreOperator) instr).getLocalInfo();
catchBlock = catchBlock.getSubBlocks()[1]; }
if (exceptionLocal != null) {
StructuredBlock newCatchBlock =
(catchBlock instanceof InstructionBlock
? new EmptyBlock()
: catchBlock.getSubBlocks()[1]);
if (catchBlock.jump != null)
newCatchBlock.moveJump(catchBlock);
catchBlock = newCatchBlock;
} }
} }
if (exceptionLocal == null) { if (exceptionLocal == null) {
exceptionLocal = new LocalInfo(99); exceptionLocal = new LocalInfo(-1);
exceptionLocal.setName(Identifier.lookup("ERROR!!!")); exceptionLocal.setName(Identifier.lookup("ERROR!!!"));
exceptionLocal.setType(exceptionType);
} }
used.addElement(exceptionLocal);
this.catchBlock = catchBlock; this.catchBlock = catchBlock;
catchBlock.outer = this; catchBlock.outer = this;
catchBlock.setFlowBlock(flowBlock); catchBlock.setFlowBlock(flowBlock);
@ -124,6 +139,24 @@ public class CatchBlock extends StructuredBlock {
&& (catchBlock.jump != null || catchBlock.jumpMayBeChanged()); && (catchBlock.jump != null || catchBlock.jumpMayBeChanged());
} }
/**
* Print the code for the declaration of a local variable.
* @param writer The tabbed print writer, where we print to.
* @param local The local that should be declared.
*/
public void dumpDeclaration(jode.TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException
{
if (local != exceptionLocal) {
/* exceptionLocal will be automatically declared in
* dumpInstruction.
*
* This is currently broken for nested tries... XXX
*/
super.dumpDeclaration(writer, local);
}
}
public void dumpInstruction(jode.TabbedPrintWriter writer) public void dumpInstruction(jode.TabbedPrintWriter writer)
throws java.io.IOException { throws java.io.IOException {
/* avoid ugly nested tries */ /* avoid ugly nested tries */
@ -132,7 +165,7 @@ public class CatchBlock extends StructuredBlock {
writer.println("try {"); writer.println("try {");
writer.tab(); writer.tab();
} }
tryBlock.dumpInstruction(writer); tryBlock.dumpSource(writer);
writer.untab(); writer.untab();
writer.println("} catch ("+/*XXX*/exceptionType.typeString writer.println("} catch ("+/*XXX*/exceptionType.typeString
(exceptionLocal.getName().toString())+") {"); (exceptionLocal.getName().toString())+") {");
@ -145,3 +178,6 @@ public class CatchBlock extends StructuredBlock {
} }
} }
} }

@ -150,7 +150,7 @@ public class FlowBlock {
same_jump: while(true) { same_jump: while(true) {
/* if the jump is the jump of the appendBlock, skip it. /* if the jump is the jump of the appendBlock, skip it.
*/ */
if (jump.prev == appendBlock) if (jump.prev == null || jump.prev == appendBlock)
continue next_jump; continue next_jump;
/* Note: jump.prev.outer != null, since appendBlock is /* Note: jump.prev.outer != null, since appendBlock is
@ -671,7 +671,7 @@ public class FlowBlock {
/* Do the following modifications on the struct block. */ /* Do the following modifications on the struct block. */
appendBlock = precedingcase; appendBlock = precedingcase;
succ.block.setFlowBlock(this); succ.block.setFlowBlock(this);
switchBlock.define(defineHere); // switchBlock.define(defineHere);
} else { } else {
@ -698,7 +698,7 @@ public class FlowBlock {
sequBlock.setFirst(appendBlock); sequBlock.setFirst(appendBlock);
sequBlock.setSecond(succ.block); sequBlock.setSecond(succ.block);
succ.block.setFlowBlock(this); succ.block.setFlowBlock(this);
sequBlock.define(defineHere); // sequBlock.define(defineHere);
} }
/* Merge the sucessors from the successing flow block /* Merge the sucessors from the successing flow block
@ -773,7 +773,6 @@ public class FlowBlock {
LoopBlock.FALSE); LoopBlock.FALSE);
int breaklevel = 1; int breaklevel = 1;
Jump debug=jump;
for (StructuredBlock surrounder = jump.prev.outer; for (StructuredBlock surrounder = jump.prev.outer;
surrounder != appendBlock.outer; surrounder != appendBlock.outer;
surrounder = surrounder.outer) { surrounder = surrounder.outer) {
@ -898,7 +897,7 @@ public class FlowBlock {
whileBlock.replace(bodyBlock, bodyBlock); whileBlock.replace(bodyBlock, bodyBlock);
whileBlock.setBody(bodyBlock); whileBlock.setBody(bodyBlock);
whileBlock.define(defineHere); // whileBlock.define(defineHere);
/* Try to eliminate as many jumps as possible. /* Try to eliminate as many jumps as possible.
*/ */

@ -31,11 +31,42 @@ public class InstructionBlock extends InstructionContainer {
super(instr, jump); super(instr, jump);
} }
/**
* True if this is a declaration.
*/
private boolean isDeclaration = false;
public void dumpDeclaration(TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException
{
if (instr instanceof Expression
&& ((Expression)instr).getOperator() instanceof LocalStoreOperator
&& ((LocalStoreOperator) ((Expression)instr).getOperator())
.getLocalInfo() == local) {
isDeclaration = true;
} else
super.dumpDeclaration(writer, local);
}
public void dumpSource(TabbedPrintWriter writer)
throws java.io.IOException
{
isDeclaration = false;
super.dumpSource(writer);
}
public void dumpInstruction(TabbedPrintWriter writer) public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
if (isDeclaration) {
writer.println
(((LocalStoreOperator) ((Expression)instr).getOperator())
.getLocalInfo().getType().toString()/*XXX*/
+ " " + instr.toString() + ";");
} else {
if (instr.getType() != MyType.tVoid) if (instr.getType() != MyType.tVoid)
writer.print("push "); writer.print("push ");
writer.println(instr.toString()+";"); writer.println(instr.toString()+";");
} }
} }
}

@ -47,8 +47,8 @@ public class RawTryCatchBlock extends StructuredBlock {
Jump endDest, Jump catchDest) { Jump endDest, Jump catchDest) {
this.type = type; this.type = type;
endBlock = new EmptyBlock(endDest); // endBlock = new EmptyBlock(endDest);
endBlock.outer = this; // endBlock.outer = this;
catchBlock = new EmptyBlock(catchDest); catchBlock = new EmptyBlock(catchDest);
catchBlock.outer = this; catchBlock.outer = this;
@ -57,13 +57,13 @@ public class RawTryCatchBlock extends StructuredBlock {
this.tryBlock = tryBlock; this.tryBlock = tryBlock;
tryBlock.outer = this; tryBlock.outer = this;
endBlock.setFlowBlock(flowBlock); // endBlock.setFlowBlock(flowBlock);
if (tryBlock instanceof RawTryCatchBlock // if (tryBlock instanceof RawTryCatchBlock
&& ((RawTryCatchBlock)tryBlock).endBlock.jump.destination // && ((RawTryCatchBlock)tryBlock).endBlock.jump.destination
== endDest.destination) // == endDest.destination)
endBlock.jump = null; // endBlock.jump = null;
else // else
flowBlock.addSuccessor(endDest); // flowBlock.addSuccessor(endDest);
catchBlock.setFlowBlock(flowBlock); catchBlock.setFlowBlock(flowBlock);
flowBlock.addSuccessor(catchDest); flowBlock.addSuccessor(catchDest);
@ -74,11 +74,11 @@ public class RawTryCatchBlock extends StructuredBlock {
*/ */
StructuredBlock tryBlock; StructuredBlock tryBlock;
/** // /**
* An empty block containing an unconditional jump to the EndBlock. // * An empty block containing an unconditional jump to the EndBlock.
* Or null if the try block is completely read. // * Or null if the try block is completely read.
*/ // */
StructuredBlock endBlock; // StructuredBlock endBlock;
/** /**
* The catch block. * The catch block.
@ -99,16 +99,16 @@ public class RawTryCatchBlock extends StructuredBlock {
*/ */
public boolean replaceSubBlock(StructuredBlock oldBlock, public boolean replaceSubBlock(StructuredBlock oldBlock,
StructuredBlock newBlock) { StructuredBlock newBlock) {
if (tryBlock == oldBlock) { if (tryBlock == oldBlock)
tryBlock = newBlock; tryBlock = newBlock;
if (tryBlock instanceof RawTryCatchBlock // if (tryBlock instanceof RawTryCatchBlock
&& ((RawTryCatchBlock)tryBlock).endBlock.jump.destination // && ((RawTryCatchBlock)tryBlock).endBlock.jump.destination
== endBlock.jump.destination) { // == endBlock.jump.destination) {
endBlock.removeJump(); // endBlock.removeJump();
} // }
} else if (endBlock == oldBlock) // } else if (endBlock == oldBlock) {
endBlock = newBlock; // endBlock = newBlock;
else if (catchBlock == oldBlock) else if (catchBlock == oldBlock)
catchBlock = newBlock; catchBlock = newBlock;
else else
@ -120,7 +120,7 @@ public class RawTryCatchBlock extends StructuredBlock {
* Returns all sub block of this structured block. * Returns all sub block of this structured block.
*/ */
public StructuredBlock[] getSubBlocks() { public StructuredBlock[] getSubBlocks() {
StructuredBlock[] result = { tryBlock, endBlock, catchBlock }; StructuredBlock[] result = { tryBlock/*, endBlock*/, catchBlock };
return result; return result;
} }
@ -140,10 +140,10 @@ public class RawTryCatchBlock extends StructuredBlock {
writer.tab(); writer.tab();
tryBlock.dumpSource(writer); tryBlock.dumpSource(writer);
writer.untab(); writer.untab();
writer.println("UNTIL"); // writer.println("UNTIL");
writer.tab(); // writer.tab();
endBlock.dumpSource(writer); // endBlock.dumpSource(writer);
writer.untab(); // writer.untab();
writer.println("CATCH TO"); writer.println("CATCH TO");
writer.tab(); writer.tab();
catchBlock.dumpSource(writer); catchBlock.dumpSource(writer);

@ -275,6 +275,29 @@ public abstract class StructuredBlock {
} }
} }
public VariableSet propagateUsage() {
StructuredBlock[] subs = getSubBlocks();
VariableSet[] childUse = new VariableSet[subs.length];
VariableSet allUse = (VariableSet) used.clone();
for (int i=0; i<subs.length; i++) {
childUse[i] = subs[i].propagateUsage();
allUse.addExact(childUse[i]);
}
if (subs.length == 2) {
/* All variables used in both sub blocks, are used in
* this block, too. But a sequential block is a notable
* exception, since it is enough if the first sub block
* declares the Variable
*/
VariableSet newUse = childUse[0].intersectExact(childUse[1]);
if (this instanceof SequentialBlock)
subs[0].used.addExact(newUse);
else
used.addExact(newUse);
}
return allUse;
}
/** /**
* Make the declarations, i.e. initialize the declare variable * Make the declarations, i.e. initialize the declare variable
* to correct values. This will declare every variable that * to correct values. This will declare every variable that
@ -282,6 +305,7 @@ public abstract class StructuredBlock {
* @param done The set of the already declare variables. * @param done The set of the already declare variables.
*/ */
public void makeDeclaration(VariableSet done) { public void makeDeclaration(VariableSet done) {
propagateUsage();
declare.addExact(used); declare.addExact(used);
declare.subtractExact(done); declare.subtractExact(done);
done.addExact(declare); done.addExact(declare);

@ -94,7 +94,7 @@
1998-09-22 20:44:33 bi 1998-09-22 20:44:33 bi
essen essen
1998-09-22 21:37:22 ei 1998-09-22 21:37:22 ei
1998-09-22 21:35:26 be 1998-09-22 21:37:26 be
1998-09-22 21:39:59 ee cd data wrongorder FlowBlock.java 1998-09-22 21:39:59 ee cd data wrongorder FlowBlock.java
1998-09-22 21:40:17 be 1998-09-22 21:40:17 be
1998-09-22 21:42:46 ee cd null omission FlowBlock.java 1998-09-22 21:42:46 ee cd null omission FlowBlock.java
@ -134,3 +134,95 @@
some heavy errors still... some heavy errors still...
... fixing ... fixing
1998-09-23 13:27:22 ete 1998-09-23 13:27:22 ete
1998-09-23 22:21:47 bcd
Local Variable improvements...
1998-09-23 22:35:31 bi
1998-09-23 22:47:50 ei
1998-09-23 23:11:14 bi
1998-09-24 00:05:02 ei
1998-09-24 00:05:07 ecd
1998-09-24 08:22:33 be
Fixing a bug I found overnight
1998-09-24 08:23:33 ee cd data omission FlowBlock.java
1998-09-24 09:18:15 be
Wrong place for in-Variables??
Make it FlowBlock-Member now!
1998-09-24 09:30:12 ee ds data ... StructuredBlock.java
1998-09-24 09:30:12 bdr
in: FlowBlock-Member?
out: Jump-Member???
1998-09-24 10:14:31 bi
1998-09-24 10:18:30 ei
1998-09-24 10:18:31 edr
1998-09-24 10:18:32 be
in/out trafos stimmen nicht!
1998-09-24 10:36:57 ee cd data overwritten StructuredBlock.java
1998-09-24 10:36:58 bte
1998-09-24 10:45:14 ete
1998-09-24 10:48:54 bcr
Clean up!
1998-09-24 10:53:42 ecr
1998-09-24 10:55:15 bte
1998-09-24 11:01:54 be
1998-09-24 11:06:42 ee ds flow notenoughthinking CodeAnalyzer.java
Test did succeed, now!!!
1998-09-24 11:11:22 ete
1998-09-24 11:11:38 bds
local definition
1998-09-24 11:24:30 eds
1998-09-24 11:24:33 bte
fine tuning...
... no success it really needs more thinking!!!
1998-09-24 12:40:16 ete
Essen fahren!
1998-09-24 16:00:00 bcd
1998-09-24 20:40:00 ecd
Local Variables are still broken
1998-09-25 11:25:27 bcd
Doing some other expression-building
1998-09-25 11:28:22 bi
java-mode configuration
1998-09-25 11:40:57 ei
1998-09-25 13:30:28 ecd
Essen fahren, CreateAssignExpression angefangen, aber noch nicht fertig!
1998-09-25 20:27:42 bcd
1998-09-25 20:32:43 ecd
1998-09-25 20:32:47 bcp
1998-09-25 20:38:43 ecp
1998-09-25 20:38:49 bte
1998-09-25 20:38:51 bi
1998-09-25 20:50:39 ei
1998-09-25 20:50:41 be
1998-09-25 20:55:58
it's a error in the old version. Doesn't support postinc's on static
fields.
1998-09-25 20:58:57 bi
1998-09-25 21:10:56 ei
1998-09-25 21:19:24 ee prevcd
1998-09-25 21:19:24 ete
We should probably try to simplify the expression mechanism. We
don't need to produce an expression if the operator has no parameters
at all.
1998-09-25 21:20:54 bcd
I now want to handle the try-catch blocks. Finally will be done later...
1998-09-25 22:25:25 ecd
1998-09-25 22:25:27 bte
finetuning until try catch block are working.
1998-09-25 23:41:36 ete
Now it runs most times...
(but the relationship of endBlock and catchBlock must be solved)
Important tasks:
1. Implement switch
2. locals need more thought
3. Handle JSR
4. Implement finally
5. Handle MonitorEnter/Exit
6. Implement synchronized()
7. field initialization
8. Type output
9. Differentiate local and member variables with same name.
1998-09-26 10:30:00 bcd
local declaration.
bug fix for empty switches
1998-09-26 11:51:09 ecd
Okay 2. works perfect

@ -350,10 +350,12 @@ public class ClassRangeType extends MyType {
public String typeString(String string, boolean flag1, boolean flag2) public String typeString(String string, boolean flag1, boolean flag2)
{ {
// if (verbose??) if (Decompiler.isDebugging)
return "<"+bottomType+"-"+topType+">" + string; return "<"+bottomType+"-"+topType+">" + string;
// else else if (bottomType != null)
// return bottomType.typeString(string, flag1, flag2); return bottomType.typeString(string, flag1, flag2);
else
return tObject.typeString(string, flag1, flag2);
} }
// public String toString() // public String toString()

@ -59,8 +59,11 @@ public class MyType extends Type {
public static Type tSuperType(Type type) { public static Type tSuperType(Type type) {
int typeCode = type.getTypeCode(); int typeCode = type.getTypeCode();
if (typeCode == 9 || typeCode == 10 || typeCode == 103) if (typeCode == 9 || typeCode == 10)
return new ClassRangeType(tObject, type); return new ClassRangeType(tObject, type);
else if (typeCode == 103)
return (((ClassRangeType)type).topType == null
? tUnknown : new ClassRangeType(tObject, null));
else else
return type; return type;
} }

Loading…
Cancel
Save