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.Const;
25 
26 /**
27  * Super class for the x2y family of instructions.
28  *
29  */
30 public abstract class ConversionInstruction extends Instruction implements TypedInstruction,
31         StackProducer, StackConsumer {
32 
33     /**
34      * Empty constructor needed for Instruction.readInstruction.
35      * Not to be used otherwise.
36      */
ConversionInstruction()37     ConversionInstruction() {
38     }
39 
40 
41     /**
42      * @param opcode opcode of instruction
43      */
ConversionInstruction(final short opcode)44     protected ConversionInstruction(final short opcode) {
45         super(opcode, (short) 1);
46     }
47 
48 
49     /** @return type associated with the instruction
50      */
51     @Override
getType( final ConstantPoolGen cp )52     public Type getType( final ConstantPoolGen cp ) {
53         final short _opcode = super.getOpcode();
54         switch (_opcode) {
55             case Const.D2I:
56             case Const.F2I:
57             case Const.L2I:
58                 return Type.INT;
59             case Const.D2F:
60             case Const.I2F:
61             case Const.L2F:
62                 return Type.FLOAT;
63             case Const.D2L:
64             case Const.F2L:
65             case Const.I2L:
66                 return Type.LONG;
67             case Const.F2D:
68             case Const.I2D:
69             case Const.L2D:
70                 return Type.DOUBLE;
71             case Const.I2B:
72                 return Type.BYTE;
73             case Const.I2C:
74                 return Type.CHAR;
75             case Const.I2S:
76                 return Type.SHORT;
77             default: // Never reached
78                 throw new ClassGenException("Unknown type " + _opcode);
79         }
80     }
81 }
82