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

InvokeInstruction.java

00001 package de.fub.bytecode.generic;
00002 
00003 import de.fub.bytecode.Constants;
00004 import de.fub.bytecode.classfile.*;
00005 import java.util.StringTokenizer;
00006 
00007 /**
00008  * Super class for the INVOKExxx family of instructions.
00009  *
00010  * @version $Id: InvokeInstruction.java,v 1.1.1.1 2002/01/24 03:41:40 pserver Exp $
00011  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00012  */
00013 public abstract class InvokeInstruction extends FieldOrMethod
00014   implements ExceptionThrower, TypedInstruction, StackConsumer, StackProducer {
00015   /**
00016    * Empty constructor needed for the Class.newInstance() statement in
00017    * Instruction.readInstruction(). Not to be used otherwise.
00018    */
00019   InvokeInstruction() {}  
00020   /**
00021    * @param index to constant pool
00022    */
00023   protected InvokeInstruction(short tag, int index) {
00024     super(tag, index);
00025   }  
00026   /**
00027    * Also works for instructions whose stack effect depends on the
00028    * constant pool entry they reference.
00029    * @return Number of words consumed from stack by this instruction
00030    */
00031   public int consumeStack(ConstantPoolGen cpg) {
00032       String signature = getSignature(cpg);
00033       Type[] args      = Type.getArgumentTypes(signature);
00034       int    sum;
00035 
00036       if(tag == Constants.INVOKESTATIC)
00037     sum = 0;
00038       else
00039     sum = 1;  // this reference
00040 
00041       int n = args.length;
00042       for (int i = 0; i < n; i++)
00043     sum += args[i].getSize();
00044 
00045       return sum;
00046    }   
00047   /** @return argument types of referenced method.
00048    */
00049   public Type[] getArgumentTypes(ConstantPoolGen cpg) {
00050     return Type.getArgumentTypes(getSignature(cpg));
00051   }  
00052   /** @return name of referenced method.
00053    */
00054   public String getMethodName(ConstantPoolGen cpg) {
00055     return getName(cpg);
00056   }  
00057   /** @return return type of referenced method.
00058    */
00059   public Type getReturnType(ConstantPoolGen cpg) {
00060     return Type.getReturnType(getSignature(cpg));
00061   }  
00062   /** @return return type of referenced method.
00063    */
00064   public Type getType(ConstantPoolGen cpg) {
00065     return getReturnType(cpg);
00066   }  
00067   /**
00068    * Also works for instructions whose stack effect depends on the
00069    * constant pool entry they reference.
00070    * @return Number of words produced onto stack by this instruction
00071    */
00072   public int produceStack(ConstantPoolGen cpg) {
00073     return getReturnType(cpg).getSize();
00074   }  
00075   /**
00076    * @return mnemonic for instruction with symbolic references resolved
00077    */
00078   public String toString(ConstantPool cp) {
00079     Constant        c   = cp.getConstant(index);
00080     StringTokenizer tok = new StringTokenizer(cp.constantToString(c));
00081 
00082     return Constants.OPCODE_NAMES[tag] + " " +
00083       tok.nextToken().replace('.', '/') + tok.nextToken();
00084   }  
00085 }

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