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

NEWARRAY.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 
00006 /** 
00007  * NEWARRAY -  Create new array of basic type (int, short, ...)
00008  * <PRE>Stack: ..., count -&gt; ..., arrayref</PRE>
00009  * type must be one of T_INT, T_SHORT, ...
00010  * 
00011  * @version $Id: NEWARRAY.java,v 1.1.1.1 2002/01/24 03:41:41 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  */
00014 public class NEWARRAY extends Instruction
00015   implements AllocationInstruction, ExceptionThrower, StackProducer {
00016   private byte type;
00017 
00018   /**
00019    * Empty constructor needed for the Class.newInstance() statement in
00020    * Instruction.readInstruction(). Not to be used otherwise.
00021    */
00022   NEWARRAY() {}  
00023   public NEWARRAY(byte type) {
00024     super(de.fub.bytecode.Constants.NEWARRAY, (short)2);
00025     this.type = type;
00026   }  
00027   public NEWARRAY(BasicType type) {
00028       this(type.getType());
00029   }  
00030   /**
00031    * Call corresponding visitor method(s). The order is:
00032    * Call visitor methods of implemented interfaces first, then
00033    * call methods according to the class hierarchy in descending order,
00034    * i.e., the most specific visitXXX() call comes last.
00035    *
00036    * @param v Visitor object
00037    */
00038   public void accept(Visitor v) {
00039     v.visitAllocationInstruction(this);
00040     v.visitExceptionThrower(this);
00041     v.visitStackProducer(this);
00042     v.visitNEWARRAY(this);
00043   }  
00044   /**
00045    * Dump instruction as byte code to stream out.
00046    * @param out Output stream
00047    */
00048   public void dump(DataOutputStream out) throws IOException {
00049     out.writeByte(tag);
00050     out.writeByte(type);
00051   }  
00052   public Class[] getExceptions() {
00053     return new Class[] { de.fub.bytecode.ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION };
00054   }  
00055   /**
00056    * @return type of constructed array
00057    */
00058   public final Type getType() {
00059     return new ArrayType(BasicType.getType(type), 1);
00060   }  
00061   /**
00062    * @return numeric code for basic element type
00063    */
00064   public final byte getTypecode() { return type; }  
00065   /**
00066    * Read needed data (e.g. index) from file.
00067    */
00068   protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00069   {
00070     type   = bytes.readByte();
00071     length = 2;
00072   }  
00073   /**
00074    * @return mnemonic for instruction
00075    */
00076   public String toString(boolean verbose) {
00077     return super.toString(verbose) + " " + de.fub.bytecode.Constants.TYPE_NAMES[type];
00078   }  
00079 }

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