1 cananian 1.2.2.4 // OpMethod.java, created Sun Sep 13 22:49:23 1998 by cananian 2 cananian 1.2 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.2 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1 package harpoon.IR.Bytecode; 5 cananian 1.1 6 cananian 1.2.2.3 import harpoon.ClassFile.HClass; 7 cananian 1.2.2.3 import harpoon.ClassFile.HMethod; 8 cananian 1.2.2.2 import harpoon.IR.RawClass.Constant; 9 cananian 1.2.2.2 import harpoon.IR.RawClass.ConstantClass; 10 cananian 1.2.2.2 import harpoon.IR.RawClass.ConstantNameAndType; 11 cananian 1.2.2.2 import harpoon.IR.RawClass.ConstantMethodref; 12 cananian 1.2.2.2 import harpoon.IR.RawClass.ConstantInterfaceMethodref; 13 cananian 1.1 14 cananian 1.1 /** 15 cananian 1.1 * <code>OpMethod</code> represents a method reference operand of a 16 cananian 1.1 * java bytecode instruction. It is generated from a 17 cananian 1.1 * <code>CONSTANT_Methodref</code> or 18 cananian 1.1 * <code>CONSTANT_InterfaceMethodref</code> constant pool entry. 19 cananian 1.1 * 20 cananian 1.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 21 cananian 1.4 * @version $Id: OpMethod.java,v 1.4 2002/09/19 20:12:24 cananian Exp $ 22 cananian 1.2.2.2 * @see harpoon.IR.RawClass.ConstantMethodref 23 cananian 1.2.2.2 * @see harpoon.IR.RawClass.ConstantInterfaceMethodref 24 cananian 1.1 */ 25 cananian 1.2.2.1 public final class OpMethod extends Operand { 26 cananian 1.2.2.1 final boolean isInterfaceMethod; 27 cananian 1.2.2.1 final HMethod hmethod; 28 cananian 1.1 /** Create an <code>OpMethod</code> from the <code>CONSTANT_Methodref</code> 29 cananian 1.1 * or <code>CONSTANT_InterfaceMethodref</code> at the given index in 30 cananian 1.1 * the constant pool. */ 31 cananian 1.1 public OpMethod(Code parent, int constant_pool_index) { 32 cananian 1.1 Constant c = parent.getConstant(constant_pool_index); 33 cananian 1.1 ConstantClass cc; 34 cananian 1.1 ConstantNameAndType cnt; 35 cananian 1.1 if (c instanceof ConstantMethodref) { 36 cananian 1.1 ConstantMethodref cm = (ConstantMethodref)c; 37 cananian 1.1 cc = cm.class_index(); 38 cananian 1.1 cnt= cm.name_and_type_index(); 39 cananian 1.1 isInterfaceMethod=false; 40 cananian 1.1 } else if (c instanceof ConstantInterfaceMethodref) { 41 cananian 1.1 ConstantInterfaceMethodref cm = (ConstantInterfaceMethodref)c; 42 cananian 1.1 cc = cm.class_index(); 43 cananian 1.1 cnt= cm.name_and_type_index(); 44 cananian 1.1 isInterfaceMethod=true; 45 cananian 1.1 } else 46 cananian 1.1 throw new Error("OpMethod not given Methodref or InterfaceMethodref"); 47 cananian 1.1 48 cananian 1.4 // jikes is very sketchy: they invoke methods of arrays, so cc.name() 49 cananian 1.4 // may start with a '[', in which case treat cc.name() as a descriptor 50 cananian 1.4 // instead of a funny form of /-delimited class name. 51 cananian 1.4 HClass cls = cc.name().charAt(0)=='[' ? 52 cananian 1.4 parent.linker.forDescriptor(cc.name()) : 53 cananian 1.4 parent.linker.forDescriptor("L"+cc.name()+";"); 54 cananian 1.1 this.hmethod = cls.getMethod(cnt.name(), cnt.descriptor()); 55 cananian 1.1 } 56 cananian 1.1 /** Return the method referenced by this operand. */ 57 cananian 1.1 public HMethod value() { return hmethod; } 58 cananian 1.1 /** Indicates whether this operand references an interface method. */ 59 cananian 1.1 public boolean isInterface() { return isInterfaceMethod; } 60 cananian 1.1 /** Return the canonical name of the method referenced. */ 61 cananian 1.1 public String toString() { return hmethod.toString(); } 62 cananian 1.1 }