1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 28 import java.io.PrintStream ; 29 30 33 34 public class InsnTableSwitch extends Insn { 35 36 private int lowOp; 37 38 39 private InsnTarget defaultOp; 40 41 43 private InsnTarget[] targetsOp; 44 45 46 47 public int nStackArgs() { 48 return 1; 49 } 50 51 public int nStackResults() { 52 return 0; 53 } 54 55 public String argTypes() { 56 return "I"; } 58 59 public String resultTypes() { 60 return ""; } 62 63 public boolean branches() { 64 return true; 65 } 66 67 70 public void markTargets() { 71 defaultOp.setBranchTarget(); 72 for (int i=0; i<targetsOp.length; i++) 73 targetsOp[i].setBranchTarget(); 74 } 75 76 77 80 public int lowCase() { 81 return lowOp; 82 } 83 84 87 public InsnTarget defaultTarget() { 88 return defaultOp; 89 } 90 91 94 public InsnTarget[] switchTargets() { 95 return targetsOp; 96 } 97 98 101 public InsnTableSwitch(int lowOp, InsnTarget defaultOp, 103 InsnTarget[] targetsOp) { 104 this(lowOp, defaultOp, targetsOp, NO_OFFSET); 105 } 106 107 108 109 110 void print (PrintStream out, int indent) { 111 ClassPrint.spaces(out, indent); 112 out.println(offset() + " opc_tableswitch "); for (int i=0; i<targetsOp.length; i++) { 114 int index = i + lowOp; 115 if (targetsOp[i].offset() != defaultOp.offset()) { 116 ClassPrint.spaces(out, indent+2); 117 out.println(index + " -> " + targetsOp[i].offset()); } 119 } 120 ClassPrint.spaces(out, indent+2); 121 out.println("default -> " + defaultOp.offset()); } 123 124 int store(byte[] buf, int index) { 125 buf[index++] = (byte) opcode(); 126 index = (index + 3) & ~3; 127 index = storeInt(buf, index, defaultOp.offset() - offset()); 128 index = storeInt(buf, index, lowOp); 129 index = storeInt(buf, index, lowOp+targetsOp.length-1); 130 for (int i=0; i<targetsOp.length; i++) 131 index = storeInt(buf, index, targetsOp[i].offset() - offset()); 132 return index; 133 } 134 135 int size() { 136 137 int basic = ((offset() + 4) & ~3) - offset() + 12; 138 139 return basic + targetsOp.length*4; 140 } 141 142 143 InsnTableSwitch(int lowOp, InsnTarget defaultOp, 144 InsnTarget[] targetsOp, int offset) { 145 super(opc_tableswitch, offset); 146 147 this.lowOp = lowOp; 148 this.defaultOp = defaultOp; 149 this.targetsOp = targetsOp; 150 151 if (defaultOp == null || targetsOp == null) 152 throw new InsnError ("attempt to create an opc_tableswitch" + " with invalid operands"); } 155 156 static InsnTableSwitch read (InsnReadEnv insnEnv, int myPC) { 157 158 int thisPC = myPC +1; 159 for (int pads = ((thisPC + 3) & ~3) - thisPC; pads > 0; pads--) 160 insnEnv.getByte(); 161 InsnTarget defaultTarget = insnEnv.getTarget(insnEnv.getInt() + myPC); 162 int low = insnEnv.getInt(); 163 int high = insnEnv.getInt(); 164 InsnTarget[] offsets = new InsnTarget[high - low + 1]; 165 for (int i=0; i<offsets.length; i++) 166 offsets[i] = insnEnv.getTarget(insnEnv.getInt() + myPC); 167 return new InsnTableSwitch(low, defaultTarget, offsets, myPC); 168 } 169 } 170 | Popular Tags |