1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.bcel.internal.generic;
23
24
25import java.io.*;
26import com.sun.org.apache.bcel.internal.util.ByteSequence;
27
28/**
29 * BIPUSH - Push byte on stack
30 *
31 * <PRE>Stack: ... -&gt; ..., value</PRE>
32 *
33 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
34 */
35public class BIPUSH extends Instruction implements ConstantPushInstruction {
36  private byte b;
37
38  /**
39   * Empty constructor needed for the Class.newInstance() statement in
40   * Instruction.readInstruction(). Not to be used otherwise.
41   */
42  BIPUSH() {}
43
44  /** Push byte on stack
45   */
46  public BIPUSH(byte b) {
47    super(com.sun.org.apache.bcel.internal.Constants.BIPUSH, (short)2);
48    this.b = b;
49  }
50
51  /**
52   * Dump instruction as byte code to stream out.
53   */
54  public void dump(DataOutputStream out) throws IOException {
55    super.dump(out);
56    out.writeByte(b);
57  }
58
59  /**
60   * @return mnemonic for instruction
61   */
62  public String toString(boolean verbose) {
63    return super.toString(verbose) + " " + b;
64  }
65
66  /**
67   * Read needed data (e.g. index) from file.
68   */
69  protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
70  {
71    length = 2;
72    b      = bytes.readByte();
73  }
74
75  public Number getValue() { return new Integer(b); }
76
77  /** @return Type.BYTE
78   */
79  public Type getType(ConstantPoolGen cp) {
80    return Type.BYTE;
81  }
82
83  /**
84   * Call corresponding visitor method(s). The order is:
85   * Call visitor methods of implemented interfaces first, then
86   * call methods according to the class hierarchy in descending order,
87   * i.e., the most specific visitXXX() call comes last.
88   *
89   * @param v Visitor object
90   */
91  public void accept(Visitor v) {
92    v.visitPushInstruction(this);
93    v.visitStackProducer(this);
94    v.visitTypedInstruction(this);
95    v.visitConstantPushInstruction(this);
96    v.visitBIPUSH(this);
97  }
98}
99