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

INVOKEINTERFACE.java

00001 package de.fub.bytecode.generic;
00002 
00003 import de.fub.bytecode.classfile.ConstantPool;
00004 import de.fub.bytecode.Constants;
00005 
00006 import java.io.*;
00007 import de.fub.bytecode.util.ByteSequence;
00008 
00009 /** 
00010  * INVOKEINTERFACE - Invoke interface method
00011  * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
00012  *
00013  * @version $Id: INVOKEINTERFACE.java,v 1.1.1.1 2002/01/24 03:44:02 pserver Exp $
00014  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00015  */
00016 public final class INVOKEINTERFACE extends InvokeInstruction {
00017   private int nargs; // Number of arguments on stack
00018 
00019   /**
00020    * Empty constructor needed for the Class.newInstance() statement in
00021    * Instruction.readInstruction(). Not to be used otherwise.
00022    */
00023   INVOKEINTERFACE() {}  
00024   public INVOKEINTERFACE(int index, int nargs) {
00025     super(Constants.INVOKEINTERFACE, index);
00026     length = 5;
00027 
00028     if(nargs < 1)
00029       throw new ClassGenException("Number of arguments must be > 0 " + nargs);
00030 
00031     this.nargs = nargs;
00032   }  
00033   public int consumeStack(ConstantPoolGen cpg)  // nargs is given in byte-code
00034    {  return nargs; }   // nargs includes this reference      
00035   /**
00036    * Dump instruction as byte code to stream out.
00037    * @param out Output stream
00038    */
00039   public void dump(DataOutputStream out) throws IOException {
00040     out.writeByte(tag);
00041     out.writeShort(index);
00042     out.writeByte(nargs);
00043     out.writeByte(0);
00044   }  
00045   public Class[] getExceptions(){
00046     Class[] cs = new Class[4 + EXCS_INTERFACE_METHOD_RESOLUTION.length];
00047 
00048     System.arraycopy(EXCS_INTERFACE_METHOD_RESOLUTION, 0,
00049              cs, 0, EXCS_INTERFACE_METHOD_RESOLUTION.length);
00050     cs[EXCS_INTERFACE_METHOD_RESOLUTION.length-3] = INCOMPATIBLE_CLASS_CHANGE_ERROR;
00051     cs[EXCS_INTERFACE_METHOD_RESOLUTION.length-2] = ILLEGAL_ACCESS_ERROR;
00052     cs[EXCS_INTERFACE_METHOD_RESOLUTION.length-1] = ABSTRACT_METHOD_ERROR;
00053     cs[EXCS_INTERFACE_METHOD_RESOLUTION.length]   = UNSATISFIED_LINK_ERROR;
00054     return cs;
00055   }  
00056   public int getNoArguments() { return nargs; }  
00057   /**
00058    * Read needed data (i.e. index) from file.
00059    */
00060   protected void initFromFile(ByteSequence bytes, boolean wide)
00061        throws IOException
00062   {
00063     super.initFromFile(bytes, wide);
00064 
00065     length = 5;
00066     nargs = bytes.readUnsignedByte();
00067     bytes.readByte(); // Skip 0 byte
00068   }  
00069   /**
00070    * @return mnemonic for instruction with symbolic references resolved
00071    */
00072   public String toString(ConstantPool cp) {
00073     return super.toString(cp) + " " + nargs;
00074   }  
00075 }

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