xtc.type
Class Reference

java.lang.Object
  extended by xtc.type.Reference
Direct Known Subclasses:
NullReference, RelativeReference, StringReference, VariableReference

public abstract class Reference
extends java.lang.Object

Representation of a reference. A reference represents a specific region of memory. It has a type, which determines the layout of the referenced memory region. Furthermore, it may optionally have a base and an offset, indicating a memory region relative to another. The optional base is a reference, and the optional offset is either an index or a field.

Version:
$Revision: 1.13 $
Author:
Robert Grimm

Field Summary
protected  Type type
          The type.
 
Constructor Summary
Reference(Type type)
          Create a new reference.
 
Method Summary
 Reference add(java.math.BigInteger val)
          Add the specified value to this reference.
 Reference add(long val)
          Add the specified value to this reference.
 java.math.BigInteger difference(Reference ref)
          Determine the difference between the two references.
 Reference getBase()
          Get this reference's base.
 java.lang.String getField()
          Get this reference's field.
 java.math.BigInteger getIndex()
          Get this reference's index.
 java.math.BigInteger getLocation(C ops)
          Get this reference's absolute memory location.
 Type getType()
          Get this reference's type.
 boolean hasBase()
          Determine whether this reference has a base.
 boolean hasField()
          Determine whether this reference has a field.
 boolean hasIndex()
          Determine whether this reference has an index.
 boolean hasLocation()
          Determine whether this reference has an absolute memory location.
 Reference indirect(Type type)
          Indirect this reference.
 boolean isCast()
          Determine whether this reference is a cast reference.
 boolean isConstant()
          Determine whether this reference represents a compile-time constant memory location.
 boolean isDynamic()
          Determine whether this reference is a dynamic reference.
 boolean isIndirect()
          Determine whether this reference is an indirect reference.
 boolean isNull()
          Determine whether this reference is a null reference.
 boolean isPrefix()
          Determine whether this reference represents a prefix operator in C syntax.
 boolean isStatic()
          Determine whether this reference is a static reference.
 boolean isString()
          Determine whether this reference is a string reference.
 boolean isVariable()
          Determine whether this reference is a variable reference.
 Reference subtract(java.math.BigInteger val)
          Subtract the specified value from this reference.
 Reference subtract(long val)
          Subtract the specified value from this reference.
 java.lang.String toString()
           
abstract  void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected final Type type
The type.

Constructor Detail

Reference

public Reference(Type type)
Create a new reference. Note that this constructor resolves the specified type and strips any arrays.

Parameters:
type - The type.
Method Detail

getType

public Type getType()
Get this reference's type.

Returns:
The type.

isNull

public boolean isNull()
Determine whether this reference is a null reference. Note that a reference other than NullReference.NULL may still return true; notably, an index reference with a null base and a zero offset still is null.

Returns:
true if this reference is a null reference.
See Also:
NullReference

isString

public boolean isString()
Determine whether this reference is a string reference.

Returns:
true if this reference is a string reference.
See Also:
StringReference

isVariable

public boolean isVariable()
Determine whether this reference is a variable reference.

Returns:
true if this reference is a variable reference.
See Also:
VariableReference

isStatic

public boolean isStatic()
Determine whether this reference is a static reference.

Returns:
true if this reference is a static reference.
See Also:
StaticReference

isDynamic

public boolean isDynamic()
Determine whether this reference is a dynamic reference.

Returns:
true if this reference is a dynamic reference.
See Also:
DynamicReference

isPrefix

public boolean isPrefix()
Determine whether this reference represents a prefix operator in C syntax.

Returns:
true if this reference represents a prefix operator.

isCast

public boolean isCast()
Determine whether this reference is a cast reference.

Returns:
true if this reference is a cast reference.

isIndirect

public boolean isIndirect()
Determine whether this reference is an indirect reference.

Returns:
true if this reference is an indirect reference.

hasBase

public boolean hasBase()
Determine whether this reference has a base.

Returns:
true if this reference has a base.
See Also:
RelativeReference

getBase

public Reference getBase()
Get this reference's base.

Returns:
The base.
Throws:
java.lang.IllegalStateException - Signals that this reference does not have a base.
See Also:
RelativeReference

hasIndex

public boolean hasIndex()
Determine whether this reference has an index.

Returns:
true if this reference has an index.
See Also:
IndexReference

getIndex

public java.math.BigInteger getIndex()
Get this reference's index.

Returns:
The index.
Throws:
java.lang.IllegalStateException - Signals that this reference does not have an index.

hasField

public boolean hasField()
Determine whether this reference has a field.

Returns:
true if this reference has a field.
See Also:
FieldReference

getField

public java.lang.String getField()
Get this reference's field.

Returns:
The field.
Throws:
java.lang.IllegalStateException - Signals that this reference does not have a field.

hasLocation

public boolean hasLocation()
Determine whether this reference has an absolute memory location.

Returns:
true if this reference has an absolute memory location.

getLocation

public java.math.BigInteger getLocation(C ops)
Get this reference's absolute memory location.

Parameters:
ops - The C operations.
Returns:
The memory location.
Throws:
java.lang.IllegalStateException - Signals that this reference does not have an absolute memory location.

isConstant

public boolean isConstant()
Determine whether this reference represents a compile-time constant memory location.

Returns:
true if this reference represents a compile-time memory location.

indirect

public Reference indirect(Type type)
Indirect this reference. This method determines the appropriate reference when using a pointer-decayed type. For arrays and functions, it simly returns this reference. For all other types, it returns an indirect reference, with this reference as the base.

Parameters:
type - The reference's declared type (before pointer decay).

add

public Reference add(long val)
Add the specified value to this reference.

Parameters:
val - The value.
Returns:
A reference with an index increased by val.

add

public Reference add(java.math.BigInteger val)
Add the specified value to this reference.

Parameters:
val - The value.
Returns:
A reference with an index increased by val.

subtract

public Reference subtract(long val)
Subtract the specified value from this reference.

Parameters:
val - The value.
Returns:
A reference with an index decreased by val.

subtract

public Reference subtract(java.math.BigInteger val)
Subtract the specified value from this reference.

Parameters:
val - The value.
Returns:
A reference with an index decreased by val.

difference

public java.math.BigInteger difference(Reference ref)
Determine the difference between the two references.

Parameters:
ref - The other reference.
Returns:
The difference or null if the difference cannot be statically determined.

write

public abstract void write(java.lang.Appendable out)
                    throws java.io.IOException
Write a human readable representation to the specified appendable.

Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2012. All Rights Reserved.