Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.flow
Class LoopBlock

java.lang.Object
  extended bynet.sf.jode.flow.StructuredBlock
      extended bynet.sf.jode.flow.LoopBlock
All Implemented Interfaces:
BreakableBlock

public class LoopBlock
extends StructuredBlock
implements BreakableBlock

This is the structured block for an Loop block.


Field Summary
static int DOWHILE
           
static Expression FALSE
           
static int FOR
           
static int POSSFOR
           
static Expression TRUE
           
static int WHILE
           
 
Constructor Summary
LoopBlock(int type, Expression cond)
           
 
Method Summary
 void checkDeclaration(java.util.Set declareSet)
          Check if this is an local store instruction to a not yet declared variable.
 boolean conditionMatches(CombineableOperator combinable)
           
 boolean doTransformations()
          Do simple transformation on the structuredBlock.
 void dumpInstruction(TabbedPrintWriter writer)
          Print the instruction expressing this structured block.
 void dumpSource(TabbedPrintWriter writer)
          Print the source code for this structured block.
 Expression getCondition()
           
 java.util.Set getDeclarables()
           
 java.lang.String getLabel()
          Returns the label of this block and creates a new label, if there wasn't a label previously.
 StructuredBlock getNextBlock(StructuredBlock subBlock)
          Returns the block where the control will normally flow to, when the given sub block is finished (not ignoring the jump after this block).
 FlowBlock getNextFlowBlock(StructuredBlock subBlock)
           
 StructuredBlock[] getSubBlocks()
          Returns all sub block of this structured block.
 int getType()
           
 boolean jumpMayBeChanged()
          Determines if there is a sub block, that flows through to the end of this block.
 void makeDeclaration(java.util.Set done)
          Make the declarations, i.e. initialize the declare variable to correct values.
 VariableStack mapStackToLocal(VariableStack stack)
          This is called after the analysis is completely done.
 void mergeBreakedStack(VariableStack stack)
          Is called by BreakBlock, to tell us what the stack can be after a break.
 void mergeContinueStack(VariableStack stack)
          Is called by BreakBlock, to tell us what the stack can be after a break.
 void removeLocallyDeclareable(java.util.Set set)
          Remove all variables from set, that we can declare inside the loop-block.
 void removeOnetimeLocals()
          This method should remove local variables that are only written and read one time directly after another.
 void removePush()
          This is called after mapStackToLocal to do the stack to local transformation.
 void replaceBreakContinue(BreakableBlock block)
          Replace all breaks to block with a continue to this.
 boolean replaceSubBlock(StructuredBlock oldBlock, StructuredBlock newBlock)
          Replaces the given sub block with a new block.
 void setBody(StructuredBlock body)
           
 void setBreaked()
          Is called by BreakBlock, to tell us that this block is breaked.
 void setCondition(Expression cond)
           
 void setInit(InstructionBlock initBlock)
           
 void setType(int type)
           
 void simplify()
           
 
Methods inherited from class net.sf.jode.flow.StructuredBlock
appendBlock, checkConsistent, contains, copyJump, fillInGenSet, flowMayBeChanged, getNextBlock, getNextFlowBlock, isEmpty, isSingleExit, moveJump, needsBraces, prependBlock, propagateUsage, removeBlock, removeJump, replace, setFlowBlock, setJump, setSuccessors, swapJump, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WHILE

public static final int WHILE
See Also:
Constant Field Values

DOWHILE

public static final int DOWHILE
See Also:
Constant Field Values

FOR

public static final int FOR
See Also:
Constant Field Values

POSSFOR

public static final int POSSFOR
See Also:
Constant Field Values

TRUE

public static final Expression TRUE

FALSE

public static final Expression FALSE
Constructor Detail

LoopBlock

public LoopBlock(int type,
                 Expression cond)
Method Detail

getNextBlock

public StructuredBlock getNextBlock(StructuredBlock subBlock)
Returns the block where the control will normally flow to, when the given sub block is finished (not ignoring the jump after this block). (This is overwritten by SequentialBlock and SwitchBlock). If this isn't called with a direct sub block, the behaviour is undefined, so take care.

Overrides:
getNextBlock in class StructuredBlock
Returns:
null, if the control flows to another FlowBlock.

getNextFlowBlock

public FlowBlock getNextFlowBlock(StructuredBlock subBlock)
Overrides:
getNextFlowBlock in class StructuredBlock

setBody

public void setBody(StructuredBlock body)

setInit

public void setInit(InstructionBlock initBlock)

conditionMatches

public boolean conditionMatches(CombineableOperator combinable)

getCondition

public Expression getCondition()

setCondition

public void setCondition(Expression cond)

getType

public int getType()

setType

public void setType(int type)

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.

getSubBlocks

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

Overrides:
getSubBlocks in class StructuredBlock

removeLocallyDeclareable

public void removeLocallyDeclareable(java.util.Set set)
Remove all variables from set, that we can declare inside the loop-block. This is the initializer for for-blocks.


getDeclarables

public java.util.Set getDeclarables()
Overrides:
getDeclarables in class StructuredBlock

checkDeclaration

public void checkDeclaration(java.util.Set declareSet)
Check if this is an local store instruction to a not yet declared variable. In that case mark this as declaration and return the variable.


makeDeclaration

public void makeDeclaration(java.util.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.

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

dumpSource

public void dumpSource(TabbedPrintWriter writer)
                throws java.io.IOException
Description copied from class: StructuredBlock
Print the source code for this structured block. This handles everything that is unique for all structured blocks and calls dumpInstruction afterwards.

Overrides:
dumpSource in class StructuredBlock
Parameters:
writer - The tabbed print writer, where we print to.
Throws:
java.io.IOException

dumpInstruction

public void dumpInstruction(TabbedPrintWriter writer)
                     throws java.io.IOException
Description copied from class: StructuredBlock
Print the instruction expressing this structured block.

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

getLabel

public java.lang.String getLabel()
Returns the label of this block and creates a new label, if there wasn't a label previously.

Specified by:
getLabel in interface BreakableBlock

setBreaked

public void setBreaked()
Is called by BreakBlock, to tell us that this block is breaked.

Specified by:
setBreaked in interface BreakableBlock

mapStackToLocal

public VariableStack mapStackToLocal(VariableStack stack)
This is called after the analysis is completely done. It will remove all PUSH/stack_i expressions, (if the bytecode is correct).

Overrides:
mapStackToLocal in class StructuredBlock
Parameters:
stack - the stack at begin of the block
Returns:
null if there is no way to the end of this block, otherwise the stack after the block has executed.

mergeContinueStack

public void mergeContinueStack(VariableStack stack)
Is called by BreakBlock, to tell us what the stack can be after a break.

Returns:
false if the stack is inconsistent.

mergeBreakedStack

public void mergeBreakedStack(VariableStack stack)
Is called by BreakBlock, to tell us what the stack can be after a break.

Specified by:
mergeBreakedStack in interface BreakableBlock
Parameters:
stack - the stack at the break.
Returns:
false if the stack is inconsistent.

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

removeOnetimeLocals

public void removeOnetimeLocals()
This method should remove local variables that are only written and read one time directly after another.
This is especially important for stack locals, that are created when there are unusual swap or dup instructions, but also makes inlined functions more pretty (but not that close to the bytecode).

Overrides:
removeOnetimeLocals in class StructuredBlock

replaceBreakContinue

public void replaceBreakContinue(BreakableBlock block)
Replace all breaks to block with a continue to this.

Parameters:
block - the breakable block where the breaks originally breaked to (Have a break now, if you didn't understand that :-).

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.

Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.