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 * BIPUSH - Push byte on stack
25 *
26 * <PRE>Stack: ... -> ..., value</PRE>
27 *
28 * @version $Id: BIPUSH.java 386056 2006-03-15 11:31:56Z tcurdt $
29 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30 */
31 public class BIPUSH extends Instruction implements ConstantPushInstruction {
32
33 private byte b;
34
35
36 /***
37 * Empty constructor needed for the Class.newInstance() statement in
38 * Instruction.readInstruction(). Not to be used otherwise.
39 */
40 BIPUSH() {
41 }
42
43
44 /*** Push byte on stack
45 */
46 public BIPUSH(byte b) {
47 super(org.apache.bcel.Constants.BIPUSH, (short) 2);
48 this.b = b;
49 }
50
51
52 /***
53 * Dump instruction as byte code to stream out.
54 */
55 public void dump( DataOutputStream out ) throws IOException {
56 super.dump(out);
57 out.writeByte(b);
58 }
59
60
61 /***
62 * @return mnemonic for instruction
63 */
64 public String toString( boolean verbose ) {
65 return super.toString(verbose) + " " + b;
66 }
67
68
69 /***
70 * Read needed data (e.g. index) from file.
71 */
72 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
73 length = 2;
74 b = bytes.readByte();
75 }
76
77
78 public Number getValue() {
79 return new Integer(b);
80 }
81
82
83 /*** @return Type.BYTE
84 */
85 public Type getType( ConstantPoolGen cp ) {
86 return Type.BYTE;
87 }
88
89
90 /***
91 * Call corresponding visitor method(s). The order is:
92 * Call visitor methods of implemented interfaces first, then
93 * call methods according to the class hierarchy in descending order,
94 * i.e., the most specific visitXXX() call comes last.
95 *
96 * @param v Visitor object
97 */
98 public void accept( Visitor v ) {
99 v.visitPushInstruction(this);
100 v.visitStackProducer(this);
101 v.visitTypedInstruction(this);
102 v.visitConstantPushInstruction(this);
103 v.visitBIPUSH(this);
104 }
105 }