public virtual void SetTableSwitchJump(int switchStart, int caseIndex, int jumpTarget)
{
if (!(0 <= jumpTarget && jumpTarget <= itsCodeBufferTop))
{
throw new ArgumentException("Bad jump target: " + jumpTarget);
}
if (!(caseIndex >= -1))
{
throw new ArgumentException("Bad case index: " + caseIndex);
}
int padSize = 3 & ~switchStart;
// == 3 - switchStart % 4
int caseOffset;
if (caseIndex < 0)
{
// default label
caseOffset = switchStart + 1 + padSize;
}
else
{
caseOffset = switchStart + 1 + padSize + 4 * (3 + caseIndex);
}
if (!(0 <= switchStart && switchStart <= itsCodeBufferTop - 4 * 4 - padSize - 1))
{
throw new ArgumentException(switchStart + " is outside a possible range of tableswitch" + " in already generated code");
}
if ((unchecked((int)(0xFF)) & itsCodeBuffer[switchStart]) != ByteCode.TABLESWITCH)
{
throw new ArgumentException(switchStart + " is not offset of tableswitch statement");
}
if (!(0 <= caseOffset && caseOffset + 4 <= itsCodeBufferTop))
{
// caseIndex >= -1 does not guarantee that caseOffset >= 0 due
// to a possible overflow.
throw new ClassFileWriter.ClassFileFormatException("Too big case index: " + caseIndex);
}
// ALERT: perhaps check against case bounds?
PutInt32(jumpTarget - switchStart, itsCodeBuffer, caseOffset);
}