1 cananian 1.1.2.1 // SET.java, created Wed Aug 5 07:04:09 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.1 import java.lang.reflect.Modifier; 7 cananian 1.1.2.1 8 cananian 1.1.2.6 import harpoon.ClassFile.HCodeElement; 9 cananian 1.1.2.6 import harpoon.ClassFile.HField; 10 cananian 1.1.2.1 import harpoon.Temp.Temp; 11 cananian 1.1.2.1 import harpoon.Temp.TempMap; 12 cananian 1.1.2.1 import harpoon.Util.Util; 13 cananian 1.1.2.2 14 cananian 1.1.2.1 /** 15 cananian 1.1.2.1 * <code>SET</code> represents field assignment-to operations. 16 cananian 1.1.2.1 * The <code>objectref</code> is null if the field is static. 17 cananian 1.1.2.1 * 18 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 19 cananian 1.5 * @version $Id: SET.java,v 1.5 2002/04/11 04:00:35 cananian Exp $ 20 cananian 1.1.2.1 */ 21 cananian 1.1.2.1 public class SET extends Quad { 22 cananian 1.1.2.1 /** The field description. */ 23 cananian 1.1.2.2 final protected HField field; 24 cananian 1.1.2.1 /** Reference to the object containing the field. <p> 25 cananian 1.1.2.1 * <code>null</code> if the field is static. */ 26 cananian 1.1.2.2 protected Temp objectref; 27 cananian 1.1.2.2 /** <code>Temp</code> containing the desired new value of the field. */ 28 cananian 1.1.2.2 protected Temp src; 29 cananian 1.1.2.1 30 cananian 1.1.2.2 /** Creates a <code>SET</code> representing a field assignment 31 cananian 1.1.2.2 * operation. 32 cananian 1.1.2.2 * @param field 33 cananian 1.1.2.2 * the description of the field to set. 34 cananian 1.1.2.2 * @param objectref 35 cananian 1.1.2.2 * <code>null</code> for static fields, or a <code>Temp</code> 36 cananian 1.1.2.2 * referencing the object containing the field otherwise. 37 cananian 1.1.2.2 * @param src 38 cananian 1.1.2.2 * the <code>Temp</code> containing the value to put into 39 cananian 1.1.2.2 * the field. 40 cananian 1.1.2.2 */ 41 cananian 1.1.2.4 public SET(QuadFactory qf, HCodeElement source, 42 cananian 1.1.2.1 HField field, Temp objectref, Temp src) { 43 cananian 1.1.2.4 super(qf, source); 44 cananian 1.1.2.1 this.field = field; 45 cananian 1.1.2.1 this.objectref = objectref; 46 cananian 1.1.2.1 this.src = src; 47 cananian 1.1.2.2 // VERIFY legality of SET 48 cananian 1.3.2.1 assert field!=null && src!=null; 49 cananian 1.1.2.2 if (isStatic()) 50 cananian 1.3.2.1 assert objectref==null; 51 cananian 1.1.2.2 else 52 cananian 1.3.2.1 assert objectref!=null; 53 cananian 1.1.2.1 } 54 cananian 1.1.2.2 /** Returns the description of the field to set. */ 55 cananian 1.1.2.2 public HField field() { return field; } 56 cananian 1.1.2.2 /** Returns <code>null</code> if the <code>SET</code> is on a static 57 cananian 1.1.2.2 * field, or the <code>Temp</code> containing the field to set 58 cananian 1.1.2.2 * otherwise. */ 59 cananian 1.1.2.2 public Temp objectref() { return objectref; } 60 cananian 1.1.2.2 /** Returns the <code>Temp</code> containing the desired new value 61 cananian 1.1.2.2 * of the field. */ 62 cananian 1.1.2.2 public Temp src() { return src; } 63 cananian 1.1.2.1 64 cananian 1.1.2.1 /** Returns the Temps used by this Quad. 65 cananian 1.1.2.1 * @return the <code>objectref</code> and <code>src</code> fields. */ 66 cananian 1.1.2.1 public Temp[] use() { 67 cananian 1.1.2.1 if (objectref==null) return new Temp[] { src }; 68 cananian 1.1.2.1 else return new Temp[] { objectref, src }; 69 cananian 1.1.2.1 } 70 cananian 1.1.2.1 71 cananian 1.1.2.3 public int kind() { return QuadKind.SET; } 72 cananian 1.1.2.3 73 cananian 1.1.2.5 public Quad rename(QuadFactory qqf, TempMap defMap, TempMap useMap) { 74 cananian 1.1.2.5 return new SET(qqf, this, 75 cananian 1.1.2.5 field, map(useMap,objectref), map(useMap,src)); 76 cananian 1.1.2.3 } 77 cananian 1.1.2.5 /** Rename all used variables in this Quad according to a mapping. 78 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 79 cananian 1.1.2.3 void renameUses(TempMap tm) { 80 cananian 1.1.2.1 if (objectref!=null) 81 cananian 1.1.2.1 objectref = tm.tempMap(objectref); 82 cananian 1.1.2.1 src = tm.tempMap(src); 83 cananian 1.1.2.1 } 84 cananian 1.1.2.5 /** Rename all defined variables in this Quad according to a mapping. 85 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 86 cananian 1.1.2.3 void renameDefs(TempMap tm) { 87 cananian 1.1.2.1 } 88 cananian 1.1.2.7 public void accept(QuadVisitor v) { v.visit(this); } 89 cananian 1.5 public <T> T accept(QuadValueVisitor<T> v) { return v.visit(this); } 90 cananian 1.1.2.1 91 cananian 1.1.2.1 /** Returns a human-readable representation of this Quad. */ 92 cananian 1.1.2.1 public String toString() { 93 cananian 1.1.2.1 StringBuffer sb = new StringBuffer("SET "); 94 cananian 1.1.2.1 if (isStatic()) sb.append("static "); 95 cananian 1.1.2.1 sb.append(field.getDeclaringClass().getName()+"."+field.getName()); 96 cananian 1.1.2.1 if (objectref!=null) sb.append(" of " + objectref); 97 cananian 1.1.2.1 sb.append(" to " + src.toString()); 98 cananian 1.1.2.1 return sb.toString(); 99 cananian 1.1.2.1 } 100 cananian 1.1.2.1 /** Determines whether the SET is of a static field. */ 101 cananian 1.1.2.1 public boolean isStatic() { return field.isStatic(); } 102 cananian 1.2 }