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
30
31 public class RET extends Instruction implements IndexedInstruction, TypedInstruction {
32
33 private boolean wide;
34 private int index;
35
36
37
38
39 RET() {
40 }
41
42 public RET(final int index) {
43 super(org.apache.bcel.Const.RET, (short) 2);
44 setIndex(index);
45 }
46
47
48
49
50
51
52
53 @Override
54 public void accept(final Visitor v) {
55 v.visitRET(this);
56 }
57
58
59
60
61
62
63 @Override
64 public void dump(final DataOutputStream out) throws IOException {
65 if (wide) {
66 out.writeByte(org.apache.bcel.Const.WIDE);
67 }
68 out.writeByte(super.getOpcode());
69 if (wide) {
70 out.writeShort(index);
71 } else {
72 out.writeByte(index);
73 }
74 }
75
76
77
78
79 @Override
80 public final int getIndex() {
81 return index;
82 }
83
84
85
86
87 @Override
88 public Type getType(final ConstantPoolGen cp) {
89 return ReturnaddressType.NO_TARGET;
90 }
91
92
93
94
95 @Override
96 protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
97 this.wide = wide;
98 if (wide) {
99 index = bytes.readUnsignedShort();
100 super.setLength(4);
101 } else {
102 index = bytes.readUnsignedByte();
103 super.setLength(2);
104 }
105 }
106
107
108
109
110 @Override
111 public final void setIndex(final int n) {
112 if (n < 0) {
113 throw new ClassGenException("Negative index value: " + n);
114 }
115 index = n;
116 setWide();
117 }
118
119 private void setWide() {
120 wide = index > org.apache.bcel.Const.MAX_BYTE;
121 if (wide) {
122 super.setLength(4);
123 } else {
124 super.setLength(2);
125 }
126 }
127
128
129
130
131 @Override
132 public String toString(final boolean verbose) {
133 return super.toString(verbose) + " " + index;
134 }
135 }