Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.code

public final Class SwitchData

extends VariableSizeInsn
Class Inheritance
Imports
org.droidparts.dexmaker.dx.io.Opcodes, org.droidparts.dexmaker.dx.rop.code.RegisterSpecList, .SourcePosition, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .Hex, .IntList

Pseudo-instruction which holds switch data. The switch data is a map of values to target addresses, and this class writes the data in either a "packed" or "sparse" form.

Field Summary

Modifier and TypeField and Description
private final IntList
cases

non-null; sorted list of switch cases (keys)

private final boolean
packed

whether the output table will be packed (vs. sparse)

private final CodeAddress[]
targets

non-null; corresponding list of code addresses; the branch target for each case

private final CodeAddress
user

non-null; address representing the instruction that uses this instance

Constructor Summary

AccessConstructor and Description
public
SwitchData(SourcePosition
non-null; source position
position
,
CodeAddress
non-null; address representing the instruction that uses this instance
user
,
IntList
non-null; sorted list of switch cases (keys)
cases
,
CodeAddress[]
non-null; corresponding list of code addresses; the branch target for each case
targets
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
protected String
argString()

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.argString.

Gets the string form for any arguments to this instance.
public int
codeSize()

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.codeSize.

Gets the size of this instruction, in 16-bit code units.
public boolean

Returns:

true iff the data is to be packed
isPacked
()

Returns whether or not this instance's data will be output as packed.

protected String
listingString0(boolean
whether to include an explicit notation of constant pool indices
noteIndices
)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.listingString0.

Helper for listingString, which returns the string form of this instance suitable for inclusion in a human-oriented listing dump, not including the instruction address and without respect for any output formatting.
private static long

Returns:

>= -1; the packed table size or -1 if the cases couldn't possibly be represented as a packed table
packedCodeSize
(IntList
non-null; sorted list of cases
cases
)

Gets the size of a packed table for the given cases, in 16-bit code units.

private static boolean

Returns:

true iff the table encoding the cases should be packed
shouldPack
(IntList
non-null; sorted list of cases
cases
)

Determines whether the given list of cases warrant being packed.

private static long

Returns:

> 0; the sparse table size
sparseCodeSize
(IntList
non-null; sorted list of cases
cases
)

Gets the size of a sparse table for the given cases, in 16-bit code units.

public DalvInsn
withRegisters(RegisterSpecList
non-null; new register list
registers
)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.withRegisters.

Returns an instance that is just like this one, except that the register list is replaced by the given one, and its address is reset.
public void
writeTo(AnnotatedOutput
non-null; where to write to
out
)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.writeTo.

Writes this instance to the given output.
Inherited from org.droidparts.dexmaker.dx.dex.code.VariableSizeInsn:
withOpcodewithRegisterOffset

Field Detail

casesback to summary
private final IntList cases

non-null; sorted list of switch cases (keys)

packedback to summary
private final boolean packed

whether the output table will be packed (vs. sparse)

targetsback to summary
private final CodeAddress[] targets

non-null; corresponding list of code addresses; the branch target for each case

userback to summary
private final CodeAddress user

non-null; address representing the instruction that uses this instance

Constructor Detail

SwitchDataback to summary
public SwitchData(SourcePosition position, CodeAddress user, IntList cases, CodeAddress[] targets)

Constructs an instance. The output address of this instance is initially unknown (-1).

Parameters
position:SourcePosition

non-null; source position

user:CodeAddress

non-null; address representing the instruction that uses this instance

cases:IntList

non-null; sorted list of switch cases (keys)

targets:CodeAddress[]

non-null; corresponding list of code addresses; the branch target for each case

Method Detail

argStringback to summary
protected String argString()

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.argString.

Doc from org.droidparts.dexmaker.dx.dex.code.DalvInsn.argString.

Gets the string form for any arguments to this instance. Subclasses must override this.

Returns:String

null-ok; the string version of any arguments or null if there are none

Annotations
@Override
codeSizeback to summary
public int codeSize()

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.codeSize.

Doc from org.droidparts.dexmaker.dx.dex.code.DalvInsn.codeSize.

Gets the size of this instruction, in 16-bit code units.

Returns:int

>= 0; the code size of this instruction

Annotations
@Override
isPackedback to summary
public boolean isPacked()

Returns whether or not this instance's data will be output as packed.

Returns:boolean

true iff the data is to be packed

listingString0back to summary
protected String listingString0(boolean noteIndices)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.listingString0.

Doc from org.droidparts.dexmaker.dx.dex.code.DalvInsn.listingString0.

Helper for listingString, which returns the string form of this instance suitable for inclusion in a human-oriented listing dump, not including the instruction address and without respect for any output formatting. This method should return null if this instance should not appear in a listing.

Parameters
noteIndices:boolean

whether to include an explicit notation of constant pool indices

Returns:String

null-ok; the listing string

Annotations
@Override
packedCodeSizeback to summary
private static long packedCodeSize(IntList cases)

Gets the size of a packed table for the given cases, in 16-bit code units.

Parameters
cases:IntList

non-null; sorted list of cases

Returns:long

>= -1; the packed table size or -1 if the cases couldn't possibly be represented as a packed table

shouldPackback to summary
private static boolean shouldPack(IntList cases)

Determines whether the given list of cases warrant being packed.

Parameters
cases:IntList

non-null; sorted list of cases

Returns:boolean

true iff the table encoding the cases should be packed

sparseCodeSizeback to summary
private static long sparseCodeSize(IntList cases)

Gets the size of a sparse table for the given cases, in 16-bit code units.

Parameters
cases:IntList

non-null; sorted list of cases

Returns:long

> 0; the sparse table size

withRegistersback to summary
public DalvInsn withRegisters(RegisterSpecList registers)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.withRegisters.

Doc from org.droidparts.dexmaker.dx.dex.code.DalvInsn.withRegisters.

Returns an instance that is just like this one, except that the register list is replaced by the given one, and its address is reset.

Parameters
registers:RegisterSpecList

non-null; new register list

Returns:DalvInsn

non-null; an appropriately-constructed instance

Annotations
@Override
writeToback to summary
public void writeTo(AnnotatedOutput out)

Implements abstract org.droidparts.dexmaker.dx.dex.code.DalvInsn.writeTo.

Doc from org.droidparts.dexmaker.dx.dex.code.DalvInsn.writeTo.

Writes this instance to the given output. This method should never annotate the output.

Parameters
out:AnnotatedOutput

non-null; where to write to

Annotations
@Override