Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

MULTIANEWARRAY.java

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 
00007 /** 
00008  * MULTIANEWARRAY - Create new mutidimensional array of references
00009  * <PRE>Stack: ..., count1, [count2, ...] -&gt; ..., arrayref</PRE>
00010  *
00011  * @version $Id: MULTIANEWARRAY.java,v 1.1.1.1 2002/01/24 03:44:02 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  */
00014 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower {
00015   private short dimensions;
00016 
00017   /**
00018    * Empty constructor needed for the Class.newInstance() statement in
00019    * Instruction.readInstruction(). Not to be used otherwise.
00020    */
00021   MULTIANEWARRAY() {}  
00022   public MULTIANEWARRAY(int index, short dimensions) {
00023     super(MULTIANEWARRAY, index);
00024 
00025     if(dimensions < 1)
00026       throw new ClassGenException("Invalid dimensions value: " + dimensions);
00027 
00028     this.dimensions = dimensions;
00029     length = 4;
00030   }  
00031   /**
00032    * Also works for instructions whose stack effect depends on the
00033    * constant pool entry they reference.
00034    * @return Number of words consumed from stack by this instruction
00035    */
00036   public int consumeStack(ConstantPoolGen cpg)
00037    { return dimensions; }   
00038   /**
00039    * Dump instruction as byte code to stream out.
00040    * @param out Output stream
00041    */
00042   public void dump(DataOutputStream out) throws IOException {
00043     out.writeByte(tag);
00044     out.writeShort(index);
00045     out.writeByte(dimensions);
00046   }  
00047   /**
00048    * @return number of dimensions to be created
00049    */
00050   public final short getDimensions() { return dimensions; }  
00051   public Class[] getExceptions() {
00052     Class[] cs = new Class[2 + EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
00053 
00054     System.arraycopy(EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0,
00055              cs, 0, EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
00056     cs[EXCS_CLASS_AND_INTERFACE_RESOLUTION.length-1] = NEGATIVE_ARRAY_SIZE_EXCEPTION;
00057     cs[EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]   = ILLEGAL_ACCESS_ERROR;
00058     return cs;
00059   }  
00060   /**
00061    * Read needed data (i.e. no. dimension) from file.
00062    */
00063   protected void initFromFile(ByteSequence bytes, boolean wide)
00064        throws IOException
00065   {
00066     super.initFromFile(bytes, wide);
00067     dimensions = bytes.readByte();
00068     length     = 4;
00069   }  
00070   /**
00071    * @return mnemonic for instruction with symbolic references resolved
00072    */
00073   public String toString(ConstantPool cp) {
00074     return super.toString(cp) + " " + dimensions;
00075   }  
00076   /**
00077    * @return mnemonic for instruction
00078    */
00079   public String toString(boolean verbose) {
00080     return super.toString(verbose) + " " + index + " " + dimensions;
00081   }  
00082 }

Generated at Thu Feb 7 06:50:34 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001