< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/PUSH.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 2019, 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 import com.sun.org.apache.bcel.internal.Const;
  24 
  25 /**
  26  * Wrapper class for push operations, which are implemented either as BIPUSH,
  27  * LDC or xCONST_n instructions.
  28  *
  29  * @version $Id$
  30  * @LastModified: Jun 2019
  31  */
  32 public final class PUSH implements CompoundInstruction, VariableLengthInstruction {
  33 
  34     private Instruction instruction;
  35 
  36 
  37     /**
  38      * This constructor also applies for values of type short, char, byte
  39      *
  40      * @param cp Constant pool
  41      * @param value to be pushed
  42      */
  43     public PUSH(final ConstantPoolGen cp, final int value) {
  44         if ((value >= -1) && (value <= 5)) {
  45             instruction = InstructionConst.getInstruction(Const.ICONST_0 + value);
  46         } else if (Instruction.isValidByte(value)) {
  47             instruction = new BIPUSH((byte) value);
  48         } else if (Instruction.isValidShort(value)) {
  49             instruction = new SIPUSH((short) value);
  50         } else {


 159      * autoboxing to create this value parameter, as an alternative constructor will be called
 160      *
 161      * @param cp Constant pool
 162      * @param value to be pushed
 163      */
 164     public PUSH(final ConstantPoolGen cp, final Character value) {
 165         this(cp, value.charValue());
 166     }
 167 
 168 
 169     /**
 170      * @param cp Constant pool
 171      * @param value to be pushed
 172      */
 173     public PUSH(final ConstantPoolGen cp, final Boolean value) {
 174         this(cp, value.booleanValue());
 175     }
 176 
 177 
 178     @Override
 179     public final InstructionList getInstructionList() {
 180         return new InstructionList(instruction);
 181     }
 182 
 183 
 184     public final Instruction getInstruction() {
 185         return instruction;
 186     }
 187 
 188 
 189     /**
 190      * @return mnemonic for instruction
 191      */
 192     @Override
 193     public String toString() {
 194         return instruction + " (PUSH)";
 195     }
 196 }
   1 /*
   2  * Copyright (c) 2017, 2020, 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 import com.sun.org.apache.bcel.internal.Const;
  24 
  25 /**
  26  * Wrapper class for push operations, which are implemented either as BIPUSH,
  27  * LDC or xCONST_n instructions.
  28  *
  29  * @LastModified: Jan 2020

  30  */
  31 public final class PUSH implements CompoundInstruction, VariableLengthInstruction {
  32 
  33     private Instruction instruction;
  34 
  35 
  36     /**
  37      * This constructor also applies for values of type short, char, byte
  38      *
  39      * @param cp Constant pool
  40      * @param value to be pushed
  41      */
  42     public PUSH(final ConstantPoolGen cp, final int value) {
  43         if ((value >= -1) && (value <= 5)) {
  44             instruction = InstructionConst.getInstruction(Const.ICONST_0 + value);
  45         } else if (Instruction.isValidByte(value)) {
  46             instruction = new BIPUSH((byte) value);
  47         } else if (Instruction.isValidShort(value)) {
  48             instruction = new SIPUSH((short) value);
  49         } else {


 158      * autoboxing to create this value parameter, as an alternative constructor will be called
 159      *
 160      * @param cp Constant pool
 161      * @param value to be pushed
 162      */
 163     public PUSH(final ConstantPoolGen cp, final Character value) {
 164         this(cp, value.charValue());
 165     }
 166 
 167 
 168     /**
 169      * @param cp Constant pool
 170      * @param value to be pushed
 171      */
 172     public PUSH(final ConstantPoolGen cp, final Boolean value) {
 173         this(cp, value.booleanValue());
 174     }
 175 
 176 
 177     @Override
 178     public InstructionList getInstructionList() {
 179         return new InstructionList(instruction);
 180     }
 181 
 182 
 183     public Instruction getInstruction() {
 184         return instruction;
 185     }
 186 
 187 
 188     /**
 189      * @return mnemonic for instruction
 190      */
 191     @Override
 192     public String toString() {
 193         return instruction + " (PUSH)";
 194     }
 195 }
< prev index next >