1 cananian 1.1.2.1 // ExactTypeMap.java, created Thu Aug 24 12:03:50 2000 by cananian
 2 cananian 1.1.2.1 // Copyright (C) 2000 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.Analysis.Maps;
 5 cananian 1.1.2.1 
 6 cananian 1.1.2.1 import harpoon.ClassFile.HClass;
 7 cananian 1.1.2.1 import harpoon.ClassFile.HCodeElement;
 8 cananian 1.1.2.1 import harpoon.Temp.Temp;
 9 cananian 1.1.2.1 
10 cananian 1.1.2.1 import java.io.Serializable;
11 cananian 1.1.2.1 import java.util.AbstractList;
12 cananian 1.1.2.1 /**
13 cananian 1.1.2.1  * <code>ExactTypeMap</code> is an extension of <code>TypeMap</code> that
14 cananian 1.1.2.1  * allows the indication of 'exact' types -- that is, temporaries that
15 cananian 1.1.2.1  * can be guaranteed to contain an object of the indicated type
16 cananian 1.1.2.1  * <strong>and not a subtype of that type</strong>.
17 cananian 1.1.2.1  * <p>
18 cananian 1.1.2.1  * Any <code>TypeMap</code> can be made into an <code>ExactTypeMap</code>
19 cananian 1.1.2.1  * by conservatively returning <code>typeMap(hce,t).isPrimitive()</code>
20 cananian 1.1.2.1  * to all calls to <code>isExactType()</code>.
21 cananian 1.1.2.1  * 
22 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
23 cananian 1.3      * @version $Id: ExactTypeMap.java,v 1.3 2002/09/02 19:23:26 cananian Exp $
24 cananian 1.1.2.1  */
25 cananian 1.3     public interface ExactTypeMap<HCE extends HCodeElement> extends TypeMap<HCE> {
26 cananian 1.1.2.1     /** Returns <code>true</code> if temporary <code>t</code> defined at
27 cananian 1.1.2.1      *  definition point <code>hce</code> contains an object of the
28 cananian 1.1.2.1      *  type returned by <code>typeMap(hce, t)</code> <strong>and not
29 cananian 1.1.2.1      *  a subtype of that type</strong>.  Returns <code>false</code> if
30 cananian 1.1.2.1      *  the object in <code>t</code> can be a subtype of the type returned
31 cananian 1.1.2.1      *  by <code>typeMap(hce, t)</code>.
32 cananian 1.1.2.1      *  <p>
33 cananian 1.1.2.1      *  If <code>typeMap()</code> returns a primitive type, then
34 cananian 1.1.2.1      *  <code>isExactType()</code> should return <code>true</code>.
35 cananian 1.1.2.1      *
36 cananian 1.1.2.1      * @param hce The <code>HCodeElement</code> defining <code>t</code> for
37 cananian 1.1.2.1      *        this request.
38 cananian 1.1.2.1      * @param t The <code>Temp</code> to examine.
39 cananian 1.1.2.1      * @return <code>true</code> if <code>t</code>'s type is exact,
40 cananian 1.1.2.1      *         <code>false</code> otherwise.
41 cananian 1.1.2.1      * @exception NullPointerException if <code>t</code> or <code>hce</code>
42 cananian 1.1.2.1      *            is <code>null</code>.
43 cananian 1.1.2.1      * @exception TypeNotKnownException if the <code>ExactTypeMap</code> does
44 cananian 1.1.2.1      *            not have any information about <code>t</code> as defined
45 cananian 1.1.2.1      *            at <code>hc</code>. */
46 cananian 1.3         public boolean isExactType(HCE hce, Temp t)
47 cananian 1.1.2.1         throws TypeMap.TypeNotKnownException;
48 cananian 1.1.2.1 
49 cananian 1.1.2.1     /** Implementors of <code>ExactTypeMap</code> will probably find this
50 cananian 1.1.2.1      *  pair type useful. */
51 cananian 1.1.2.1     static class ExactType extends AbstractList implements Serializable {
52 cananian 1.1.2.1         public final HClass type;
53 cananian 1.1.2.1         public final boolean isExact;
54 cananian 1.1.2.1         public ExactType(HClass type, boolean isExact) {
55 cananian 1.1.2.1             this.type = type; this.isExact = type.isPrimitive() || isExact;
56 cananian 1.1.2.1         }
57 cananian 1.1.2.1         public int size() { return 2; }
58 cananian 1.1.2.1         public Object get(int index) {
59 cananian 1.1.2.1             switch(index) {
60 cananian 1.1.2.1             case 0: return type;
61 cananian 1.1.2.1             case 1: return new Boolean(isExact);
62 cananian 1.1.2.1             default: throw new IndexOutOfBoundsException();
63 cananian 1.1.2.1             }
64 cananian 1.1.2.1         }
65 cananian 1.1.2.1     }
66 cananian 1.1.2.1 }
67 cananian 1.1.2.1 
68 cananian 1.2