sofya.graphs.cfg
Class Block

java.lang.Object
  extended by sofya.graphs.Node
      extended by sofya.graphs.cfg.Block
All Implemented Interfaces:
SConstants

public class Block
extends Node

A block represents a basic block of a control flow graph. A basic block is one in which control enters at one end and exits at the other end without being broken. A block knows about its label, type, subtype, offset where it starts, and offset where it ends.

Version:
09/24/2004
Author:
Alex Kinneer

Nested Class Summary
 
Nested classes/interfaces inherited from interface sofya.base.SConstants
SConstants.BlockLabel, SConstants.BlockObjectType, SConstants.BlockSubType, SConstants.BlockType, SConstants.BranchObjectType, SConstants.BranchType, SConstants.EDObjectType, SConstants.TraceObjectType
 
Field Summary
protected  int endOffset
          The end offset of this block.
protected  java.lang.Object endRef
          Reference to a relevant entity at the end of the block.
protected  SConstants.BlockLabel label
          The character label for the node type of this block.
protected  int startOffset
          The start offset of this block.
protected  java.lang.Object startRef
          Reference to a relevant entity at the start of the block.
protected  SConstants.BlockSubType subType
          The integer mapping to the subtype of this block.
protected  SConstants.BlockType type
          The integer mapping to the type of this block.
static Block[] ZL_ARRAY
          Zero-length block array useful for specifying array cast types to methods such Node.getSuccessors(Node[]).
 
Fields inherited from class sofya.graphs.Node
nodeID, predecessors, successors
 
Fields inherited from interface sofya.base.SConstants
DEFAULT_PORT, INST_COMPATIBLE, INST_OLD_UNSUPPORTED, INST_OPT_NORMAL, INST_OPT_SEQUENCE, SIG_CHKALIVE, SIG_ECHO
 
Constructor Summary
Block()
          Creates a new block with fields initialized to default values.
Block(int id)
          Creates a new block with a given ID and all other fields initialized to default values.
Block(int id, SConstants.BlockType type, SConstants.BlockSubType subType)
          Creates a new block with a given ID, type, and sub-type.
Block(int id, SConstants.BlockType type, SConstants.BlockSubType subType, SConstants.BlockLabel label)
          Creates a new block.
Block(int id, SConstants.BlockType type, SConstants.BlockSubType subType, SConstants.BlockLabel label, int startOffset, int endOffset)
          Creates a new block.
Block(int id, SConstants.BlockType type, SConstants.BlockSubType subType, SConstants.BlockLabel label, int startOffset, int endOffset, java.lang.Object startRef, java.lang.Object endRef)
          Creates a new block.
 
Method Summary
 int getEndOffset()
          Gets the end offset for this block.
 java.lang.Object getEndRef()
          Gets the reference to an object of interest associated with the end of the block.
 SConstants.BlockLabel getLabel()
          Gets the block label.
 int getStartOffset()
          Gets the start offset for this block.
 java.lang.Object getStartRef()
          Gets the reference to an object of interest associated with the start of the block.
 SConstants.BlockSubType getSubType()
          Gets the block subtype.
 Block[] getSuccessors(SConstants.BlockType type, SConstants.BlockSubType subType)
          Gets the successors of this block which are of a given type and subtype.
 SConstants.BlockType getType()
          Gets the block type.
 void setEndOffset(int i)
          Sets the end offset variable to the given value.
 void setEndRef(java.lang.Object ref)
          Sets a reference to an object of interest to be associated with the end of the block.
 void setLabel(SConstants.BlockLabel bl)
          Sets the block label to the given value.
 void setStartOffset(int i)
          Sets the start offset variable to the given value.
 void setStartRef(java.lang.Object ref)
          Sets a reference to an object of interest to be associated with the start of the block.
 void setSubType(SConstants.BlockSubType bst)
          Sets the block subtype to the given value.
 void setType(SConstants.BlockType bt)
          Sets the block type to the given value.
 java.lang.String toString()
          Returns a string representation of this block in the form:
(nodeID, (nodeType, nodeSubType, nodeLabel), [startOffset, endOffset]).
 
Methods inherited from class sofya.graphs.Node
addPredecessor, addSuccessor, getID, getPredecessorCount, getPredecessors, getPredecessors, getPredecessorsList, getSuccessorCount, getSuccessors, getSuccessors, getSuccessorsList, main, removePredecessor, removeSuccessor, setID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected SConstants.BlockType type
The integer mapping to the type of this block.


subType

protected SConstants.BlockSubType subType
The integer mapping to the subtype of this block.


label

protected SConstants.BlockLabel label
The character label for the node type of this block.


startOffset

protected int startOffset
The start offset of this block.


endOffset

protected int endOffset
The end offset of this block.


startRef

protected java.lang.Object startRef
Reference to a relevant entity at the start of the block. This field is not preserved when the CFG is written to file.


endRef

protected java.lang.Object endRef
Reference to a relevant entity at the end of the block. This field is not preserved when the CFG is written to file.


ZL_ARRAY

