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
00012
00013
00014
00015
00016
00017 public final class INVOKEINTERFACE extends InvokeInstruction {
00018 private int nargs;
00019
00020
00021
00022
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
00036
00037
00038
00039
00040
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) {
00054 return nargs;
00055 }
00056
00057
00058
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
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();
00091 }
00092
00093
00094
00095 public String toString(ConstantPool cp) {
00096 return super.toString(cp) + " " + nargs;
00097 }
00098 }