1 cananian 1.1.2.1 // COMPONENTOF.java, created Wed Sep 9 13:05:33 1998 by cananian 2 cananian 1.1.2.1 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.1.2.1 package harpoon.IR.Quads; 5 cananian 1.1.2.1 6 cananian 1.1.2.7 import harpoon.ClassFile.HCodeElement; 7 cananian 1.1.2.1 import harpoon.Temp.Temp; 8 cananian 1.1.2.1 import harpoon.Temp.TempMap; 9 cananian 1.1.2.2 import harpoon.Util.Util; 10 cananian 1.1.2.2 11 cananian 1.1.2.1 /** 12 cananian 1.1.2.1 * <code>COMPONENTOF</code> objects implement the test needed to determine 13 cananian 1.1.2.1 * if an <code>ASET</code> needs to throw an exception. Specifically, 14 cananian 1.1.2.1 * <code>COMPONENTOF</code> evaluates to boolean <code>true</code> if 15 cananian 1.1.2.10 * a certain temporary is an instance of the component 16 cananian 1.1.2.10 * type of a certain array, or boolean <code>false</code> otherwise. 17 cananian 1.1.2.10 * The given array should <strong>never</strong> have components of primitive 18 cananian 1.1.2.10 * type, as <code>COMPONENTOF</code> would always return <code>true</code> in 19 cananian 1.1.2.10 * this case, given a type-safe program.<p> 20 cananian 1.1.2.10 * 21 cananian 1.1.2.10 * <strong>In quad-with-try form ONLY:</strong> 22 cananian 1.1.2.10 * The component object to test (<code>componentref</code>) may have 23 cananian 1.1.2.10 * the value null, in which case <code>COMPONENTOF</code> returns 24 cananian 1.1.2.10 * <code>true</code> (it is always safe to store <code>null</code> 25 cananian 1.1.2.10 * in an object array). 26 cananian 1.1.2.10 * <strong>In all other forms the component object must be provably 27 cananian 1.1.2.10 * non-null.</strong> An explicit null-check may be needed prior to the 28 cananian 1.1.2.10 * <code>COMPONENTOF</code> if the component object cannot be 29 cananian 1.1.2.10 * proven non-null. 30 cananian 1.1.2.1 * 31 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 32 cananian 1.5 * @version $Id: COMPONENTOF.java,v 1.5 2002/04/11 04:00:34 cananian Exp $ 33 cananian 1.1.2.1 * @see ASET 34 cananian 1.1.2.1 * @see "The Java Virtual Machine Specification" 35 cananian 1.1.2.1 */ 36 cananian 1.1.2.1 public class COMPONENTOF extends Quad { 37 cananian 1.1.2.2 /** The <code>Temp</code> in which to store the result of the test. */ 38 cananian 1.1.2.2 protected Temp dst; 39 cananian 1.1.2.1 /** The array object to test. */ 40 cananian 1.1.2.2 protected Temp arrayref; 41 cananian 1.1.2.9 /** The component object to test. */ 42 cananian 1.1.2.2 protected Temp objectref; 43 cananian 1.1.2.1 44 cananian 1.1.2.2 /** Creates a <code>COMPONENTOF</code> representing a typecheck test. 45 cananian 1.1.2.2 * @param dst 46 cananian 1.1.2.2 * the <code>Temp</code> in which to store the result of the test. 47 cananian 1.1.2.2 * The <code>Temp</code> specified by <code>dst</code> gets a 48 cananian 1.1.2.2 * boolean <code>true</code> value if <code>objectref</code> 49 cananian 1.1.2.10 * contains a reference to an instance 50 cananian 1.1.2.2 * of the component type of the array in <code>arrayref</code> 51 cananian 1.1.2.2 * or any subtype; or a boolean <code>false</code> value otherwise. 52 cananian 1.1.2.10 * In quad-with-try form <strong>only</strong>, the result is also 53 cananian 1.1.2.10 * <code>true</code> if <code>objectref</code> is 54 cananian 1.1.2.10 * <code>null</code>; in all other forms this possibility 55 cananian 1.1.2.10 * is a semantic error. 56 cananian 1.1.2.2 * @param arrayref 57 cananian 1.1.2.10 * the array object to test. <strong>Should never be an 58 cananian 1.1.2.10 * array of primitive component type.</strong> 59 cananian 1.1.2.2 * The <code>Temp</code> specified by <code>arrayref</code> 60 cananian 1.1.2.2 * <strong>should never</strong> contain the value 61 cananian 1.1.2.2 * <code>null</code> at run-time. 62 cananian 1.1.2.2 * @param objectref 63 cananian 1.1.2.2 * the component object to test. 64 cananian 1.1.2.2 * The <code>Temp</code> specified by <code>objectref</code> 65 cananian 1.1.2.2 * <strong>may</strong> contain the value <code>null</code> 66 cananian 1.1.2.10 * at run-time <strong>if and only if</strong> we are in 67 cananian 1.1.2.10 * quad-with-try form. 68 cananian 1.1.2.2 */ 69 cananian 1.1.2.4 public COMPONENTOF(QuadFactory qf, HCodeElement source, 70 cananian 1.1.2.1 Temp dst, Temp arrayref, Temp objectref) { 71 cananian 1.1.2.4 super(qf, source); 72 cananian 1.1.2.1 this.dst = dst; 73 cananian 1.1.2.1 this.arrayref = arrayref; 74 cananian 1.1.2.1 this.objectref = objectref; 75 cananian 1.3.2.1 assert dst!=null && arrayref!=null && objectref!=null; 76 cananian 1.1.2.1 } 77 cananian 1.1.2.2 // ACCESSOR METHODS: 78 cananian 1.1.2.2 /** Returns the <code>Temp</code> in which to store the result of the 79 cananian 1.1.2.2 * type check test. */ 80 cananian 1.1.2.2 public Temp dst() { return dst; } 81 cananian 1.1.2.2 /** Returns the array reference to test. */ 82 cananian 1.1.2.2 public Temp arrayref() { return arrayref; } 83 cananian 1.1.2.2 /** Returns the component object reference to test. */ 84 cananian 1.1.2.2 public Temp objectref() { return objectref; } 85 cananian 1.1.2.2 86 cananian 1.1.2.1 /** Returns the <code>Temp</code>s used by this quad. */ 87 cananian 1.1.2.1 public Temp[] use() { return new Temp[] { arrayref, objectref }; } 88 cananian 1.1.2.1 /** Returns the <code>Temp</code>s defined by this quad. */ 89 cananian 1.1.2.1 public Temp[] def() { return new Temp[] { dst }; } 90 cananian 1.1.2.1 91 cananian 1.1.2.3 public int kind() { return QuadKind.COMPONENTOF; } 92 cananian 1.1.2.3 93 cananian 1.1.2.5 public Quad rename(QuadFactory qqf, TempMap defMap, TempMap useMap) { 94 cananian 1.1.2.5 return new COMPONENTOF(qqf, this, map(defMap,dst), 95 cananian 1.1.2.5 map(useMap,arrayref), map(useMap,objectref)); 96 cananian 1.1.2.3 } 97 cananian 1.1.2.5 /** Rename all used variables in this Quad according to a mapping. 98 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 99 cananian 1.1.2.3 void renameUses(TempMap tm) { 100 cananian 1.1.2.1 arrayref = tm.tempMap(arrayref); 101 cananian 1.1.2.1 objectref = tm.tempMap(objectref); 102 cananian 1.1.2.1 } 103 cananian 1.1.2.5 /** Rename all defined variables in this Quad according to a mapping. 104 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 105 cananian 1.1.2.3 void renameDefs(TempMap tm) { 106 cananian 1.1.2.1 dst = tm.tempMap(dst); 107 cananian 1.1.2.1 } 108 cananian 1.1.2.1 109 cananian 1.1.2.8 public void accept(QuadVisitor v) { v.visit(this); } 110 cananian 1.5 public <T> T accept(QuadValueVisitor<T> v) { return v.visit(this); } 111 cananian 1.1.2.1 112 cananian 1.1.2.1 /** Returns a human-readable representation of this Quad. */ 113 cananian 1.1.2.1 public String toString() { 114 cananian 1.1.2.1 return dst.toString() + " = " + 115 cananian 1.1.2.1 objectref.toString() + " COMPONENTOF " + arrayref.toString(); 116 cananian 1.1.2.1 } 117 cananian 1.2 }