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 family of arithmetic instructions.
23   *
24   * @version $Id: ArithmeticInstruction.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 ArithmeticInstruction 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      ArithmeticInstruction() {
35      }
36  
37  
38      /***
39       * @param opcode of instruction
40       */
41      protected ArithmeticInstruction(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.DADD:
51              case Constants.DDIV:
52              case Constants.DMUL:
53              case Constants.DNEG:
54              case Constants.DREM:
55              case Constants.DSUB:
56                  return Type.DOUBLE;
57              case Constants.FADD:
58              case Constants.FDIV:
59              case Constants.FMUL:
60              case Constants.FNEG:
61              case Constants.FREM:
62              case Constants.FSUB:
63                  return Type.FLOAT;
64              case Constants.IADD:
65              case Constants.IAND:
66              case Constants.IDIV:
67              case Constants.IMUL:
68              case Constants.INEG:
69              case Constants.IOR:
70              case Constants.IREM:
71              case Constants.ISHL:
72              case Constants.ISHR:
73              case Constants.ISUB:
74              case Constants.IUSHR:
75              case Constants.IXOR:
76                  return Type.INT;
77              case Constants.LADD:
78              case Constants.LAND:
79              case Constants.LDIV:
80              case Constants.LMUL:
81              case Constants.LNEG:
82              case Constants.LOR:
83              case Constants.LREM:
84              case Constants.LSHL:
85              case Constants.LSHR:
86              case Constants.LSUB:
87              case Constants.LUSHR:
88              case Constants.LXOR:
89                  return Type.LONG;
90              default: // Never reached
91                  throw new ClassGenException("Unknown type " + opcode);
92          }
93      }
94  }