1 17 package org.apache.bcel.generic; 18 19 import java.io.DataOutputStream ; 20 import java.io.IOException ; 21 import org.apache.bcel.util.ByteSequence; 22 23 30 public class TABLESWITCH extends Select { 31 32 36 TABLESWITCH() { 37 } 38 39 40 46 public TABLESWITCH(int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget) { 47 super(org.apache.bcel.Constants.TABLESWITCH, match, targets, defaultTarget); 48 length = (short) (13 + match_length * 4); 50 fixed_length = length; 51 } 52 53 54 58 public void dump( DataOutputStream out ) throws IOException { 59 super.dump(out); 60 int low = (match_length > 0) ? match[0] : 0; 61 out.writeInt(low); 62 int high = (match_length > 0) ? match[match_length - 1] : 0; 63 out.writeInt(high); 64 for (int i = 0; i < match_length; i++) { 65 out.writeInt(indices[i] = getTargetOffset(targets[i])); 66 } 67 } 68 69 70 73 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { 74 super.initFromFile(bytes, wide); 75 int low = bytes.readInt(); 76 int high = bytes.readInt(); 77 match_length = high - low + 1; 78 fixed_length = (short) (13 + match_length * 4); 79 length = (short) (fixed_length + padding); 80 match = new int[match_length]; 81 indices = new int[match_length]; 82 targets = new InstructionHandle[match_length]; 83 for (int i = low; i <= high; i++) { 84 match[i - low] = i; 85 } 86 for (int i = 0; i < match_length; i++) { 87 indices[i] = bytes.readInt(); 88 } 89 } 90 91 92 100 public void accept( Visitor v ) { 101 v.visitVariableLengthInstruction(this); 102 v.visitStackProducer(this); 103 v.visitBranchInstruction(this); 104 v.visitSelect(this); 105 v.visitTABLESWITCH(this); 106 } 107 } 108 | Popular Tags |