Top Description Fields Constructors Methods
org.aspectj.apache.bcel.generic

public final Class SwitchBuilder

extends Object
Class Inheritance

SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or TABLESWITCH instruction, depending on whether the match values (int[]) can be sorted with no gaps between the numbers.
Author
M. Dahm
Version
$Id: SwitchBuilder.java,v 1.2 2008/05/28 23:52:57 aclement Exp $

Field Summary

Modifier and TypeField and Description
private InstructionSelect
private int[]
private int
private InstructionHandle[]

Constructor Summary

AccessConstructor and Description
public
SwitchBuilder(int[]
array of match values (case 2: ... case 7: ..., etc.)
match
,
InstructionHandle[]
the instructions to be branched to for each case
targets
,
InstructionHandle
the default target
target
,
int
maximum gap that may between case branches
max_gap
)

Template for switch() constructs.

public
SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target)

Method Summary

Modifier and TypeMethod and Description
private final void
fillup(int max_gap, InstructionHandle target)

public final InstructionSelect
private final boolean

Returns:

match is sorted in ascending order with no gap bigger than max_gap?
matchIsOrdered
(int max_gap)

private final void
sort(int l, int r)

Sort match and targets array with QuickSort.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instructionback to summary
private InstructionSelect instruction
matchback to summary
private int[] match
match_lengthback to summary
private int match_length
targetsback to summary
private InstructionHandle[] targets

Constructor Detail

SwitchBuilderback to summary
public SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target, int max_gap)

Template for switch() constructs. If the match array can be sorted in ascending order with gaps no larger than max_gap between the numbers, a TABLESWITCH instruction is generated, and a LOOKUPSWITCH otherwise. The former may be more efficient, but needs more space. Note, that the key array always will be sorted, though we leave the original arrays unaltered.

Parameters
match:int[]

array of match values (case 2: ... case 7: ..., etc.)

targets:InstructionHandle[]

the instructions to be branched to for each case

target:InstructionHandle

the default target

max_gap:int

maximum gap that may between case branches

SwitchBuilderback to summary
public SwitchBuilder(int[] match, InstructionHandle[] targets, InstructionHandle target)

Method Detail

fillupback to summary
private final void fillup(int max_gap, InstructionHandle target)
getInstructionback to summary
public final InstructionSelect getInstruction()
matchIsOrderedback to summary
private final boolean matchIsOrdered(int max_gap)
Returns:boolean

match is sorted in ascending order with no gap bigger than max_gap?

sortback to summary
private final void sort(int l, int r)

Sort match and targets array with QuickSort.