1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 import com.sun.org.apache.bcel.internal.Constants; 57 import com.sun.org.apache.bcel.internal.classfile.*; 58 import java.util.StringTokenizer ; 59 60 66 public abstract class InvokeInstruction extends FieldOrMethod 67 implements ExceptionThrower, TypedInstruction, StackConsumer, StackProducer { 68 72 InvokeInstruction() {} 73 74 77 protected InvokeInstruction(short opcode, int index) { 78 super(opcode, index); 79 } 80 81 84 public String toString(ConstantPool cp) { 85 Constant c = cp.getConstant(index); 86 StringTokenizer tok = new StringTokenizer (cp.constantToString(c)); 87 88 return Constants.OPCODE_NAMES[opcode] + " " + 89 tok.nextToken().replace('.', '/') + tok.nextToken(); 90 } 91 92 97 public int consumeStack(ConstantPoolGen cpg) { 98 String signature = getSignature(cpg); 99 Type[] args = Type.getArgumentTypes(signature); 100 int sum; 101 102 if(opcode == Constants.INVOKESTATIC) 103 sum = 0; 104 else 105 sum = 1; 107 int n = args.length; 108 for (int i = 0; i < n; i++) 109 sum += args[i].getSize(); 110 111 return sum; 112 } 113 114 119 public int produceStack(ConstantPoolGen cpg) { 120 return getReturnType(cpg).getSize(); 121 } 122 123 125 public Type getType(ConstantPoolGen cpg) { 126 return getReturnType(cpg); 127 } 128 129 131 public String getMethodName(ConstantPoolGen cpg) { 132 return getName(cpg); 133 } 134 135 137 public Type getReturnType(ConstantPoolGen cpg) { 138 return Type.getReturnType(getSignature(cpg)); 139 } 140 141 143 public Type[] getArgumentTypes(ConstantPoolGen cpg) { 144 return Type.getArgumentTypes(getSignature(cpg)); 145 } 146 } 147 | Popular Tags |