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

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