1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 /***
24 * LOOKUPSWITCH - Switch with unordered set of values
25 *
26 * @version $Id: LOOKUPSWITCH.java 386056 2006-03-15 11:31:56Z tcurdt $
27 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28 * @see SWITCH
29 */
30 public class LOOKUPSWITCH extends Select {
31
32 /***
33 * Empty constructor needed for the Class.newInstance() statement in
34 * Instruction.readInstruction(). Not to be used otherwise.
35 */
36 LOOKUPSWITCH() {
37 }
38
39
40 public LOOKUPSWITCH(int[] match, InstructionHandle[] targets, InstructionHandle defaultTarget) {
41 super(org.apache.bcel.Constants.LOOKUPSWITCH, match, targets, defaultTarget);
42 length = (short) (9 + match_length * 8);
43
44 fixed_length = length;
45 }
46
47
48 /***
49 * Dump instruction as byte code to stream out.
50 * @param out Output stream
51 */
52 public void dump( DataOutputStream out ) throws IOException {
53 super.dump(out);
54 out.writeInt(match_length);
55 for (int i = 0; i < match_length; i++) {
56 out.writeInt(match[i]);
57 out.writeInt(indices[i] = getTargetOffset(targets[i]));
58 }
59 }
60
61
62 /***
63 * Read needed data (e.g. index) from file.
64 */
65 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
66 super.initFromFile(bytes, wide);
67 match_length = bytes.readInt();
68 fixed_length = (short) (9 + match_length * 8);
69 length = (short) (fixed_length + padding);
70 match = new int[match_length];
71 indices = new int[match_length];
72 targets = new InstructionHandle[match_length];
73 for (int i = 0; i < match_length; i++) {
74 match[i] = bytes.readInt();
75 indices[i] = bytes.readInt();
76 }
77 }
78
79
80 /***
81 * Call corresponding visitor method(s). The order is:
82 * Call visitor methods of implemented interfaces first, then
83 * call methods according to the class hierarchy in descending order,
84 * i.e., the most specific visitXXX() call comes last.
85 *
86 * @param v Visitor object
87 */
88 public void accept( Visitor v ) {
89 v.visitVariableLengthInstruction(this);
90 v.visitStackProducer(this);
91 v.visitBranchInstruction(this);
92 v.visitSelect(this);
93 v.visitLOOKUPSWITCH(this);
94 }
95 }