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
24
25/**
26 * Super class for instructions dealing with array access such as IALOAD.
27 *
28 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
29 */
30public abstract class ArrayInstruction extends Instruction
31  implements ExceptionThrower, TypedInstruction {
32  /**
33   * Empty constructor needed for the Class.newInstance() statement in
34   * Instruction.readInstruction(). Not to be used otherwise.
35   */
36  ArrayInstruction() {}
37
38  /**
39   * @param opcode of instruction
40   */
41  protected ArrayInstruction(short opcode) {
42    super(opcode, (short)1);
43  }
44
45  public Class[] getExceptions() {
46    return com.sun.org.apache.bcel.internal.ExceptionConstants.EXCS_ARRAY_EXCEPTION;
47  }
48
49  /** @return type associated with the instruction
50   */
51  public Type getType(ConstantPoolGen cp) {
52    switch(opcode) {
53    case com.sun.org.apache.bcel.internal.Constants.IALOAD: case com.sun.org.apache.bcel.internal.Constants.IASTORE:
54      return Type.INT;
55    case com.sun.org.apache.bcel.internal.Constants.CALOAD: case com.sun.org.apache.bcel.internal.Constants.CASTORE:
56      return Type.CHAR;
57    case com.sun.org.apache.bcel.internal.Constants.BALOAD: case com.sun.org.apache.bcel.internal.Constants.BASTORE:
58      return Type.BYTE;
59    case com.sun.org.apache.bcel.internal.Constants.SALOAD: case com.sun.org.apache.bcel.internal.Constants.SASTORE:
60      return Type.SHORT;
61    case com.sun.org.apache.bcel.internal.Constants.LALOAD: case com.sun.org.apache.bcel.internal.Constants.LASTORE:
62      return Type.LONG;
63    case com.sun.org.apache.bcel.internal.Constants.DALOAD: case com.sun.org.apache.bcel.internal.Constants.DASTORE:
64      return Type.DOUBLE;
65    case com.sun.org.apache.bcel.internal.Constants.FALOAD: case com.sun.org.apache.bcel.internal.Constants.FASTORE:
66      return Type.FLOAT;
67    case com.sun.org.apache.bcel.internal.Constants.AALOAD: case com.sun.org.apache.bcel.internal.Constants.AASTORE:
68      return Type.OBJECT;
69
70    default: throw new ClassGenException("Oops: unknown case in switch" + opcode);
71    }
72  }
73}
74