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