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 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 }