1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 import java.io.*; 57 import com.sun.org.apache.bcel.internal.util.ByteSequence; 58 import com.sun.org.apache.bcel.internal.classfile.ConstantPool; 59 import com.sun.org.apache.bcel.internal.ExceptionConstants; 60 61 68 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower { 69 private short dimensions; 70 71 75 MULTIANEWARRAY() {} 76 77 public MULTIANEWARRAY(int index, short dimensions) { 78 super(com.sun.org.apache.bcel.internal.Constants.MULTIANEWARRAY, index); 79 80 if(dimensions < 1) 81 throw new ClassGenException("Invalid dimensions value: " + dimensions); 82 83 this.dimensions = dimensions; 84 length = 4; 85 } 86 87 91 public void dump(DataOutputStream out) throws IOException { 92 out.writeByte(opcode); 93 out.writeShort(index); 94 out.writeByte(dimensions); 95 } 96 97 100 protected void initFromFile(ByteSequence bytes, boolean wide) 101 throws IOException 102 { 103 super.initFromFile(bytes, wide); 104 dimensions = bytes.readByte(); 105 length = 4; 106 } 107 108 111 public final short getDimensions() { return dimensions; } 112 113 116 public String toString(boolean verbose) { 117 return super.toString(verbose) + " " + index + " " + dimensions; 118 } 119 120 123 public String toString(ConstantPool cp) { 124 return super.toString(cp) + " " + dimensions; 125 } 126 127 132 public int consumeStack(ConstantPoolGen cpg) { return dimensions; } 133 134 public Class [] getExceptions() { 135 Class [] cs = new Class [2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; 136 137 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, 138 cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); 139 140 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; 141 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; 142 143 return cs; 144 } 145 146 public ObjectType getLoadClassType(ConstantPoolGen cpg) { 147 Type t = getType(cpg); 148 149 if (t instanceof ArrayType){ 150 t = ((ArrayType) t).getBasicType(); 151 } 152 153 return (t instanceof ObjectType)? (ObjectType) t : null; 154 } 155 156 164 public void accept(Visitor v) { 165 v.visitLoadClass(this); 166 v.visitAllocationInstruction(this); 167 v.visitExceptionThrower(this); 168 v.visitTypedInstruction(this); 169 v.visitCPInstruction(this); 170 v.visitMULTIANEWARRAY(this); 171 } 172 } 173 | Popular Tags |