| 1 21 package proguard.classfile.instruction; 22 23 import proguard.classfile.*; 24 import proguard.classfile.instruction.visitor.InstructionVisitor; 25 import proguard.classfile.attribute.*; 26 27 33 public class LookUpSwitchInstruction extends SwitchInstruction 34 { 35 public int[] cases; 36 37 38 41 public LookUpSwitchInstruction() {} 42 43 44 47 public LookUpSwitchInstruction(byte opcode, 48 int defaultOffset, 49 int[] cases, 50 int[] jumpOffsets) 51 { 52 this.opcode = opcode; 53 this.defaultOffset = defaultOffset; 54 this.cases = cases; 55 this.jumpOffsets = jumpOffsets; 56 } 57 58 59 64 public LookUpSwitchInstruction copy(LookUpSwitchInstruction lookUpSwitchInstruction) 65 { 66 this.opcode = lookUpSwitchInstruction.opcode; 67 this.defaultOffset = lookUpSwitchInstruction.defaultOffset; 68 this.cases = lookUpSwitchInstruction.cases; 69 this.jumpOffsets = lookUpSwitchInstruction.jumpOffsets; 70 71 return this; 72 } 73 74 75 77 public Instruction shrink() 78 { 79 return this; 81 } 82 83 protected void readInfo(byte[] code, int offset) 84 { 85 offset += -offset & 3; 87 88 defaultOffset = readInt(code, offset); offset += 4; 90 int jumpOffsetCount = readInt(code, offset); offset += 4; 91 92 cases = new int[jumpOffsetCount]; 94 jumpOffsets = new int[jumpOffsetCount]; 95 96 for (int index = 0; index < jumpOffsetCount; index++) 97 { 98 cases[index] = readInt(code, offset); offset += 4; 99 jumpOffsets[index] = readInt(code, offset); offset += 4; 100 } 101 } 102 103 104 protected void writeInfo(byte[] code, int offset) 105 { 106 while ((offset & 3) != 0) 108 { 109 writeByte(code, offset++, 0); 110 } 111 112 writeInt(code, offset, defaultOffset); offset += 4; 114 writeInt(code, offset, cases.length); offset += 4; 115 116 for (int index = 0; index < cases.length; index++) 118 { 119 writeInt(code, offset, cases[index]); offset += 4; 120 writeInt(code, offset, jumpOffsets[index]); offset += 4; 121 } 122 } 123 124 125 public int length(int offset) 126 { 127 return 1 + (-(offset+1) & 3) + 8 + cases.length * 8; 128 } 129 130 131 public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor) 132 { 133 instructionVisitor.visitLookUpSwitchInstruction(clazz, method, codeAttribute, offset, this); 134 } 135 } 136 | Popular Tags |