com.claritysys.jvm.builder
Class CodeBlock

java.lang.Object
  extended by com.claritysys.jvm.builder.CodeBlock
Direct Known Subclasses:
CatchBlock, ElseBlock, IfBlock, TryBlock

public class CodeBlock
extends java.lang.Object

Represents a code block, which defines a scope for local variables.

A block can be a a scope block, an If/Else block, or a Try/Catch/Finally block.

Variables allocated within a block go out of scope when the block ends and can have their indexes reused.


Field Summary
protected  ByteArray code
          The byte[] being written to.
protected  CodeBuilder codeBuilder
          The code builder.
protected  Label endLabel
          Linked list of labels to be defined at blockEnd().
protected  int endPC
          The PC where the block was ended.
protected  LocalVariable headVar
          Linked list of scoped variables.
protected  int startPC
          The PC where the block was started.
protected  CodeBlock surroundingBlock
          Link to surrounding block.
protected  LocalVariable undeclaredLocals
          List of undeclared LocalVariable.
 
Constructor Summary
CodeBlock(CodeBuilder cb)
          Create a new CodeBlock.
 
Method Summary
 void addLocal(LocalVariable local)
          Add a local variable to this block's scope, to be declared in the containing CfMethod once the block is ended.
 void clearEndLabel()
          Clear the end label (set it to null).
 void end()
          End the block, noting the endPC and defining any labels specified to be defined at block end.
 Label getEndLabel()
          Return a label that will be defined when the block ends.
 int getEndPC()
           
 CfMethod getMethod()
          Get the method builder.
 int getStartPC()
           
 CodeBlock getSurroundingBlock()
          Return the surrounding block.
 void setCodeBuilder(CodeBuilder cb)
          Set the CodeBuilder, in case this block was pooled.
 void setEndLabel(Label end)
          Set the end label.
 void setSurroundingBlock(CodeBlock sb)
          Make the given block the surrounding block.
 void start()
          Formally start the block, noting the startPC.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startPC

protected int startPC
The PC where the block was started.


endPC

protected int endPC
The PC where the block was ended.


codeBuilder

protected CodeBuilder codeBuilder
The code builder.


code

protected ByteArray code
The byte[] being written to.


headVar

protected LocalVariable headVar
Linked list of scoped variables.


endLabel

protected Label endLabel
Linked list of labels to be defined at blockEnd().


surroundingBlock

protected CodeBlock surroundingBlock
Link to surrounding block.


undeclaredLocals

protected LocalVariable undeclaredLocals
List of undeclared LocalVariable. They are declared, because the user declared them within the code builder, but they haven't yet been declared in the CfMethod, because until the block ends it doesn't know the length of the local variable.

Constructor Detail

CodeBlock

public CodeBlock(CodeBuilder cb)
Create a new CodeBlock.

Method Detail

setCodeBuilder

public void setCodeBuilder(CodeBuilder cb)
Set the CodeBuilder, in case this block was pooled.


getMethod

public CfMethod getMethod()
Get the method builder.


getSurroundingBlock

public CodeBlock getSurroundingBlock()
Return the surrounding block.


setSurroundingBlock

public void setSurroundingBlock(CodeBlock sb)
Make the given block the surrounding block.


getEndLabel

public Label getEndLabel()
Return a label that will be defined when the block ends.

Note that the block may not have begun yet.


setEndLabel

public void setEndLabel(Label end)
Set the end label.


clearEndLabel

public void clearEndLabel()
Clear the end label (set it to null).


start

public void start()
Formally start the block, noting the startPC.


end

public void end()
End the block, noting the endPC and defining any labels specified to be defined at block end.


getStartPC

public int getStartPC()

getEndPC

public int getEndPC()

addLocal

public void addLocal(LocalVariable local)
Add a local variable to this block's scope, to be declared in the containing CfMethod once the block is ended.



Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.