public static final Block[] ZL_ARRAY
Zero-length block array useful for specifying array cast types to methods such Node.getSuccessors(Node[]).

Constructor Detail

Block

public Block()
Creates a new block with fields initialized to default values.


Block

public Block(int id)
Creates a new block with a given ID and all other fields initialized to default values.

Parameters:
id - ID to be associated with the new block.

Block

public Block(int id,
             SConstants.BlockType type,
             SConstants.BlockSubType subType)
Creates a new block with a given ID, type, and sub-type. Other fields are initialized to default values.

Parameters:
id - ID to be associated with the new block.
type - Main type of the new block.
subType - Secondary type of the new block.

Block

public Block(int id,
             SConstants.BlockType type,
             SConstants.BlockSubType subType,
             SConstants.BlockLabel label)
Creates a new block.

Parameters:
id - ID to be associated with the new block.
type - Main type of the new block.
subType - Secondary type of the new block.
label - Label (character) associated with the new block.

Block

public Block(int id,
             SConstants.BlockType type,
             SConstants.BlockSubType subType,
             SConstants.BlockLabel label,
             int startOffset,
             int endOffset)
Creates a new block.

Parameters:
id - ID to be associated with the new block.
type - Main type of the new block.
subType - Secondary type of the new block.
label - Label (character) associated with the new block.
startOffset - Offset of the first bytecode instruction in the new block.
endOffset - Offset of the last bytecode instruction in the new block.

Block

public Block(int id,
             SConstants.BlockType type,
             SConstants.BlockSubType subType,
             SConstants.BlockLabel label,
             int startOffset,
             int endOffset,
             java.lang.Object startRef,
             java.lang.Object endRef)
Creates a new block.

Parameters:
id - ID to be associated with the new block.
type - Main type of the new block.
subType - Secondary type of the new block.
label - Label (character) associated with the new block.
startOffset - Offset of the first bytecode instruction in the new block.
startRef - Reference to an object with some meaningful correlation to the start of the new block; typically used to reference the BCEL instruction handle of the first instruction in the block.
endRef - Reference to an object with some meaningful correlation to the end of the new block; typically used to reference the BCEL instruction handle of the last instruction in the block.
Method Detail

setType

public void setType(SConstants.BlockType bt)
Sets the block type to the given value.

Parameters:
bt - Block type to assign to this block.

getType

public SConstants.BlockType getType()
Gets the block type.

Returns:
The block type to which this block has been set.

setSubType

public void setSubType(SConstants.BlockSubType bst)
Sets the block subtype to the given value.

Parameters:
bst - Block subtype to assign to this block.

getSubType

public SConstants.BlockSubType getSubType()
Gets the block subtype.

Returns:
The block subtype to which this block has been set.

setLabel

public void setLabel(SConstants.BlockLabel bl)
Sets the block label to the given value.

Parameters:
bl - Label which this block should be assigned .

getLabel

public SConstants.BlockLabel getLabel()
Gets the block label.

Returns:
The label which has been assigned to this block.

setStartOffset

public void setStartOffset(int i)
Sets the start offset variable to the given value.

Parameters:
i - Integer representing the new start offset for this block.

getStartOffset

public int getStartOffset()
Gets the start offset for this block.

Returns:
Integer representing the start offset for this block.

setEndOffset

public void setEndOffset(int i)
Sets the end offset variable to the given value.

Parameters:
i - Integer representing the new end offset for this block.

getEndOffset

public int getEndOffset()
Gets the end offset for this block.

Returns:
Integer representing the end offset for this block.

setStartRef

public void setStartRef(java.lang.Object ref)
Sets a reference to an object of interest to be associated with the start of the block.

For example, the CFG class stores a reference to the BCEL InstructionHandle which represents the beginning of the block to improve the performance of the cfInstrumentor.

Parameters:
ref - Reference to object to be associated with the start of the block.

getStartRef

public java.lang.Object getStartRef()
Gets the reference to an object of interest associated with the start of the block.

Returns:
Reference to an object associated with the start of the block.

setEndRef

public void setEndRef(java.lang.Object ref)
Sets a reference to an object of interest to be associated with the end of the block.

For example, the CFG class stores a reference to the BCEL InstructionHandle which represents the end of the block to improve the performance of the cfInstrumentor.

Parameters:
ref - Reference to object to be associated with the end of the block.

getEndRef

public java.lang.Object getEndRef()
Gets the reference to an object of interest associated with the end of the block.

Returns:
Reference to an object associated with the end of the block.

getSuccessors

public Block[] getSuccessors(SConstants.BlockType type,
                             SConstants.BlockSubType subType)
Gets the successors of this block which are of a given type and subtype.

Parameters:
type - Major type that must be matched for a successor to be returned.
subType - Subtype that must be matched for a successor to be returned.
Returns:
An array of this node's successors which are of the given type and subtype, which may have zero elements.

toString

public java.lang.String toString()
Returns a string representation of this block in the form:
(nodeID, (nodeType, nodeSubType, nodeLabel), [startOffset, endOffset]).

Overrides:
toString in class Node
Returns:
This block represented as a string.
See Also:
Node.toString()