1 jwhaley 1.1.2.1 // EXPR.java, created Wed Jan 13 21:14:57 1999 by cananian 2 jwhaley 1.1.2.1 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu> 3 jwhaley 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 jwhaley 1.1.2.1 package harpoon.IR.Tree; 5 jwhaley 1.1.2.1 6 jwhaley 1.1.2.1 import harpoon.ClassFile.HCodeElement; 7 jwhaley 1.1.2.1 import harpoon.Temp.TempMap; 8 jwhaley 1.1.2.1 import harpoon.Util.Util; 9 jwhaley 1.1.2.1 10 jwhaley 1.1.2.1 /** 11 jwhaley 1.1.2.1 * <code>EXPR</code> objects evaluate an expression (for side-effects) and then 12 jwhaley 1.1.2.1 * throw away the result. 13 jwhaley 1.1.2.1 * 14 jwhaley 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu>, based on 15 jwhaley 1.1.2.1 * <i>Modern Compiler Implementation in Java</i> by Andrew Appel. 16 cananian 1.4 * @version $Id: EXPR.java,v 1.4 2002/04/10 03:05:45 cananian Exp $ 17 jwhaley 1.1.2.1 */ 18 jwhaley 1.1.2.1 public class EXPR extends Stm { 19 jwhaley 1.1.2.1 /** Constructor. */ 20 jwhaley 1.1.2.1 public EXPR(TreeFactory tf, HCodeElement source, 21 jwhaley 1.1.2.1 Exp exp) { 22 jwhaley 1.1.2.1 super(tf, source, 1); 23 cananian 1.3.2.1 assert exp!=null; 24 jwhaley 1.1.2.1 this.setExp(exp); 25 cananian 1.3.2.1 assert tf == exp.tf : "Dest and Src must have same tree factory"; 26 jwhaley 1.1.2.1 27 jwhaley 1.1.2.1 // FSK: debugging hack 28 jwhaley 1.1.2.1 // this.accept(TreeVerifyingVisitor.norepeats()); 29 jwhaley 1.1.2.1 } 30 jwhaley 1.1.2.1 31 jwhaley 1.1.2.1 /** Returns the expression to evaluate. */ 32 jwhaley 1.1.2.1 public Exp getExp() { return (Exp) getChild(0); } 33 jwhaley 1.1.2.1 34 jwhaley 1.1.2.1 /** Sets the expression to evaluate. */ 35 jwhaley 1.1.2.1 public void setExp(Exp exp) { setChild(0, exp); } 36 jwhaley 1.1.2.1 37 jwhaley 1.1.2.1 public int kind() { return TreeKind.EXPR; } 38 jwhaley 1.1.2.1 39 jwhaley 1.1.2.1 public Stm build(TreeFactory tf, ExpList kids) { 40 cananian 1.3.2.1 assert kids!=null && kids.tail==null; 41 cananian 1.3.2.1 assert tf == kids.head.tf; 42 jwhaley 1.1.2.1 return new EXPR(tf, this, kids.head); 43 jwhaley 1.1.2.1 } 44 jwhaley 1.1.2.1 /** Accept a visitor */ 45 jwhaley 1.1.2.1 public void accept(TreeVisitor v) { v.visit(this); } 46 jwhaley 1.1.2.1 47 jwhaley 1.1.2.1 public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) { 48 jwhaley 1.1.2.1 return cb.callback(this, new EXPR(tf, this, (Exp)getExp().rename(tf, tm, cb)), tm); 49 jwhaley 1.1.2.1 } 50 jwhaley 1.1.2.1 51 jwhaley 1.1.2.1 public String toString() { 52 jwhaley 1.1.2.1 return "EXPR(#" + getExp().getID() + ")"; 53 jwhaley 1.1.2.1 } 54 jwhaley 1.1.2.1 } 55 cananian 1.2