1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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: 
73                  throw new ClassGenException("Unknown type " + opcode);
74          }
75      }
76  }