View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
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: ... -&gt; ..., 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 }