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 import de.fub.bytecode.ExceptionConstants;
00006 
00007 import java.io.*;
00008 import de.fub.bytecode.util.ByteSequence;
00009 
00010 /** 
00011  * INVOKEINTERFACE - Invoke interface method
00012  * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
00013  *
00014  * @version $Id: INVOKEINTERFACE.java,v 1.1.1.1 2002/01/24 03:41:40 pserver Exp $
00015  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00016  */
00017 public final class INVOKEINTERFACE extends InvokeInstruction {
00018   private int nargs; // Number of arguments on stack
00019 
00020   /**
00021    * Empty constructor needed for the Class.newInstance() statement in
00022    * Instruction.readInstruction(). Not to be used otherwise.
00023    */
00024   INVOKEINTERFACE() {}  
00025   public INVOKEINTERFACE(int index, int nargs) {
00026     super(Constants.INVOKEINTERFACE, index);
00027     length = 5;
00028 
00029     if(nargs < 1)
00030       throw new ClassGenException("Number of arguments must be > 0 " + nargs);
00031 
00032     this.nargs = nargs;
00033   }  
00034   /**
00035    * Call corresponding visitor method(s). The order is:
00036    * Call visitor methods of implemented interfaces first, then
00037    * call methods according to the class hierarchy in descending order,
00038    * i.e., the most specific visitXXX() call comes last.
00039    *
00040    * @param v Visitor object
00041    */
00042   public void accept(Visitor v) {
00043     v.visitExceptionThrower(this);
00044     v.visitTypedInstruction(this);
00045     v.visitStackConsumer(this);
00046     v.visitStackProducer(this);
00047     v.visitLoadClass(this);
00048     v.visitCPInstruction(this);
00049     v.visitFieldOrMethod(this);
00050     v.visitInvokeInstruction(this);
00051     v.visitINVOKEINTERFACE(this);
00052   }  
00053   public int consumeStack(ConstantPoolGen cpg) { // nargs is given in byte-code
00054     return nargs;  // nargs includes this reference
00055   }  
00056   /**
00057    * Dump instruction as byte code to stream out.
00058    * @param out Output stream
00059    */
00060   public void dump(DataOutputStream out) throws IOException {
00061     out.writeByte(tag);
00062     out.writeShort(index);
00063     out.writeByte(nargs);
00064     out.writeByte(0);
00065   }  
00066   public Class[] getExceptions() {
00067     Class[] cs = new Class[4 + ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length];
00068 
00069     System.arraycopy(ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION, 0,
00070              cs, 0, ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length);
00071 
00072     cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length+3] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
00073     cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length+2] = ExceptionConstants.ILLEGAL_ACCESS_ERROR;
00074     cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length+1] = ExceptionConstants.ABSTRACT_METHOD_ERROR;
00075     cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length]   = ExceptionConstants.UNSATISFIED_LINK_ERROR;
00076 
00077     return cs;
00078   }  
00079   public int getNoArguments() { return nargs; }  
00080   /**
00081    * Read needed data (i.e., index) from file.
00082    */
00083   protected void initFromFile(ByteSequence bytes, boolean wide)
00084        throws IOException
00085   {
00086     super.initFromFile(bytes, wide);
00087 
00088     length = 5;
00089     nargs = bytes.readUnsignedByte();
00090     bytes.readByte(); // Skip 0 byte
00091   }  
00092   /**
00093    * @return mnemonic for instruction with symbolic references resolved
00094    */
00095   public String toString(ConstantPool cp) {
00096     return super.toString(cp) + " " + nargs;
00097   }  
00098 }

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