1 cananian 1.1     // TypeMap.java, created Wed Aug 19 01:02:27 1998 by cananian
 2 cananian 1.3     // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.3     // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1     package harpoon.Analysis.Maps;
 5 cananian 1.1     
 6 cananian 1.1     import harpoon.Temp.Temp;
 7 cananian 1.1     import harpoon.ClassFile.HClass;
 8 duncan   1.3.2.2 import harpoon.ClassFile.HCodeElement;
 9 cananian 1.1     
10 cananian 1.1     /**
11 cananian 1.2      * A <code>TypeMap</code> is a mapping from temporaries to their types.
12 cananian 1.1      * 
13 cananian 1.1      * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
14 cananian 1.5      * @version $Id: TypeMap.java,v 1.5 2002/09/02 19:23:26 cananian Exp $
15 cananian 1.1      */
16 cananian 1.5     public interface TypeMap<HCE extends HCodeElement>  { 
17 cananian 1.1         /** 
18 cananian 1.3.2.3      * Return the type of a given temporary <code>t</code>, as defined
19 cananian 1.3.2.3      * at the definition point <code>hce</code>.  Iff the type of the
20 cananian 1.3.2.3      * temporary is not known, or if <code>hce</code> does not define
21 cananian 1.3.2.3      * <code>t</code>, throws <code>TypeNotKnownException</code>.  If
22 cananian 1.3.2.3      * the temporary represents a derived pointer, <code>null</code>
23 cananian 1.3.2.3      * should be returned; in which case the <code>Derivation</code>
24 cananian 1.3.2.3      * <b>must</b> return a non-<code>null</code> value.  Obviously,
25 cananian 1.3.2.3      * <code>TypeMap</code>s for high-level representations without
26 cananian 1.3.2.3      * derived pointers should never return <code>null</code>.  As a
27 cananian 1.3.2.3      * special case, <code>HClass.Void</code> may be returned in
28 cananian 1.3.2.3      * low-level IRs to indicate an opaque pointer value which does
29 cananian 1.3.2.3      * <b>not</b> correspond to a java object pointer or some
30 cananian 1.3.2.3      * derivation thereof --- for example, a pointer into a method
31 cananian 1.3.2.4      * dispatch table.  The only other time <code>HClass.Void</code>
32 cananian 1.3.2.4      * should be returned is for known-<code>null</code> pointer values.
33 duncan   1.3.2.1      * 
34 cananian 1.3.2.3      * @param hce The <code>HCodeElement</code> defining <code>t</code>.
35 cananian 1.1          * @param t The temporary to examine.
36 duncan   1.3.2.1      * @return the static type of <code>t</code>.  
37 cananian 1.3.2.3      * @exception NullPointerException if <code>t</code> or <code>hc</code>
38 cananian 1.3.2.3      *            is <code>null</code>.
39 cananian 1.3.2.3      * @exception TypeNotKnownException if the <code>TypeMap</code> does
40 cananian 1.3.2.3      *            not have any information about <code>t</code> as defined
41 cananian 1.3.2.3      *            at <code>hc</code>.  */
42 cananian 1.5         public HClass typeMap(HCE hce, Temp t)
43 cananian 1.3.2.3         throws TypeNotKnownException;
44 cananian 1.3.2.3 
45 cananian 1.3.2.3     /** <code>TypeNotKnownException</code> is thrown to indicate that
46 cananian 1.3.2.3      *  the <code>TypeMap</code> does not have type information for the
47 cananian 1.3.2.3      *  specified <code>Temp</code> in the given <code>HCodeElement</code>.
48 cananian 1.3.2.3      *  This could be because the <code>HCodeElement</code> does not
49 cananian 1.3.2.3      *  define the specified <code>Temp</code>, or because the type
50 cananian 1.3.2.3      *  analysis was faulty.  In either case, this exception should
51 cananian 1.3.2.3      *  never be caught -- it indicates a flaw in either the type
52 cananian 1.3.2.3      *  analysis or the querying method, which should be fixed. */
53 cananian 1.3.2.3     public static class TypeNotKnownException extends RuntimeException {
54 cananian 1.3.2.3         public TypeNotKnownException(HCodeElement hce, Temp t) {
55 cananian 1.3.2.3             super("Type not known for Temp "+t+" in "+hce);
56 cananian 1.3.2.3         }
57 cananian 1.3.2.3     }
58 cananian 1.1     }