本文整理汇总了Java中org.objectweb.asm.tree.TableSwitchInsnNode类的典型用法代码示例。如果您正苦于以下问题:Java TableSwitchInsnNode类的具体用法?Java TableSwitchInsnNode怎么用?Java TableSwitchInsnNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TableSwitchInsnNode类属于org.objectweb.asm.tree包,在下文中一共展示了TableSwitchInsnNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchTable
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private InsnList dispatchTable(List<LabelNode> extLabels, List<LabelNode> resumptionLabels,
LabelNode errorStateLabel) {
InsnList il = new InsnList();
assert (!extLabels.isEmpty());
ArrayList<LabelNode> labels = new ArrayList<>();
labels.addAll(extLabels);
labels.addAll(resumptionLabels);
LabelNode[] labelArray = labels.toArray(new LabelNode[labels.size()]);
int min = 1 - extLabels.size();
int max = resumptionLabels.size();
il.add(new VarInsnNode(ILOAD, LV_RESUME));
il.add(new TableSwitchInsnNode(min, max, errorStateLabel, labelArray));
return il;
}
示例2: convertTableSwitchInsn
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private void convertTableSwitchInsn(TableSwitchInsnNode insn) {
StackFrame frame = getFrame(insn);
if (units.containsKey(insn)) {
frame.mergeIn(pop());
return;
}
Operand key = popImmediate();
UnitBox dflt = Jimple.v().newStmtBox(null);
List<UnitBox> targets = new ArrayList<UnitBox>(insn.labels.size());
labels.put(insn.dflt, dflt);
for (LabelNode ln : insn.labels) {
UnitBox box = Jimple.v().newStmtBox(null);
targets.add(box);
labels.put(ln, box);
}
TableSwitchStmt tss = Jimple.v().newTableSwitchStmt(key.stackOrValue(),
insn.min, insn.max, targets, dflt);
key.addBox(tss.getKeyBox());
frame.in(key);
frame.boxes(tss.getKeyBox());
setUnit(insn, tss);
}
示例3: visitTableSwitchInsnNode
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private void visitTableSwitchInsnNode(TableSwitchInsnNode node) {
ExpressionStack stack = mState.getActiveStack();
int defaultLabel = stack.getLabelId(node.dflt.getLabel());
Map<Integer, String> labelCaseMap = new HashMap<>();
for (int i = 0; i <= node.max - node.min; i++) {
int labelId = stack.getLabelId(((LabelNode) node.labels.get(i)).getLabel());
String caseKey = String.valueOf(node.min + i);
labelCaseMap.put(labelId, caseKey);
}
labelCaseMap.put(defaultLabel, SwitchExpression.CaseExpression.DEFAULT);
SwitchExpression switchExp = new SwitchExpression(node.getOpcode());
mState.moveNode();
updateSwitchWithCases(switchExp, defaultLabel, labelCaseMap);
stack.push(switchExp);
}
示例4: findJumpTargets
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private static Set<AbstractInsnNode> findJumpTargets(final InsnList instructions) {
final Set<AbstractInsnNode> jumpTargets = new HashSet<AbstractInsnNode>();
final ListIterator<AbstractInsnNode> it = instructions.iterator();
while (it.hasNext()) {
final AbstractInsnNode o = it.next();
if (o instanceof JumpInsnNode) {
jumpTargets.add(((JumpInsnNode) o).label);
} else if (o instanceof TableSwitchInsnNode) {
final TableSwitchInsnNode twn = (TableSwitchInsnNode) o;
jumpTargets.add(twn.dflt);
jumpTargets.addAll(twn.labels);
} else if (o instanceof LookupSwitchInsnNode) {
final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o;
jumpTargets.add(lsn.dflt);
jumpTargets.addAll(lsn.labels);
}
}
return jumpTargets;
}
示例5: registerSwitchInstruction
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private void registerSwitchInstruction(BytecodeInstruction v) {
if (!v.isSwitch())
throw new IllegalArgumentException("expect a switch instruction");
LabelNode defaultLabel = null;
switch (v.getASMNode().getOpcode()) {
case Opcodes.TABLESWITCH:
TableSwitchInsnNode tableSwitchNode = (TableSwitchInsnNode) v.getASMNode();
registerTableSwitchCases(v, tableSwitchNode);
defaultLabel = tableSwitchNode.dflt;
break;
case Opcodes.LOOKUPSWITCH:
LookupSwitchInsnNode lookupSwitchNode = (LookupSwitchInsnNode) v.getASMNode();
registerLookupSwitchCases(v, lookupSwitchNode);
defaultLabel = lookupSwitchNode.dflt;
break;
default:
throw new IllegalStateException(
"expect ASMNode of a switch to either be a LOOKUP- or TABLESWITCH");
}
registerDefaultCase(v, defaultLabel);
}
示例6: instrumentswitchBlock
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
/**
* <p>
* This method finds Switch block in a method and processes it
* </p>.
*
* @param scanStartIndex Start index for the scan
* @param scanEndIndex End index for the scan
*/
private void instrumentswitchBlock(int scanStartIndex,
int scanEndIndex) {
for (scanIndexForswitch = scanStartIndex; scanIndexForswitch <= scanEndIndex; scanIndexForswitch++) {
AbstractInsnNode currentInsnNode = insnArr[scanIndexForswitch];
if (currentInsnNode instanceof TableSwitchInsnNode
&& Opcodes.TABLESWITCH == currentInsnNode.getOpcode()) {
processTableSwitchBlock((TableSwitchInsnNode) currentInsnNode);
} else if (currentInsnNode instanceof LookupSwitchInsnNode
&& Opcodes.LOOKUPSWITCH == currentInsnNode.getOpcode()) {
processLookupSwitchBlock((LookupSwitchInsnNode) currentInsnNode);
}
}
}
示例7: processTableSwitchBlock
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
/**
* <p>
* This method Handled the Switch block of TableSwitchInsnNode type in a
* method
* </p>.
*
* @param currentTableSwithInsn Type of switch block
*/
private void processTableSwitchBlock(
TableSwitchInsnNode currentTableSwithInsn) {
LabelNode currentLabel = currentTableSwithInsn.dflt;
int switchStartIndex = CollectionUtil.getObjectIndexInArray(insnArr,
currentTableSwithInsn);
int switchTargetIndex = CollectionUtil.getObjectIndexInArray(insnArr,
currentLabel);
if (switchTargetIndex > switchStartIndex) {
LOGGER.debug("switch block ended at: " + switchTargetIndex);
switchCount++;
AbstractInsnNode[] ainSwitchBlock = new AbstractInsnNode[] {
currentTableSwithInsn.getPrevious(), currentLabel };
Integer[] lineNumbers = getLineNumbersForSwitchBlock(ainSwitchBlock);
InsnList[] il = getInsnForswitchBlock(switchCount, lineNumbers);
addInsnForswitchBlock(il, ainSwitchBlock);
scanIndexForswitch = switchTargetIndex;
handleTableSwitchCases(currentTableSwithInsn);
}
}
示例8: findJumpTargets
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private static Set<AbstractInsnNode> findJumpTargets(final InsnList instructions) {
final Set<AbstractInsnNode> jumpTargets = new HashSet<>();
final ListIterator<AbstractInsnNode> it = instructions.iterator();
while (it.hasNext()) {
final AbstractInsnNode o = it.next();
if (o instanceof JumpInsnNode) {
jumpTargets.add(((JumpInsnNode) o).label);
} else if (o instanceof TableSwitchInsnNode) {
final TableSwitchInsnNode twn = (TableSwitchInsnNode) o;
jumpTargets.add(twn.dflt);
jumpTargets.addAll(twn.labels);
} else if (o instanceof LookupSwitchInsnNode) {
final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o;
jumpTargets.add(lsn.dflt);
jumpTargets.addAll(lsn.labels);
}
}
return jumpTargets;
}
示例9: handle
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
@Override
public void handle(AbstractInsnNode node) throws IncorrectNodeException {
super.handle(node);
LOG.debug(logNode(node));
if (node instanceof TableSwitchInsnNode) {
visitTableSwitchInsnNode((TableSwitchInsnNode) node);
} else if (node instanceof LookupSwitchInsnNode) {
visitLookupSwitchInsnNode((LookupSwitchInsnNode) node);
} else {
throw new IncorrectNodeException("Incorrect node type, expected switch but was " + node.getClass().getSimpleName());
}
}
示例10: registerTableSwitchCases
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
private void registerTableSwitchCases(BytecodeInstruction v,
TableSwitchInsnNode tableSwitchNode) {
int num = 0;
for (int i = tableSwitchNode.min; i <= tableSwitchNode.max; i++) {
LabelNode targetLabel = (LabelNode) tableSwitchNode.labels.get(num);
Branch switchBranch = createSwitchCaseBranch(v, i, targetLabel);
if (!switchBranch.isSwitchCaseBranch() || !switchBranch.isActualCase())
throw new IllegalStateException(
"expect created branch to be an actual case branch of a switch");
num++;
}
}
示例11: addInstrumentationForDefaultTableswitchCase
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
/**
* <p>
* addInstrumentationForDefaultTableswitchCase
* </p>
*
* @param v
* a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
* @param instrumentation
* a {@link org.objectweb.asm.tree.InsnList} object.
*/
protected void addInstrumentationForDefaultTableswitchCase(BytecodeInstruction v,
InsnList instrumentation) {
if (!v.isTableSwitch())
throw new IllegalArgumentException("tableswitch instruction expected");
// setup instructions
TableSwitchInsnNode toInstrument = (TableSwitchInsnNode) v.getASMNode();
LabelNode caseLabel = new LabelNode();
LabelNode defaultLabel = new LabelNode();
LabelNode endLabel = new LabelNode();
int keySize = (toInstrument.max - toInstrument.min) + 1;
LabelNode[] caseLabels = new LabelNode[keySize];
for (int i = 0; i < keySize; i++)
caseLabels[i] = caseLabel;
TableSwitchInsnNode mySwitch = new TableSwitchInsnNode(toInstrument.min,
toInstrument.max, defaultLabel, caseLabels);
// add instrumentation
addDefaultCaseInstrumentation(v, instrumentation, mySwitch, defaultLabel,
caseLabel, endLabel);
}
示例12: tableSwitch
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
/**
* Generates instructions for a switch table. This does not automatically generate jumps at the end of each default/case statement. It's
* your responsibility to either add the relevant jumps, throws, or returns at each default/case statement, otherwise the code will
* just fall through (which is likely not what you want).
* @param indexInsnList instructions to calculate the index -- must leave an int on the stack
* @param defaultInsnList instructions to execute on default statement -- must leave the stack unchanged
* @param caseStartIdx the number which the case statements start at
* @param caseInsnLists instructions to execute on each case statement -- must leave the stack unchanged
* @return instructions for a table switch
* @throws NullPointerException if any argument is {@code null} or contains {@code null}
* @throws IllegalArgumentException if any numeric argument is {@code < 0}, or if {@code caseInsnLists} is empty
*/
public static InsnList tableSwitch(InsnList indexInsnList, InsnList defaultInsnList, int caseStartIdx, InsnList... caseInsnLists) {
Validate.notNull(defaultInsnList);
Validate.notNull(indexInsnList);
Validate.isTrue(caseStartIdx >= 0);
Validate.notNull(caseInsnLists);
Validate.noNullElements(caseInsnLists);
Validate.isTrue(caseInsnLists.length > 0);
InsnList ret = new InsnList();
LabelNode defaultLabelNode = new LabelNode();
LabelNode[] caseLabelNodes = new LabelNode[caseInsnLists.length];
for (int i = 0; i < caseInsnLists.length; i++) {
caseLabelNodes[i] = new LabelNode();
}
ret.add(indexInsnList);
ret.add(new TableSwitchInsnNode(caseStartIdx, caseStartIdx + caseInsnLists.length - 1, defaultLabelNode, caseLabelNodes));
for (int i = 0; i < caseInsnLists.length; i++) {
LabelNode caseLabelNode = caseLabelNodes[i];
InsnList caseInsnList = caseInsnLists[i];
if (caseInsnList != null) {
ret.add(caseLabelNode);
ret.add(caseInsnList);
}
}
if (defaultInsnList != null) {
ret.add(defaultLabelNode);
ret.add(defaultInsnList);
}
return ret;
}
示例13: visitTableSwitchInsn
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
public CodeBlock visitTableSwitchInsn(final int min, final int max,
final LabelNode defaultHandler, final LabelNode[] handlers)
{
instructionList.add(new TableSwitchInsnNode(min, max, defaultHandler,
handlers));
return this;
}
示例14: tableswitch
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
public CodeBlock tableswitch(final int min, final int max,
final LabelNode defaultLabel, final LabelNode[] cases)
{
instructionList.add(new TableSwitchInsnNode(min, max, defaultLabel,
cases));
return this;
}
示例15: isBranch
import org.objectweb.asm.tree.TableSwitchInsnNode; //导入依赖的package包/类
public static boolean isBranch (final AbstractInsnNode insn) {
final int opcode = insn.getOpcode();
return insn instanceof JumpInsnNode
|| insn instanceof LookupSwitchInsnNode
|| insn instanceof TableSwitchInsnNode
|| opcode == Opcodes.ATHROW || opcode == Opcodes.RET
|| (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN);
}