simplify() now in extra method

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@637 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 25 years ago
parent d93672ba8a
commit eac030bc79
  1. 3
      jode/jode/flow/ConditionalBlock.java
  2. 7
      jode/jode/flow/IfThenElseBlock.java
  3. 6
      jode/jode/flow/InstructionContainer.java
  4. 19
      jode/jode/flow/LoopBlock.java
  5. 2
      jode/jode/flow/ReturnBlock.java
  6. 2
      jode/jode/flow/SwitchBlock.java
  7. 9
      jode/jode/flow/SynchronizedBlock.java

@ -122,7 +122,7 @@ public class ConditionalBlock extends InstructionContainer {
public void dumpInstruction(TabbedPrintWriter writer) public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
writer.println("IF ("+instr.simplify().toString()+")"); writer.println("IF ("+instr.toString()+")");
writer.tab(); writer.tab();
trueBlock.dumpSource(writer); trueBlock.dumpSource(writer);
writer.untab(); writer.untab();
@ -135,3 +135,4 @@ public class ConditionalBlock extends InstructionContainer {
|| CreateIfThenElseOperator.createFunny(this, last); || CreateIfThenElseOperator.createFunny(this, last);
} }
} }

@ -140,7 +140,7 @@ public class IfThenElseBlock extends StructuredBlock {
throws java.io.IOException throws java.io.IOException
{ {
boolean needBrace = thenBlock.needsBraces(); boolean needBrace = thenBlock.needsBraces();
writer.print("if ("+cond.simplify().toString()+")"); writer.print("if ("+cond.toString()+")");
if (needBrace) if (needBrace)
writer.openBrace(); writer.openBrace();
else else
@ -194,6 +194,11 @@ public class IfThenElseBlock extends StructuredBlock {
&& (elseBlock.jump != null || elseBlock.jumpMayBeChanged()); && (elseBlock.jump != null || elseBlock.jumpMayBeChanged());
} }
public void simplify() {
cond = cond.simplify();
super.simplify();
}
public boolean doTransformations() { public boolean doTransformations() {
StructuredBlock last = flowBlock.lastModified; StructuredBlock last = flowBlock.lastModified;
return CreateCheckNull.transformJikes(this, last) return CreateCheckNull.transformJikes(this, last)

@ -99,6 +99,12 @@ public abstract class InstructionContainer extends StructuredBlock {
return instr; return instr;
} }
public void simplify() {
if (instr != null)
instr = instr.simplify();
super.simplify();
}
/** /**
* Set the contained instruction. * Set the contained instruction.
* @param instr the new instruction. * @param instr the new instruction.

@ -246,7 +246,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
/* special syntax for endless loops: */ /* special syntax for endless loops: */
writer.print("for (;;)"); writer.print("for (;;)");
else else
writer.print("while ("+cond.simplify().toString()+")"); writer.print("while ("+cond.toString()+")");
break; break;
case DOWHILE: case DOWHILE:
writer.print("do"); writer.print("do");
@ -259,11 +259,11 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
init.getInstruction().getOperator()) init.getInstruction().getOperator())
.getLocalInfo().getType().getHint() .getLocalInfo().getType().getHint()
+ " "); + " ");
writer.print(init.getInstruction().simplify().toString()); writer.print(init.getInstruction().toString());
} else } else
writer.print("/**/"); writer.print("/**/");
writer.print("; "+cond.simplify().toString()+"; " writer.print("; "+cond.toString()+"; "
+incr.getInstruction().simplify().toString()+")"); +incr.getInstruction().toString()+")");
break; break;
} }
if (needBrace) if (needBrace)
@ -439,8 +439,19 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
return mayChangeJump; return mayChangeJump;
} }
public void simplify() {
cond = cond.simplify();
if (type == FOR) {
incr.simplify();
if (init != null)
init.simplify();
}
super.simplify();
}
public boolean doTransformations() { public boolean doTransformations() {
return init == null && (type == FOR || type == POSSFOR) return init == null && (type == FOR || type == POSSFOR)
&& CreateForInitializer.transform(this, flowBlock.lastModified); && CreateForInitializer.transform(this, flowBlock.lastModified);
} }
} }

@ -75,6 +75,6 @@ public class ReturnBlock extends InstructionContainer {
throws java.io.IOException throws java.io.IOException
{ {
writer.println("return" + writer.println("return" +
(instr == null ? "" : " " + instr.simplify()) + ";"); (instr == null ? "" : " " + instr) + ";");
} }
} }

@ -191,7 +191,7 @@ implements BreakableBlock {
writer.println(label+":"); writer.println(label+":");
writer.tab(); writer.tab();
} }
writer.print("switch ("+instr.simplify()+")"); writer.print("switch ("+instr+")");
writer.openBrace(); writer.openBrace();
for (int i=0; i < caseBlocks.length; i++) for (int i=0; i < caseBlocks.length; i++)
caseBlocks[i].dumpSource(writer); caseBlocks[i].dumpSource(writer);

@ -85,7 +85,7 @@ public class SynchronizedBlock extends StructuredBlock {
writer.println("MISSING MONITORENTER"); writer.println("MISSING MONITORENTER");
writer.print("synchronized (" writer.print("synchronized ("
+ (object != null + (object != null
? object.simplify().toString() ? object.toString()
: local.getName()) + ")"); : local.getName()) + ")");
writer.openBrace(); writer.openBrace();
writer.tab(); writer.tab();
@ -94,6 +94,13 @@ public class SynchronizedBlock extends StructuredBlock {
writer.closeBrace(); writer.closeBrace();
} }
public void simplify() {
if (object != null)
object = object.simplify();
super.simplify();
}
public boolean doTransformations() { public boolean doTransformations() {
StructuredBlock last = flowBlock.lastModified; StructuredBlock last = flowBlock.lastModified;
return (!isEntered && CompleteSynchronized.enter(this, last)) return (!isEntered && CompleteSynchronized.enter(this, last))

Loading…
Cancel
Save