1 cananian 1.1.2.1 // INSTANCEOF.java, created Tue Sep 1 21:09:43 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.HClass; 7 cananian 1.1.2.7 import harpoon.ClassFile.HCodeElement; 8 cananian 1.1.2.1 import harpoon.Temp.Temp; 9 cananian 1.1.2.1 import harpoon.Temp.TempMap; 10 cananian 1.1.2.2 import harpoon.Util.Util; 11 cananian 1.1.2.4 12 cananian 1.1.2.1 /** 13 cananian 1.1.2.1 * <code>INSTANCEOF</code> objects represent an 'instanceof' evaluation. 14 cananian 1.1.2.1 * <code>INSTANCEOF</code> assigns a boolean value to a temporary after 15 cananian 1.1.2.1 * evaluating whether a certain temporary is an instance of a given 16 cananian 1.1.2.1 * class type.<p> 17 cananian 1.1.2.9 * <strong>In quad-with-try form ONLY:</strong> 18 cananian 1.1.2.6 * The <code>src</code> <code>Temp</code> may have the value 19 cananian 1.1.2.6 * <code>null</code>, in which case <code>INSTANCEOF</code> evaluates to 20 cananian 1.1.2.6 * <code>false</code>. 21 cananian 1.1.2.9 * <strong>In all other forms the <code>src</code> <code>Temp</code> 22 cananian 1.1.2.9 * should always contain a provably non-null value at runtime.</strong> 23 cananian 1.1.2.9 * (An explicit null-check may need to be added prior to the 24 cananian 1.1.2.9 * <code>INSTANCEOF</code> if the value cannot be proven non-null.) 25 cananian 1.1.2.1 * 26 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 27 cananian 1.5 * @version $Id: INSTANCEOF.java,v 1.5 2002/04/11 04:00:34 cananian Exp $ 28 cananian 1.1.2.1 */ 29 cananian 1.1.2.1 public class INSTANCEOF extends Quad { 30 cananian 1.1.2.2 /** The <code>Temp</code> in which to store the result of the test. */ 31 cananian 1.1.2.2 protected Temp dst; 32 cananian 1.1.2.2 /** The <code>Temp</code> to evaluate. */ 33 cananian 1.1.2.2 protected Temp src; 34 cananian 1.1.2.1 /** The class in which <code>src</code> is tested for membership. */ 35 cananian 1.1.2.2 final protected HClass hclass; 36 cananian 1.1.2.1 37 cananian 1.1.2.6 /** Creates a <code>INSTANCEOF</code> representing a type check. 38 cananian 1.1.2.2 * @param dst 39 cananian 1.1.2.2 * the <code>Temp</code> in which to store the result of the test. 40 cananian 1.1.2.2 * @param src 41 cananian 1.1.2.2 * the <code>Temp</code> to test. 42 cananian 1.1.2.2 * @param hclass 43 cananian 1.1.2.2 * the class in which <code>src</code> is tested for membership. 44 cananian 1.1.2.2 */ 45 cananian 1.1.2.4 public INSTANCEOF(QuadFactory qf, HCodeElement source, 46 cananian 1.1.2.1 Temp dst, Temp src, HClass hclass) { 47 cananian 1.1.2.4 super(qf, source); 48 cananian 1.1.2.1 this.dst = dst; 49 cananian 1.1.2.1 this.src = src; 50 cananian 1.1.2.1 this.hclass = hclass; 51 cananian 1.1.2.2 // VERIFY legality of INSTANCEOF 52 cananian 1.3.2.1 assert dst!=null && src!=null && hclass!=null; 53 cananian 1.1.2.1 } 54 cananian 1.1.2.2 // ACCESSOR METHODS: 55 cananian 1.1.2.2 /** Returns the <code>Temp</code> in which to store the result of the 56 cananian 1.1.2.2 * <code>instanceof</code> test. */ 57 cananian 1.1.2.2 public Temp dst() { return dst; } 58 cananian 1.1.2.2 /** Returns the <code>Temp</code> to test. */ 59 cananian 1.1.2.2 public Temp src() { return src; } 60 cananian 1.1.2.2 /** Returns the class in which <code>src</code> is tested for 61 cananian 1.1.2.2 * membership. */ 62 cananian 1.1.2.2 public HClass hclass() { return hclass; } 63 cananian 1.1.2.1 64 cananian 1.1.2.1 /** Returns the <code>Temp</code>s used by this quad. */ 65 cananian 1.1.2.1 public Temp[] use() { return new Temp[] { src }; } 66 cananian 1.1.2.1 /** Returns the <code>Temp</code>s defined by this quad. */ 67 cananian 1.1.2.1 public Temp[] def() { return new Temp[] { dst }; } 68 cananian 1.1.2.1 69 cananian 1.1.2.3 public int kind() { return QuadKind.INSTANCEOF; } 70 cananian 1.1.2.3 71 cananian 1.1.2.5 public Quad rename(QuadFactory qqf, TempMap defMap, TempMap useMap) { 72 cananian 1.1.2.5 return new INSTANCEOF(qqf, this, 73 cananian 1.1.2.5 map(defMap,dst), map(useMap,src), hclass); 74 cananian 1.1.2.3 } 75 cananian 1.1.2.5 /** Rename all used variables in this Quad according to a mapping. 76 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 77 cananian 1.1.2.3 void renameUses(TempMap tm) { 78 cananian 1.1.2.1 src = tm.tempMap(src); 79 cananian 1.1.2.1 } 80 cananian 1.1.2.5 /** Rename all defined variables in this Quad according to a mapping. 81 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 82 cananian 1.1.2.3 void renameDefs(TempMap tm) { 83 cananian 1.1.2.1 dst = tm.tempMap(dst); 84 cananian 1.1.2.1 } 85 cananian 1.1.2.1 86 cananian 1.1.2.8 public void accept(QuadVisitor v) { v.visit(this); } 87 cananian 1.5 public <T> T accept(QuadValueVisitor<T> v) { return v.visit(this); } 88 cananian 1.1.2.1 89 cananian 1.1.2.1 /** Returns a human-readable representation of this Quad. */ 90 cananian 1.1.2.1 public String toString() { 91 cananian 1.1.2.1 return dst.toString() + " = " + 92 cananian 1.1.2.1 src.toString() + " INSTANCEOF " + hclass.getName(); 93 cananian 1.1.2.1 } 94 cananian 1.2 }