View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
15   *
16   */
17  package org.apache.bcel.generic;
18  
19  import org.apache.bcel.Constants;
20  
21  /***
22   * Super class for the x2y family of instructions.
23   *
24   * @version $Id: ConversionInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
25   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26   */
27  public abstract class ConversionInstruction extends Instruction implements TypedInstruction,
28          StackProducer, StackConsumer {
29  
30      /***
31       * Empty constructor needed for the Class.newInstance() statement in
32       * Instruction.readInstruction(). Not to be used otherwise.
33       */
34      ConversionInstruction() {
35      }
36  
37  
38      /***
39       * @param opcode opcode of instruction
40       */
41      protected ConversionInstruction(short opcode) {
42          super(opcode, (short) 1);
43      }
44  
45  
46      /*** @return type associated with the instruction
47       */
48      public Type getType( ConstantPoolGen cp ) {
49          switch (opcode) {
50              case Constants.D2I:
51              case Constants.F2I:
52              case Constants.L2I:
53                  return Type.INT;
54              case Constants.D2F:
55              case Constants.I2F:
56              case Constants.L2F:
57                  return Type.FLOAT;
58              case Constants.D2L:
59              case Constants.F2L:
60              case Constants.I2L:
61                  return Type.LONG;
62              case Constants.F2D:
63              case Constants.I2D:
64              case Constants.L2D:
65                  return Type.DOUBLE;
66              case Constants.I2B:
67                  return Type.BYTE;
68              case Constants.I2C:
69                  return Type.CHAR;
70              case Constants.I2S:
71                  return Type.SHORT;
72              default: // Never reached
73                  throw new ClassGenException("Unknown type " + opcode);
74          }
75      }
76  }