simplify expressions before printing them

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@56 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 1915c9f8f4
commit 7be8903482
  1. 2
      jode/jode/flow/ConditionalBlock.java
  2. 1
      jode/jode/flow/FlowBlock.java
  3. 3
      jode/jode/flow/IfThenElseBlock.java
  4. 4
      jode/jode/flow/InstructionBlock.java
  5. 10
      jode/jode/flow/LoopBlock.java
  6. 3
      jode/jode/flow/ReturnBlock.java
  7. 2
      jode/jode/flow/SwitchBlock.java
  8. 3
      jode/jode/flow/ThrowBlock.java

@ -76,7 +76,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.toString()+")"); writer.println("IF ("+instr.simplify().toString()+")");
writer.tab(); writer.tab();
trueBlock.dumpSource(writer); trueBlock.dumpSource(writer);
writer.untab(); writer.untab();

@ -1013,7 +1013,6 @@ public class FlowBlock {
new CombineIfGotoExpressions(), new CombineIfGotoExpressions(),
new CreateIfThenElseOperator(), new CreateIfThenElseOperator(),
new CreateConstantArray(), new CreateConstantArray(),
new SimplifyExpression()
}; };

@ -97,7 +97,8 @@ public class IfThenElseBlock extends StructuredBlock {
throws java.io.IOException throws java.io.IOException
{ {
boolean needBrace = thenBlock.needsBraces(); boolean needBrace = thenBlock.needsBraces();
writer.println("if ("+cond.toString()+")"+(needBrace?" {":"")); writer.println("if ("+cond.simplify().toString()+")"
+(needBrace?" {":""));
writer.tab(); writer.tab();
thenBlock.dumpSource(writer); thenBlock.dumpSource(writer);
writer.untab(); writer.untab();

@ -70,11 +70,11 @@ public class InstructionBlock extends InstructionContainer {
writer.println writer.println
(((LocalStoreOperator) ((Expression)instr).getOperator()) (((LocalStoreOperator) ((Expression)instr).getOperator())
.getLocalInfo().getType().toString()/*XXX*/ .getLocalInfo().getType().toString()/*XXX*/
+ " " + instr.toString() + ";"); + " " + instr.simplify().toString() + ";");
} else { } else {
if (instr.getType() != Type.tVoid) if (instr.getType() != Type.tVoid)
writer.print("push "); writer.print("push ");
writer.println(instr.toString()+";"); writer.println(instr.simplify().toString()+";");
} }
} }
} }

@ -135,14 +135,16 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
boolean needBrace = bodyBlock.needsBraces(); boolean needBrace = bodyBlock.needsBraces();
switch (type) { switch (type) {
case WHILE: case WHILE:
writer.print("while ("+cond.toString()+")"); writer.print("while ("+cond.simplify().toString()+")");
break; break;
case DOWHILE: case DOWHILE:
writer.print("do"); writer.print("do");
break; break;
case FOR: case FOR:
writer.print("for ("+(init != null ? init.toString() : "") + writer.print("for ("
"; "+cond.toString()+"; "+incr.toString()+")"); +(init != null ? init.simplify().toString() : "")
+"; "+cond.simplify().toString()+"; "
+incr.simplify().toString()+")");
break; break;
} }
writer.println( needBrace?" {": ""); writer.println( needBrace?" {": "");
@ -151,7 +153,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
writer.untab(); writer.untab();
if (type == DOWHILE) if (type == DOWHILE)
writer.println((needBrace?"} ": "")+ writer.println((needBrace?"} ": "")+
"while ("+cond.toString()+")"); "while ("+cond.simplify().toString()+")");
else if (needBrace) else if (needBrace)
writer.println("}"); writer.println("}");
} }

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

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

@ -32,6 +32,7 @@ public class ThrowBlock extends InstructionContainer {
public void dumpInstruction(TabbedPrintWriter writer) public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
writer.println("throw" + (instr == null ? "" : " " + instr) + ";"); writer.println("throw" +
(instr == null ? "" : " " + instr.simplify()) + ";");
} }
} }

Loading…
Cancel
Save