org.apache.bcel.generic

Class Select

Implemented Interfaces:
Cloneable, InstructionTargeter, Serializable, StackProducer, VariableLengthInstruction
Known Direct Subclasses:
LOOKUPSWITCH, TABLESWITCH

public abstract class Select
extends BranchInstruction
implements VariableLengthInstruction, StackProducer

Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions.

We use our super's target property as the default target.

Version:
$Id: Select.java 386056 2006-03-15 11:31:56Z tcurdt $
Author:
M. Dahm
See Also:
LOOKUPSWITCH, TABLESWITCH, InstructionList

Field Summary

protected int
fixed_length
protected int[]
indices
protected int[]
match
protected int
match_length
protected int
padding
protected InstructionHandle[]
targets

Fields inherited from class org.apache.bcel.generic.BranchInstruction

index, position, target

Fields inherited from class org.apache.bcel.generic.Instruction

cmp, length, opcode

Constructor Summary

Select()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction().
Select(short opcode, int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget)
(Match, target) pairs for switch.

Method Summary

protected Object
clone()
boolean
containsTarget(InstructionHandle ih)
(package private) void
dispose()
Inform targets that they're not targeted anymore.
void
dump(DataOutputStream out)
Dump instruction as byte code to stream out.
int[]
getIndices()
int[]
getMatchs()
InstructionHandle[]
getTargets()
protected void
initFromFile(ByteSequence bytes, boolean wide)
Read needed data (e.g.
void
setTarget(int i, InstructionHandle target)
Set branch target for `i'th case
String
toString(boolean verbose)
protected int
updatePosition(int offset, int max_offset)
Since this is a variable length instruction, it may shift the following instructions which then need to update their position.
void
updateTarget(InstructionHandle old_ih, InstructionHandle new_ih)

Methods inherited from class org.apache.bcel.generic.BranchInstruction

containsTarget, dispose, dump, getIndex, getTarget, getTargetOffset, getTargetOffset, initFromFile, notifyTarget, setTarget, toString, updatePosition, updateTarget

Methods inherited from class org.apache.bcel.generic.Instruction

accept, className, consumeStack, copy, dispose, dump, equals, getComparator, getLength, getName, getOpcode, initFromFile, produceStack, readInstruction, setComparator, setOpcode, toString, toString, toString

Field Details

fixed_length

protected int fixed_length

indices

protected int[] indices

match

protected int[] match

match_length

protected int match_length

padding

protected int padding

targets

protected InstructionHandle[] targets

Constructor Details

Select

(package private)  Select()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction(). Not to be used otherwise.

Select

(package private)  Select(short opcode,
                          int[] match,
                          InstructionHandle[] targets,
                          InstructionHandle defaultTarget)
(Match, target) pairs for switch. `Match' and `targets' must have the same length of course.
Parameters:
match - array of matching values
targets - instruction targets
defaultTarget - default instruction target

Method Details

clone

protected Object clone()
            throws CloneNotSupportedException

containsTarget

public boolean containsTarget(InstructionHandle ih)
Specified by:
containsTarget in interface InstructionTargeter
Overrides:
containsTarget in interface BranchInstruction
Returns:
true, if ih is target of this instruction

dispose

(package private)  void dispose()
Inform targets that they're not targeted anymore.
Overrides:
dispose in interface BranchInstruction

dump

public void dump(DataOutputStream out)
            throws IOException
Dump instruction as byte code to stream out.
Overrides:
dump in interface BranchInstruction
Parameters:
out - Output stream

getIndices

public int[] getIndices()
Returns:
array of match target offsets

getMatchs

public int[] getMatchs()
Returns:
array of match indices

getTargets

public InstructionHandle[] getTargets()
Returns:
array of match targets

initFromFile

protected void initFromFile(ByteSequence bytes,
                            boolean wide)
            throws IOException
Read needed data (e.g. index) from file.
Overrides:
initFromFile in interface BranchInstruction

setTarget

public void setTarget(int i,
                      InstructionHandle target)
Set branch target for `i'th case

toString

public String toString(boolean verbose)
Overrides:
toString in interface BranchInstruction
Returns:
mnemonic for instruction

updatePosition

protected int updatePosition(int offset,
                             int max_offset)
Since this is a variable length instruction, it may shift the following instructions which then need to update their position. Called by InstructionList.setPositions when setting the position for every instruction. In the presence of variable length instructions `setPositions' performs multiple passes over the instruction list to calculate the correct (byte) positions and offsets by calling this function.
Overrides:
updatePosition in interface BranchInstruction
Parameters:
offset - additional offset caused by preceding (variable length) instructions
max_offset - the maximum offset that may be caused by these instructions
Returns:
additional offset caused by possible change of this instruction's length

updateTarget

public void updateTarget(InstructionHandle old_ih,
                         InstructionHandle new_ih)
Specified by:
updateTarget in interface InstructionTargeter
Overrides:
updateTarget in interface BranchInstruction
Parameters:
old_ih - old target
new_ih - new target