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 import de.fub.bytecode.ExceptionConstants;
00007 
00008 /** 
00009  * MULTIANEWARRAY - Create new mutidimensional array of references
00010  * <PRE>Stack: ..., count1, [count2, ...] -&gt; ..., arrayref</PRE>
00011  *
00012  * @version $Id: MULTIANEWARRAY.java,v 1.1.1.1 2002/01/24 03:41:41 pserver Exp $
00013  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00014  */
00015 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower {
00016   private short dimensions;
00017 
00018   /**
00019    * Empty constructor needed for the Class.newInstance() statement in
00020    * Instruction.readInstruction(). Not to be used otherwise.
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    * Call corresponding visitor method(s). The order is:
00034    * Call visitor methods of implemented interfaces first, then
00035    * call methods according to the class hierarchy in descending order,
00036    * i.e., the most specific visitXXX() call comes last.
00037    *
00038    * @param v Visitor object
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    * Also works for instructions whose stack effect depends on the
00050    * constant pool entry they reference.
00051    * @return Number of words consumed from stack by this instruction
00052    */
00053   public int consumeStack(ConstantPoolGen cpg) { return dimensions; }  
00054   /**
00055    * Dump instruction as byte code to stream out.
00056    * @param out Output stream
00057    */
00058   public void dump(DataOutputStream out) throws IOException {
00059     out.writeByte(tag);
00060     out.writeShort(index);
00061     out.writeByte(dimensions);
00062   }  
00063   /**
00064    * @return number of dimensions to be created
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    * Read needed data (i.e., no. dimension) from file.
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    * @return mnemonic for instruction with symbolic references resolved
00090    */
00091   public String toString(ConstantPool cp) {
00092     return super.toString(cp) + " " + dimensions;
00093   }  
00094   /**
00095    * @return mnemonic for instruction
00096    */
00097   public String toString(boolean verbose) {
00098     return super.toString(verbose) + " " + index + " " + dimensions;
00099   }  
00100 }

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