net.sf.jode.flow
Class IfThenElseBlock

java.lang.Object
  extended by net.sf.jode.flow.StructuredBlock
      extended by net.sf.jode.flow.IfThenElseBlock

public class IfThenElseBlock
extends StructuredBlock

An IfThenElseBlock is the structured block representing an if instruction. The else part may be null.


Constructor Summary
IfThenElseBlock(Expression cond)
          Creates a new if then else block.
 
Method Summary
 boolean doTransformations()
          Do simple transformation on the structuredBlock.
 void dumpInstruction(TabbedPrintWriter writer)
          Print the source code for this structured block.
 Expression getCondition()
          Gets the condition.
 Set getDeclarables()
           
 StructuredBlock getElseBlock()
           
 StructuredBlock[] getSubBlocks()
          Returns all sub block of this structured block.
 StructuredBlock getThenBlock()
           
 boolean hasElse()
           
 boolean jumpMayBeChanged()
          Determines if there is a sub block, that flows through to the end of this block.
 void makeDeclaration(Set done)
          Make the declarations, i.e.
 VariableStack mapStackToLocal(VariableStack stack)
          This does take the instr into account and modifies stack accordingly.
 void removePush()
          This is called after mapStackToLocal to do the stack to local transformation.
 boolean replaceSubBlock(StructuredBlock oldBlock, StructuredBlock newBlock)
          Replaces the given sub block with a new block.
 void setElseBlock(StructuredBlock elseBlock)
          Sets the else block.
 void setThenBlock(StructuredBlock thenBlock)
          Sets the then block.
 void simplify()
           
 
Methods inherited from class net.sf.jode.flow.StructuredBlock
appendBlock, checkConsistent, contains, copyJump, dumpSource, fillInGenSet, flowMayBeChanged, getBCELInstructions, getBytecodeInstructions, getNextBlock, getNextBlock, getNextFlowBlock, getNextFlowBlock, isEmpty, isSingleExit, moveJump, needsBraces, prependBlock, propagateUsage, removeBlock, removeJump, removeOnetimeLocals, replace, setFlowBlock, setJump, setSuccessors, swapJump, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfThenElseBlock

public IfThenElseBlock(Expression cond)
Creates a new if then else block. The method setThenBlock must be called shortly after the creation.

Method Detail

getCondition

public Expression getCondition()
Gets the condition. The expression returned has boolean type.


setThenBlock

public void setThenBlock(StructuredBlock thenBlock)
Sets the then block.

Parameters:
thenBlock - the then block, must be non null.

getThenBlock

public StructuredBlock getThenBlock()

setElseBlock

public void setElseBlock(StructuredBlock elseBlock)
Sets the else block.

Parameters:
elseBlock - the else block

getElseBlock

public StructuredBlock getElseBlock()

hasElse

public boolean hasElse()

replaceSubBlock

public boolean replaceSubBlock(StructuredBlock oldBlock,
                               StructuredBlock newBlock)
Replaces the given sub block with a new block.

Overrides:
replaceSubBlock in class StructuredBlock
Parameters:
oldBlock - the old sub block.
newBlock - the new sub block.
Returns:
false, if oldBlock wasn't a direct sub block.

mapStackToLocal

public VariableStack mapStackToLocal(VariableStack stack)
This does take the instr into account and modifies stack accordingly. It then calls super.mapStackToLocal.

Overrides:
mapStackToLocal in class StructuredBlock
Parameters:
stack - the stack before the instruction is called
Returns:
stack the stack afterwards.

removePush

public void removePush()
Description copied from class: StructuredBlock
This is called after mapStackToLocal to do the stack to local transformation.

Overrides:
removePush in class StructuredBlock

getDeclarables

public Set getDeclarables()
Overrides:
getDeclarables in class StructuredBlock

makeDeclaration

public void makeDeclaration(Set done)
Make the declarations, i.e. initialize the declare variable to correct values. This will declare every variable that is marked as used, but not done.
This will now also combine locals, that use the same slot, have compatible types and are declared in the same block.

Overrides:
makeDeclaration in class StructuredBlock
Parameters:
done - The set of the already declare variables.

dumpInstruction

public void dumpInstruction(TabbedPrintWriter writer)
                     throws IOException
Print the source code for this structured block. This may be called only once, because it remembers which local variables were declared.

Specified by:
dumpInstruction in class StructuredBlock
Parameters:
writer - The tabbed print writer, where we print to.
Throws:
IOException

getSubBlocks

public StructuredBlock[] getSubBlocks()
Returns all sub block of this structured block.

Overrides:
getSubBlocks in class StructuredBlock

jumpMayBeChanged

public boolean jumpMayBeChanged()
Determines if there is a sub block, that flows through to the end of this block. If this returns true, you know that jump is null.

Overrides:
jumpMayBeChanged in class StructuredBlock
Returns:
true, if the jump may be safely changed.

simplify

public void simplify()
Overrides:
simplify in class StructuredBlock

doTransformations

public boolean doTransformations()
Description copied from class: StructuredBlock
Do simple transformation on the structuredBlock.

Overrides:
doTransformations in class StructuredBlock
Returns:
true, if some transformation was done.