1 cananian 1.1.2.6 // InterfaceListPointer.java, created Sat Mar 27 17:05:08 1999 by duncan
 2 cananian 1.1.2.5 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu>
 3 cananian 1.1.2.5 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 duncan   1.1.2.1 package harpoon.Interpret.Tree;
 5 duncan   1.1.2.1 
 6 duncan   1.1.2.1 import harpoon.Util.Tuple;
 7 duncan   1.1.2.1 
 8 duncan   1.1.2.1 /**
 9 duncan   1.1.2.1  * The <code>InterfaceListPointer</code> is used to representing a pointer
10 duncan   1.1.2.1  * to a list of interfaces.  The pointers of this type resides inside
11 duncan   1.1.2.1  * the blocks of class data allocated by the class loader.
12 duncan   1.1.2.1  *
13 duncan   1.1.2.1  * @author  Duncan Bryce <duncan@lcs.mit.edu>
14 cananian 1.2      * @version $Id: InterfaceListPointer.java,v 1.2 2002/02/25 21:05:57 cananian Exp $
15 duncan   1.1.2.1  */
16 duncan   1.1.2.1 public class InterfaceListPointer extends Pointer {
17 duncan   1.1.2.1   
18 duncan   1.1.2.1     // Private constructor used to add two interface list pointers
19 duncan   1.1.2.1     private InterfaceListPointer(InterfaceListPointer ptr, long offset) {
20 duncan   1.1.2.1         this((InterfaceList)ptr.getBase(), offset + ptr.getOffset());
21 duncan   1.1.2.1     }
22 duncan   1.1.2.1 
23 duncan   1.1.2.1     /** Class constructor. */
24 duncan   1.1.2.1     InterfaceListPointer(InterfaceList list, long offset) {
25 duncan   1.1.2.1         super(new Object[] { list, new Long(offset) });
26 duncan   1.1.2.1     }
27 duncan   1.1.2.1 
28 duncan   1.1.2.1     /** Adds the specified parameter to this <code>ClazPointer</code>'s
29 duncan   1.1.2.1      *  offset */
30 duncan   1.1.2.1     public Pointer add(long offset) { 
31 duncan   1.1.2.1         return new InterfaceListPointer(this, offset);
32 duncan   1.1.2.1     }
33 duncan   1.1.2.1 
34 duncan   1.1.2.1     /** Returns true if <code>obj</code> is an 
35 duncan   1.1.2.1      *  <code>InterfaceListPointer</code> which points to the same location 
36 duncan   1.1.2.1      *  as this <code>InterfaceListPointer</code>.
37 duncan   1.1.2.1      */
38 duncan   1.1.2.1     public boolean equals(Object obj) {
39 cananian 1.1.2.3         InterfaceListPointer ptr;
40 cananian 1.1.2.3         if (this==obj) return true;
41 cananian 1.1.2.3         if (null==obj) return false;
42 cananian 1.1.2.3         try { ptr = (InterfaceListPointer)obj; }
43 cananian 1.1.2.3         catch (ClassCastException ignore) { return false; }
44 cananian 1.1.2.3         return ptr.getBase()==getBase() &&
45 cananian 1.1.2.3             ptr.getOffset()==getOffset();
46 duncan   1.1.2.1     }
47 duncan   1.1.2.1 
48 duncan   1.1.2.1     /** Returns an <code>InterfaceList</code> representing the base of this 
49 duncan   1.1.2.1      *  <code>InterfaceListPointer</code>.
50 duncan   1.1.2.1      */
51 duncan   1.1.2.1     public Object getBase() {
52 duncan   1.1.2.1         return proj(0);
53 duncan   1.1.2.1     }
54 duncan   1.1.2.1 
55 duncan   1.1.2.1     /** Returns the offset of this <code>ClazPointer</code>. */
56 duncan   1.1.2.1     public long getOffset() { 
57 duncan   1.1.2.1         return ((Long)proj(1)).longValue();
58 duncan   1.1.2.1     }
59 duncan   1.1.2.1 
60 duncan   1.1.2.1     /** Dereferences this <code>InterfaceListPointer</code> and returns the 
61 duncan   1.1.2.1      *  value it points to. */ 
62 duncan   1.1.2.1     public Object getValue() { 
63 duncan   1.1.2.1         return ((InterfaceList)getBase()).getInterface((int)getOffset());
64 duncan   1.1.2.1     }
65 duncan   1.1.2.1 
66 duncan   1.1.2.1     /** Always returns false. */
67 duncan   1.1.2.1     public boolean isConst()   { return false; }
68 duncan   1.1.2.1 
69 duncan   1.1.2.1     /** Always returns false. */
70 duncan   1.1.2.1     public boolean isDerived() { return false; }
71 duncan   1.1.2.4 
72 duncan   1.1.2.4     /** Returns an integer enumeration of the kind of this Pointer.  The 
73 duncan   1.1.2.4         enumerated values are public fields of the Pointer class.
74 duncan   1.1.2.4     */
75 duncan   1.1.2.4     public int kind() { return Pointer.IFACE_PTR; }
76 duncan   1.1.2.1 
77 duncan   1.1.2.1     /** Throws an error, as the program is not supposed to
78 duncan   1.1.2.1      *  modify static class data */
79 duncan   1.1.2.1     public void updateValue(Object obj) { 
80 duncan   1.1.2.1         throw new Error("Can't update the value of an InterfaceListPointer!");
81 duncan   1.1.2.1     }
82 duncan   1.1.2.1 
83 duncan   1.1.2.1     /** Returns a human-readable representation of this
84 duncan   1.1.2.1      *  <code>InterfaceListPointer</code>.
85 duncan   1.1.2.1      */
86 duncan   1.1.2.1     public String toString() {
87 duncan   1.1.2.1         StringBuffer sb = new StringBuffer("InterfaceListPtr <");
88 duncan   1.1.2.1         sb.append(getOffset());
89 duncan   1.1.2.1         sb.append(">");
90 duncan   1.1.2.1         return sb.toString();
91 duncan   1.1.2.1     }
92 duncan   1.1.2.1 }
93 duncan   1.1.2.1     
94 cananian 1.2