1 cananian 1.1.2.4 // UndefinedPointer.java, created Sat Mar 27 17:05:10 1999 by duncan 2 cananian 1.1.2.3 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu> 3 cananian 1.1.2.3 // 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.ClassFile.HClass; 7 duncan 1.1.2.1 import harpoon.IR.Tree.NAME; 8 duncan 1.1.2.1 import harpoon.Temp.Label; 9 duncan 1.1.2.1 import harpoon.Util.Tuple; 10 duncan 1.1.2.1 11 duncan 1.1.2.1 /** 12 duncan 1.1.2.1 * The <code>UndefinedPointer</code> class represents a pointer to a 13 duncan 1.1.2.1 * value for which the type is not known. It is an error to access 14 duncan 1.1.2.1 * the value of this pointer until it is converted to a pointer of another 15 duncan 1.1.2.1 * type. 16 duncan 1.1.2.1 * 17 duncan 1.1.2.1 * @author Duncan Bryce <duncan@lcs.mit.edu> 18 cananian 1.2 * @version $Id: UndefinedPointer.java,v 1.2 2002/02/25 21:06:01 cananian Exp $ 19 duncan 1.1.2.1 */ 20 duncan 1.1.2.1 public class UndefinedPointer extends Pointer { 21 duncan 1.1.2.1 22 duncan 1.1.2.1 // Private constructor used to add two UndefinedPointers 23 duncan 1.1.2.1 private UndefinedPointer(UndefinedPointer ptr, long offset) { 24 duncan 1.1.2.1 this((UndefinedRef)ptr.getBase(), ptr.getOffset() + offset); 25 duncan 1.1.2.1 } 26 duncan 1.1.2.1 27 duncan 1.1.2.1 /** Class constructor */ 28 duncan 1.1.2.1 public UndefinedPointer(UndefinedRef ref, long offset) { 29 duncan 1.1.2.1 super(new Object[] { ref, new Long(offset) }); 30 duncan 1.1.2.1 } 31 duncan 1.1.2.1 32 duncan 1.1.2.1 /** Adds the specified offset to the offset of this 33 duncan 1.1.2.1 * <code>UndefinedPointer</code> and returns the resulting pointer. */ 34 duncan 1.1.2.1 public Pointer add(long offset) { 35 duncan 1.1.2.1 return new UndefinedPointer(this, offset); 36 duncan 1.1.2.1 } 37 duncan 1.1.2.1 38 duncan 1.1.2.1 /** Returns an <code>UndefinedRef</code> object representing the 39 duncan 1.1.2.1 * base of this <code>UndefinedPointer</code>. */ 40 duncan 1.1.2.1 public Object getBase() { 41 duncan 1.1.2.1 return ((UndefinedRef)proj(0)); 42 duncan 1.1.2.1 } 43 duncan 1.1.2.1 44 duncan 1.1.2.1 /** Returns the offset of this <code>UndefinedPointer</code>. */ 45 duncan 1.1.2.1 public long getOffset() { 46 duncan 1.1.2.1 return ((Long)proj(1)).longValue(); 47 duncan 1.1.2.1 } 48 duncan 1.1.2.1 49 duncan 1.1.2.1 /** Throws an error. */ 50 duncan 1.1.2.1 Object getValue() { 51 duncan 1.1.2.1 throw new Error("Can't get value of an UndefinedPointer!"); 52 duncan 1.1.2.1 } 53 duncan 1.1.2.1 54 duncan 1.1.2.1 /** Always returns false. */ 55 duncan 1.1.2.1 public boolean isConst() { return false; } 56 duncan 1.1.2.1 57 duncan 1.1.2.1 /** Always returns false. */ 58 duncan 1.1.2.1 public boolean isDerived() { return false; } 59 duncan 1.1.2.2 60 duncan 1.1.2.2 /** Returns an integer enumeration of the kind of this Pointer. The 61 duncan 1.1.2.2 enumerated values are public fields of the Pointer class. 62 duncan 1.1.2.2 */ 63 duncan 1.1.2.2 public int kind() { return Pointer.UNDEF_PTR; } 64 duncan 1.1.2.1 65 duncan 1.1.2.1 /** Returns a human-readable representation of this 66 duncan 1.1.2.1 * <code>UndefinedPointer</code>. */ 67 duncan 1.1.2.1 public String toString() { 68 duncan 1.1.2.1 StringBuffer sb = new StringBuffer("UndefPtr: < "); 69 duncan 1.1.2.1 sb.append(getOffset()); 70 duncan 1.1.2.1 sb.append(" >"); 71 duncan 1.1.2.1 return sb.toString(); 72 duncan 1.1.2.1 } 73 duncan 1.1.2.1 74 duncan 1.1.2.1 /** Updates the value at the location pointed to by this 75 duncan 1.1.2.1 * <code>UndefinedPointer</code> to have the specified value. */ 76 duncan 1.1.2.1 void updateValue(Object value) { 77 duncan 1.1.2.1 UndefinedRef.update(this, value); 78 duncan 1.1.2.1 } 79 duncan 1.1.2.1 } 80 cananian 1.2