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
22 import org.apache.bcel.util.ByteSequence;
23
24
25
26
27
28
29 public class TABLESWITCH extends Select {
30
31
32
33
34 TABLESWITCH() {
35 }
36
37
38
39
40
41
42 public TABLESWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) {
43 super(org.apache.bcel.Const.TABLESWITCH, match, targets, defaultTarget);
44
45 final short length = (short) (13 + getMatchLength() * 4);
46 super.setLength(length);
47 setFixedLength(length);
48 }
49
50
51
52
53
54
55
56 @Override
57 public void accept(final Visitor v) {
58 v.visitVariableLengthInstruction(this);
59 v.visitStackConsumer(this);
60 v.visitBranchInstruction(this);
61 v.visitSelect(this);
62 v.visitTABLESWITCH(this);
63 }
64
65
66
67
68
69
70 @Override
71 public void dump(final DataOutputStream out) throws IOException {
72 super.dump(out);
73 final int matchLength = getMatchLength();
74 final int low = matchLength > 0 ? super.getMatch(0) : 0;
75 out.writeInt(low);
76 final int high = matchLength > 0 ? super.getMatch(matchLength - 1) : 0;
77 out.writeInt(high);
78 for (int i = 0; i < matchLength; i++) {
79 out.writeInt(setIndices(i, getTargetOffset(super.getTarget(i))));
80 }
81 }
82
83
84
85
86 @Override
87 protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
88 super.initFromFile(bytes, wide);
89 final int low = bytes.readInt();
90 final int high = bytes.readInt();
91 final int matchLength = high - low + 1;
92 setMatchLength(matchLength);
93 final short fixedLength = (short) (13 + matchLength * 4);
94 setFixedLength(fixedLength);
95 super.setLength((short) (fixedLength + super.getPadding()));
96 super.setMatches(new int[matchLength]);
97 super.setIndices(new int[matchLength]);
98 super.setTargets(new InstructionHandle[matchLength]);
99 for (int i = 0; i < matchLength; i++) {
100 super.setMatch(i, low + i);
101 super.setIndices(i, bytes.readInt());
102 }
103 }
104 }