1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 import java.io.PrintStream ; 28 29 32 33 public class InsnLookupSwitch extends Insn { 34 35 private InsnTarget defaultOp; 36 37 38 private int[] matchesOp; 39 40 42 private InsnTarget[] targetsOp; 43 44 45 46 public int nStackArgs() { 47 return 1; 48 } 49 50 public int nStackResults() { 51 return 0; 52 } 53 54 57 public String argTypes() { 58 return "I"; } 60 61 64 public String resultTypes() { 65 return ""; } 67 68 public boolean branches() { 69 return true; 70 } 71 72 75 public void markTargets() { 76 defaultOp.setBranchTarget(); 77 for (int i=0; i<targetsOp.length; i++) 78 targetsOp[i].setBranchTarget(); 79 } 80 81 82 85 public InsnTarget defaultTarget() { 86 return defaultOp; 87 } 88 89 92 public int[] switchCases() { 93 return matchesOp; 94 } 95 96 99 public InsnTarget[] switchTargets() { 100 return targetsOp; 101 } 102 103 106 public InsnLookupSwitch (InsnTarget defaultOp, int[] matchesOp, 107 InsnTarget[] targetsOp) { 108 this(defaultOp, matchesOp, targetsOp, NO_OFFSET); 109 } 110 111 112 113 114 InsnLookupSwitch (InsnTarget defaultOp, int[] matchesOp, 115 InsnTarget[] targetsOp, int offset) { 116 super(opc_lookupswitch, offset); 117 118 this.defaultOp = defaultOp; 119 this.matchesOp = matchesOp; 120 this.targetsOp = targetsOp; 121 122 if (defaultOp == null || targetsOp == null || matchesOp == null || 123 targetsOp.length != matchesOp.length) 124 throw new InsnError ("attempt to create an opc_lookupswitch" + " with invalid operands"); } 127 128 void print (PrintStream out, int indent) { 129 ClassPrint.spaces(out, indent); 130 out.println(offset() + " opc_lookupswitch "); for (int i=0; i<matchesOp.length; i++) { 132 ClassPrint.spaces(out, indent+2); 133 out.println(matchesOp[i] + " -> " + targetsOp[i].offset()); } 135 ClassPrint.spaces(out, indent+2); 136 out.println("default -> " + defaultOp.offset()); } 138 139 int store(byte[] buf, int index) { 140 buf[index++] = (byte) opcode(); 141 index = (index + 3) & ~3; 142 index = storeInt(buf, index, defaultOp.offset() - offset()); 143 index = storeInt(buf, index, targetsOp.length); 144 for (int i=0; i<targetsOp.length; i++) { 145 index = storeInt(buf, index, matchesOp[i]); 146 index = storeInt(buf, index, targetsOp[i].offset() - offset()); 147 } 148 return index; 149 } 150 151 int size() { 152 153 int basic = ((offset() + 4) & ~3) - offset() + 8; 154 155 return basic + targetsOp.length*8; 156 } 157 158 static InsnLookupSwitch read (InsnReadEnv insnEnv, int myPC) { 159 160 int thisPC = myPC +1; 161 for (int pads = ((thisPC + 3) & ~3) - thisPC; pads > 0; pads--) 162 insnEnv.getByte(); 163 InsnTarget defaultTarget = insnEnv.getTarget(insnEnv.getInt() + myPC); 164 int npairs = insnEnv.getInt(); 165 int matches[] = new int[npairs]; 166 InsnTarget[] offsets = new InsnTarget[npairs]; 167 for (int i=0; i<npairs; i++) { 168 matches[i] = insnEnv.getInt(); 169 offsets[i] = insnEnv.getTarget(insnEnv.getInt() + myPC); 170 } 171 return new InsnLookupSwitch(defaultTarget, matches, offsets, myPC); 172 } 173 } 174 | Popular Tags |