1 cananian 1.1.2.9  // THROW.java, created Thu Feb 18 16:59:53 1999 by duncan
 2 cananian 1.1.2.17 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu>
 3 cananian 1.1.2.8  // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 duncan   1.1.2.1  package harpoon.IR.Tree;
 5 duncan   1.1.2.1  
 6 duncan   1.1.2.1  import harpoon.ClassFile.HCodeElement;
 7 cananian 1.1.2.15 import harpoon.Temp.TempMap;
 8 cananian 1.1.2.4  import harpoon.Util.Util;
 9 duncan   1.1.2.1  
10 duncan   1.1.2.1  /**
11 duncan   1.1.2.1   * <code>THROW</code> objects are used to represent a thrown exception.
12 duncan   1.1.2.1   *
13 cananian 1.1.2.17  * @author   Duncan Bryce <duncan@lcs.mit.edu>, based on
14 duncan   1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
15 cananian 1.4       * @version  $Id: THROW.java,v 1.4 2002/04/10 03:05:45 cananian Exp $
16 duncan   1.1.2.1   */
17 cananian 1.1.2.4  public class THROW extends Stm implements Typed {
18 duncan   1.1.2.3      /** Constructor 
19 duncan   1.1.2.10      *  @param retex   the exceptional value to return 
20 duncan   1.1.2.10      *  @param handler the location of the exception-handling code to branch to
21 duncan   1.1.2.3       */
22 duncan   1.1.2.3      public THROW(TreeFactory tf, HCodeElement source, 
23 duncan   1.1.2.10                  Exp retex, Exp handler) {
24 cananian 1.1.2.14         super(tf, source, 2);
25 duncan   1.1.2.12         this.setRetex(retex);
26 cananian 1.1.2.14         this.setHandler(handler);
27 duncan   1.1.2.12 
28 cananian 1.3.2.1          assert retex.type()==POINTER; 
29 cananian 1.3.2.1          assert handler.type()==POINTER;
30 cananian 1.3.2.1          assert tf == retex.tf : "This and Retex must have same tree factory";
31 cananian 1.3.2.1          assert tf == handler.tf : "This and Handler must have the same tree factory";
32 duncan   1.1.2.3      }           
33 duncan   1.1.2.12     
34 cananian 1.1.2.14     /** The exceptional value to return */
35 cananian 1.1.2.14     public Exp getRetex() { return (Exp) getChild(0); }
36 cananian 1.1.2.14     /** The location of the exception-handling code */
37 cananian 1.1.2.14     public Exp getHandler() { return (Exp) getChild(1); } 
38 duncan   1.1.2.12 
39 cananian 1.1.2.14     /** Set the exceptional value to return */
40 cananian 1.1.2.14     public void setRetex(Exp retex) { setChild(0, retex); }
41 cananian 1.1.2.14     /** Set the location of the exception-handling code */
42 cananian 1.1.2.14     public void setHandler(Exp handler) { setChild(1, handler); }
43 duncan   1.1.2.1    
44 duncan   1.1.2.3      public int kind() { return TreeKind.THROW; }
45 duncan   1.1.2.7  
46 duncan   1.1.2.7      public Stm build(TreeFactory tf, ExpList kids) { 
47 cananian 1.3.2.1          assert kids!=null && kids.tail!=null && kids.tail.tail==null;
48 cananian 1.3.2.1          assert tf == kids.head.tf;
49 cananian 1.3.2.1          assert tf == kids.tail.head.tf;
50 duncan   1.1.2.10         return new THROW(tf, this, kids.head, kids.tail.head);
51 duncan   1.1.2.3      }
52 duncan   1.1.2.1  
53 duncan   1.1.2.3      /** Accept a visitor */
54 cananian 1.1.2.11     public void accept(TreeVisitor v) { v.visit(this); }
55 duncan   1.1.2.1  
56 cananian 1.1.2.15     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
57 cananian 1.1.2.15         return cb.callback(this,
58 cananian 1.1.2.15                            new THROW(tf,this,
59 cananian 1.1.2.15                                      (Exp)getRetex().rename(tf, tm, cb),
60 cananian 1.1.2.16                                      (Exp)getHandler().rename(tf, tm, cb)),
61 cananian 1.1.2.16                            tm);
62 duncan   1.1.2.3      }
63 duncan   1.1.2.1  
64 cananian 1.1.2.4      /** @return <code>Type.POINTER</code> */
65 cananian 1.1.2.4      public int type() { return POINTER; }
66 cananian 1.1.2.4      public boolean isDoubleWord() { return Type.isDoubleWord(tf, POINTER); }
67 cananian 1.1.2.4      public boolean isFloatingPoint() { return false; }
68 cananian 1.1.2.4      
69 duncan   1.1.2.3      public String toString() {
70 cananian 1.1.2.14         return "THROW(#"+getRetex().getID()+", "+getHandler().getID()+")";
71 duncan   1.1.2.3      }
72 cananian 1.2      }