edu.wisc.cs.java
Class CodeLabel

java.lang.Object
  |
  +--edu.wisc.cs.java.Bytecode
        |
        +--edu.wisc.cs.java.CodeLabel

public class CodeLabel
extends Bytecode

Instances of this class represent labels in the bytecode. Any branch or jump instruction may have a label as a target. Additionally, try/catch blocks are marked with labels. A label must have a unique ID string within a method. The byte offset of the label is resolved computed when a classfile is written. Since each CodeLabel has a unique ID, it is sufficient in most cases to compare only the references for distinguishing one label from another. Note that there may be two or more labels at the same program counter within a method, so that destinguishing labels is not sufficient to destinguish program points.


Field Summary
protected  java.lang.String ID
          Stores the label's ID string.
 
Fields inherited from class edu.wisc.cs.java.Bytecode
opcode, params, wide
 
Constructor Summary
CodeLabel()
          Creates a new label with the next identifier in the sequence.
CodeLabel(int pc)
          Creates a new Label with the next ID in the sequence.
CodeLabel(java.lang.String prefix)
          Creates a new label and constructs its ID from the specified prefix.
CodeLabel(java.lang.String prefix, int pc)
          Creates a new label with an initial program counter value and constructs an ID from the specified prefix.
 
Method Summary
 boolean equals(CodeLabel cl)
          Returns true if and only if the two labels have the same identifier.
 java.lang.String getID()
          Returns the string which is the identifier for this label.
 int getNBytes()
          Returns zero.
protected static java.lang.String getNextLabel()
          Returns the next label in the sequence.
 int getParamBytes()
          Returns zero.
 int getTargetPC()
          Returns the byte index of the branch target, as read from a classfile.
 void setTargetPC(int pc)
          Sets a new target pc.
 java.lang.String toString()
          Returns a string representation of a label object.
 void writeTo(java.io.DataOutputStream out)
          This method does nothing.
 
Methods inherited from class edu.wisc.cs.java.Bytecode
getConstantIndex, getOpcode, isWide
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID

protected final java.lang.String ID
Stores the label's ID string.
Constructor Detail

CodeLabel

public CodeLabel()
Creates a new label with the next identifier in the sequence.

CodeLabel

public CodeLabel(java.lang.String prefix)
Creates a new label and constructs its ID from the specified prefix. An underscore character and the next label in the sequence are appended, to guarantee uniqueness.
Parameters:
prefix - a prefix to use as part of the ID string.
pc - the initial position of this label in the bytecode.

CodeLabel

public CodeLabel(int pc)
Creates a new Label with the next ID in the sequence.
Parameters:
pc - the initial position of this label in the bytecode.

CodeLabel

public CodeLabel(java.lang.String prefix,
                 int pc)
Creates a new label with an initial program counter value and constructs an ID from the specified prefix. An underscore character and the next label in the sequence are appended, to guarantee uniqueness.
Parameters:
prefix - a prefix to use as part of the ID string.
pc - the initial position of this label in the bytecode.
Method Detail

getNextLabel

protected static java.lang.String getNextLabel()
Returns the next label in the sequence. The sequence starts with A, B and rolls over at Z to AA, AB, etc.
Returns:
the next label in the sequence.

getID

public java.lang.String getID()
Returns the string which is the identifier for this label.
Returns:
the string which is the identifier for this label.

toString

public java.lang.String toString()
Returns a string representation of a label object.
Overrides:
toString in class Bytecode
Returns:
a string representation of a label object.

equals

public boolean equals(CodeLabel cl)
Returns true if and only if the two labels have the same identifier.
Returns:
true if and only if the two labels have the same identifier.

getTargetPC

public int getTargetPC()
Returns the byte index of the branch target, as read from a classfile.
Returns:
the byte index of the branch target, as read from a classfile.

setTargetPC

public void setTargetPC(int pc)
Sets a new target pc. Note that this does not actually move this label in a sequence of bytecodes. This only updates the pc value stored in this CodeLabel.
Parameters:
pc - a new target pc.

getNBytes

public int getNBytes()
Returns zero. Labels are not part of the bytecode stream.
Overrides:
getNBytes in class Bytecode
Returns:
zero.

getParamBytes

public int getParamBytes()
Returns zero. Labels do not have parameters.
Overrides:
getParamBytes in class Bytecode
Returns:
zero.

writeTo

public void writeTo(java.io.DataOutputStream out)
             throws java.io.IOException
This method does nothing. It is a place holder just in case something actually does attempt to write a label into a bytecode stream.
Overrides:
writeTo in class Bytecode
Parameters:
out - a stream to write nothing to.
Throws:
java.io.IOException - never, but keeps the signatures consistant.