< prev index next >

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

Print this page




   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 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 import com.sun.org.apache.bcel.internal.Constants;

  25 /**
  26  * Super class for the x2y family of instructions.
  27  *
  28  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  29  */
  30 public abstract class ConversionInstruction extends Instruction
  31   implements TypedInstruction, StackProducer, StackConsumer {

  32   /**
  33    * Empty constructor needed for the Class.newInstance() statement in
  34    * Instruction.readInstruction(). Not to be used otherwise.
  35    */
  36   ConversionInstruction() {}


  37 
  38   /**
  39    * @param opcode opcode of instruction
  40    */
  41   protected ConversionInstruction(short opcode) {
  42     super(opcode, (short)1);
  43   }
  44 

  45   /** @return type associated with the instruction
  46    */
  47   public Type getType(ConstantPoolGen cp) {
  48     switch(opcode) {
  49     case Constants.D2I: case Constants.F2I: case Constants.L2I:




  50       return Type.INT;
  51     case Constants.D2F: case Constants.I2F: case Constants.L2F:


  52       return Type.FLOAT;
  53     case Constants.D2L: case Constants.F2L: case Constants.I2L:


  54       return Type.LONG;
  55     case Constants.F2D:  case Constants.I2D: case Constants.L2D:


  56         return Type.DOUBLE;
  57     case Constants.I2B:
  58       return Type.BYTE;
  59     case Constants.I2C:
  60       return Type.CHAR;
  61     case Constants.I2S:
  62       return Type.SHORT;
  63 
  64     default: // Never reached
  65       throw new ClassGenException("Unknown type " + opcode);
  66     }
  67   }
  68 }


   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 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 import com.sun.org.apache.bcel.internal.Const;
  25 
  26 /**
  27  * Super class for the x2y family of instructions.
  28  *
  29  * @version $Id: ConversionInstruction.java 1747278 2016-06-07 17:28:43Z britter $
  30  */
  31 public abstract class ConversionInstruction extends Instruction implements TypedInstruction,
  32         StackProducer, StackConsumer {
  33 
  34     /**
  35      * Empty constructor needed for the Class.newInstance() statement in
  36      * Instruction.readInstruction(). Not to be used otherwise.
  37      */
  38     ConversionInstruction() {
  39     }
  40 
  41 
  42     /**
  43      * @param opcode opcode of instruction
  44      */
  45     protected ConversionInstruction(final short opcode) {
  46         super(opcode, (short) 1);
  47     }
  48 
  49 
  50     /** @return type associated with the instruction
  51      */
  52     @Override
  53     public Type getType( final ConstantPoolGen cp ) {
  54         final short _opcode = super.getOpcode();
  55         switch (_opcode) {
  56             case Const.D2I:
  57             case Const.F2I:
  58             case Const.L2I:
  59                 return Type.INT;
  60             case Const.D2F:
  61             case Const.I2F:
  62             case Const.L2F:
  63                 return Type.FLOAT;
  64             case Const.D2L:
  65             case Const.F2L:
  66             case Const.I2L:
  67                 return Type.LONG;
  68             case Const.F2D:
  69             case Const.I2D:
  70             case Const.L2D:
  71                 return Type.DOUBLE;
  72             case Const.I2B:
  73                 return Type.BYTE;
  74             case Const.I2C:
  75                 return Type.CHAR;
  76             case Const.I2S:
  77                 return Type.SHORT;

  78             default: // Never reached
  79                 throw new ClassGenException("Unknown type " + _opcode);
  80         }
  81     }
  82 }
< prev index next >