本文整理汇总了Java中org.objectweb.asm.tree.LookupSwitchInsnNode类的典型用法代码示例。如果您正苦于以下问题:Java LookupSwitchInsnNode类的具体用法?Java LookupSwitchInsnNode怎么用?Java LookupSwitchInsnNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LookupSwitchInsnNode类属于org.objectweb.asm.tree包,在下文中一共展示了LookupSwitchInsnNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitLookupSwitchInsnNode
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
private void visitLookupSwitchInsnNode(LookupSwitchInsnNode node) {
ExpressionStack stack = mState.getActiveStack();
int defaultLabel = stack.getLabelId(node.dflt.getLabel());
Map<Integer, String> labelCaseMap = new HashMap<>();
for (int i = 0; i < node.labels.size(); i++) {
int labelId = stack.getLabelId(((LabelNode) node.labels.get(i)).getLabel());
String caseKey = String.valueOf(node.keys.get(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);
}
示例2: findJumpTargets
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的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;
}
示例3: registerSwitchInstruction
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的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);
}
示例4: instrumentswitchBlock
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的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);
}
}
}
示例5: findJumpTargets
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的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;
}
示例6: build
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
private void build(LookupSwitchInsnNode insn, IRBuilder builder) {
processLocalVariablesAtControlEdge(insn, builder);
int[] keys = new int[insn.keys.size()];
for (int i = 0; i < insn.keys.size(); i++) {
keys[i] = (int) insn.keys.get(i);
}
buildSwitch(insn.dflt, insn.labels, keys, builder);
}
示例7: switchStatement
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
public MethodDefinition switchStatement(String defaultCase, List<CaseStatement> cases)
{
LabelNode defaultLabel = getLabel(defaultCase);
int[] keys = new int[cases.size()];
LabelNode[] labels = new LabelNode[cases.size()];
for (int i = 0; i < cases.size(); i++) {
keys[i] = cases.get(i).getKey();
labels[i] = getLabel(cases.get(i).getLabel());
}
instructionList.add(new LookupSwitchInsnNode(defaultLabel, keys, labels));
return this;
}
示例8: convertLookupSwitchInsn
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
private void convertLookupSwitchInsn(LookupSwitchInsnNode 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);
}
List<IntConstant> keys = new ArrayList<IntConstant>(insn.keys.size());
for (Integer i : insn.keys)
keys.add(IntConstant.v(i));
LookupSwitchStmt lss = Jimple.v().newLookupSwitchStmt(key.stackOrValue(),
keys, targets, dflt);
key.addBox(lss.getKeyBox());
frame.in(key);
frame.boxes(lss.getKeyBox());
setUnit(insn, lss);
}
示例9: handle
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的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: testSwitch
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
private void testSwitch() {
InsnList insnList = new InsnList();
LabelNode defaultLabelNode = new LabelNode(new Label());
LabelNode[] nodes = new LabelNode[2];
nodes[0] = new LabelNode(new Label());
nodes[1] = new LabelNode(new Label());
nodes[0].accept(ga);
ga.push(42);
nodes[1].accept(ga);
ga.push(43);
LookupSwitchInsnNode lookupSwitchInsnNode = new LookupSwitchInsnNode(defaultLabelNode, new int[]{1, 2}, nodes);
insnList.add(lookupSwitchInsnNode);
insnList.accept(ga);
}
示例11: registerLookupSwitchCases
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
private void registerLookupSwitchCases(BytecodeInstruction v,
LookupSwitchInsnNode lookupSwitchNode) {
for (int i = 0; i < lookupSwitchNode.keys.size(); i++) {
LabelNode targetLabel = (LabelNode) lookupSwitchNode.labels.get(i);
Branch switchBranch = createSwitchCaseBranch(v,
(Integer) lookupSwitchNode.keys.get(i),
targetLabel);
if (!switchBranch.isSwitchCaseBranch() || !switchBranch.isActualCase())
throw new IllegalStateException(
"expect created branch to be an actual case branch of a switch");
}
}
示例12: handleLookupSwitchCases
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
/**
* <p>
* This method Handled the Switch cases of LookupSwitchInsnNode type in a
* method
* </p>.
*
* @param currentTableSwithInsn Type of switch block
*/
@SuppressWarnings("unchecked")
private void handleLookupSwitchCases(
LookupSwitchInsnNode currentTableSwithInsn) {
List<AbstractInsnNode> caseList = currentTableSwithInsn.labels;
LabelNode currentLabel = currentTableSwithInsn.dflt;
List<Integer> casekeys = currentTableSwithInsn.keys;
int totalcaselogs = casekeys.size() * 2;
String[] logMsgs = new String[totalcaselogs];
int[] caseValues = new int[totalcaselogs];
AbstractInsnNode abstractCaseInsnNode[] = new AbstractInsnNode[totalcaselogs];
int index = 0;
for (int i = 0; i < casekeys.size(); i++) {
abstractCaseInsnNode[index] = caseList.get(i);
caseValues[index] = casekeys.get(i);
caseValues[index + 1] = casekeys.get(i);
AbstractInsnNode nextNode = lookNode(caseList,
abstractCaseInsnNode[index], currentLabel);
abstractCaseInsnNode[index + 1] = nextNode;
logMsgs[index] = InstrumentationMessageLoader
.getMessage(MessageConstants.MSG_IN_SWITCHCASE);
logMsgs[index + 1] = InstrumentationMessageLoader
.getMessage(MessageConstants.MSG_OUT_SWITCHCASE);
index += 2;
}
Integer[] lineNumbers = getLineNumbersForSwitchCase(abstractCaseInsnNode);
InsnList[] il = getInsnForswitchCaseBlock(logMsgs, caseValues,
lineNumbers);
addInsnForswitchBlock(il, abstractCaseInsnNode);
}
示例13: processLookupSwitchBlock
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
/**
* <p>
* This method Handled the Switch block of LookupSwitchInsnNode type in a
* method
* </p>.
*
* @param currentTableSwithInsn Type of switch block
*/
private void processLookupSwitchBlock(
LookupSwitchInsnNode 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;
handleLookupSwitchCases(currentTableSwithInsn);
}
}
示例14: lookupswitch
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
public CodeBlock lookupswitch(final LabelNode defaultHandler,
final int[] keys,
final LabelNode[] handlers)
{
instructionList.add(new LookupSwitchInsnNode(defaultHandler, keys,
handlers));
return this;
}
示例15: visitLookupSwitchInsn
import org.objectweb.asm.tree.LookupSwitchInsnNode; //导入依赖的package包/类
public CodeBlock visitLookupSwitchInsn(final LabelNode defaultHandler,
final int[] keys, final LabelNode[] handlers)
{
instructionList.add(new LookupSwitchInsnNode(defaultHandler, keys,
handlers));
return this;
}