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
22package com.sun.org.apache.bcel.internal.generic;
23
24import com.sun.org.apache.bcel.internal.Constants;
25import com.sun.org.apache.bcel.internal.ExceptionConstants;
26
27/**
28 * Super class for the xRETURN family of instructions.
29 *
30 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
31 */
32public abstract class ReturnInstruction extends Instruction
33  implements ExceptionThrower, TypedInstruction, StackConsumer {
34  /**
35   * Empty constructor needed for the Class.newInstance() statement in
36   * Instruction.readInstruction(). Not to be used otherwise.
37   */
38  ReturnInstruction() {}
39
40  /**
41   * @param opcode of instruction
42   */
43  protected ReturnInstruction(short opcode) {
44    super(opcode, (short)1);
45  }
46
47  public Type getType() {
48    switch(opcode) {
49      case Constants.IRETURN: return Type.INT;
50      case Constants.LRETURN: return Type.LONG;
51      case Constants.FRETURN: return Type.FLOAT;
52      case Constants.DRETURN: return Type.DOUBLE;
53      case Constants.ARETURN: return Type.OBJECT;
54      case Constants.RETURN:  return Type.VOID;
55
56    default: // Never reached
57      throw new ClassGenException("Unknown type " + opcode);
58    }
59  }
60
61  public Class[] getExceptions() {
62    return new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE };
63  }
64
65  /** @return type associated with the instruction
66   */
67  public Type getType(ConstantPoolGen cp) {
68    return getType();
69  }
70}
71