00001 package de.fub.bytecode.generic;
00002
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 import de.fub.bytecode.classfile.ConstantPool;
00006 import de.fub.bytecode.ExceptionConstants;
00007
00008
00009
00010
00011
00012
00013
00014
00015 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower {
00016 private short dimensions;
00017
00018
00019
00020
00021
00022 MULTIANEWARRAY() {}
00023 public MULTIANEWARRAY(int index, short dimensions) {
00024 super(de.fub.bytecode.Constants.MULTIANEWARRAY, index);
00025
00026 if(dimensions < 1)
00027 throw new ClassGenException("Invalid dimensions value: " + dimensions);
00028
00029 this.dimensions = dimensions;
00030 length = 4;
00031 }
00032
00033
00034
00035
00036
00037
00038
00039
00040 public void accept(Visitor v) {
00041 v.visitLoadClass(this);
00042 v.visitAllocationInstruction(this);
00043 v.visitExceptionThrower(this);
00044 v.visitTypedInstruction(this);
00045 v.visitCPInstruction(this);
00046 v.visitMULTIANEWARRAY(this);
00047 }
00048
00049
00050
00051
00052
00053 public int consumeStack(ConstantPoolGen cpg) { return dimensions; }
00054
00055
00056
00057
00058 public void dump(DataOutputStream out) throws IOException {
00059 out.writeByte(tag);
00060 out.writeShort(index);
00061 out.writeByte(dimensions);
00062 }
00063
00064
00065
00066 public final short getDimensions() { return dimensions; }
00067 public Class[] getExceptions() {
00068 Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
00069
00070 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0,
00071 cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
00072
00073 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
00074 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
00075
00076 return cs;
00077 }
00078
00079
00080
00081 protected void initFromFile(ByteSequence bytes, boolean wide)
00082 throws IOException
00083 {
00084 super.initFromFile(bytes, wide);
00085 dimensions = bytes.readByte();
00086 length = 4;
00087 }
00088
00089
00090
00091 public String toString(ConstantPool cp) {
00092 return super.toString(cp) + " " + dimensions;
00093 }
00094
00095
00096
00097 public String toString(boolean verbose) {
00098 return super.toString(verbose) + " " + index + " " + dimensions;
00099 }
00100 }