static List<Item> getInitialLocals(MethodDescriptor descriptor) { List<Item> locals = new ArrayList<>(); Type[] argTypes = Type.getArgumentTypes(descriptor.getSignature()); int reg = 0; if (!descriptor.isStatic()) { Item it = Item.typeOnly("L" + descriptor.getSlashedClassName() + ";"); locals.add(it); reg += it.getSize(); } for (Type argType : argTypes) { Item it = Item.typeOnly(argType.getSignature()); locals.add(it); reg += it.getSize(); if (it.usesTwoSlots()) { locals.add(null); } } return locals; }
return Item.typeOnly("D"); case Const.ITEM_Float: return Item.typeOnly("F"); case Const.ITEM_Integer: return Item.typeOnly("I"); case Const.ITEM_Long: return Item.typeOnly("J"); case Const.ITEM_Bogus: case Const.ITEM_NewObject: return Item.typeOnly("Ljava/lang/Object;"); case Const.ITEM_Null: Item it = new Item(); return it; case Const.ITEM_InitObject: return Item.typeOnly("Ljava/lang/Object;"); case Const.ITEM_Object: int index = t.getIndex(); name = "L" + name + ";"; return Item.typeOnly(name); default: throw new IllegalArgumentException("Bad item type: " + t.getType());
static List<Item> getInitialLocals(MethodDescriptor descriptor) { List<Item> locals = new ArrayList<Item>(); Type[] argTypes = Type.getArgumentTypes(descriptor.getSignature()); int reg = 0; if (!descriptor.isStatic()) { Item it = Item.typeOnly("L" + descriptor.getSlashedClassName() + ";"); locals.add(it); reg += it.getSize(); } for (Type argType : argTypes) { Item it = Item.typeOnly(argType.getSignature()); locals.add(it); reg += it.getSize(); if (it.usesTwoSlots()) { locals.add(null); } } return locals; }
return Item.typeOnly("D"); case Constants.ITEM_Float: return Item.typeOnly("F"); case Constants.ITEM_Integer: return Item.typeOnly("I"); case Constants.ITEM_Long: return Item.typeOnly("J"); case Constants.ITEM_Bogus: case Constants.ITEM_NewObject: return Item.typeOnly("Ljava/lang/Object;"); case Constants.ITEM_Null: Item it = new Item(); return it; case Constants.ITEM_InitObject: return Item.typeOnly("Ljava/lang/Object;"); case Constants.ITEM_Object: int index = t.getIndex(); name = "L" + name + ";"; return Item.typeOnly(name); default: throw new IllegalArgumentException("Bad item type: " + t.getType());
@Test public void testMergeTypeOnly() { OpcodeStack.Item intOnly = OpcodeStack.Item.typeOnly("I"); OpcodeStack.Item zeroItem = new OpcodeStack.Item("I", 0); OpcodeStack.Item m1 = OpcodeStack.Item.merge(intOnly, zeroItem); assertEquals(0,m1.getConstant()); OpcodeStack.Item m2 = OpcodeStack.Item.merge(zeroItem, intOnly); assertEquals(0,m2.getConstant()); }