harpoon.IR.Tree
Class CONST

java.lang.Object
  extended by harpoon.IR.Tree.Tree
      extended by harpoon.IR.Tree.Exp
          extended by harpoon.IR.Tree.CONST
All Implemented Interfaces:
HCodeElement, HDataElement, PreciselyTyped, Typed

public class CONST
extends Exp
implements PreciselyTyped, HDataElement

CONST objects are expressions which stand for a constant value. CONSTs should be used to represent numeric types only. The one notable exception is the constant null, which is represented by a CONST with value == null and type == POINTER.

Version:
$Id: CONST.java,v 1.4 2002/04/10 03:05:40 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>, based on Modern Compiler Implementation in Java by Andrew Appel.

Nested Class Summary
 
Nested classes/interfaces inherited from class harpoon.IR.Tree.Tree
Tree.CloneCallback
 
Field Summary
 boolean isSmall
           
 int type
          The type of this CONST expression.
 Number value
          The constant value of this CONST expression.
 
Fields inherited from class harpoon.IR.Tree.Tree
arrayFactory, child
 
Fields inherited from interface harpoon.IR.Tree.Typed
DOUBLE, FLOAT, INT, LONG, POINTER
 
Constructor Summary
CONST(TreeFactory tf, HCodeElement source)
          Creates a CONST representing the constant null.
CONST(TreeFactory tf, HCodeElement source, double dval)
           
CONST(TreeFactory tf, HCodeElement source, float fval)
           
CONST(TreeFactory tf, HCodeElement source, int ival)
           
CONST(TreeFactory tf, HCodeElement source, int bitwidth, boolean signed, int val)
          Creates a CONST with a precisely defined type.
CONST(TreeFactory tf, HCodeElement source, long lval)
           
 
Method Summary
 void accept(TreeVisitor v)
          Accept a visitor
 int bitwidth()
          Returns the size of the expression, in bits.
 Exp build(TreeFactory tf, ExpList kids)
           
 boolean isSmall()
          Returns true if this is a sub-integer expression.
 int kind()
          Return an integer enumeration of the kind of this Tree.
 Tree rename(TreeFactory tf, TempMap tm, Tree.CloneCallback cb)
          Rename while cloning a subtree.
 boolean signed()
          Returns true if this is a signed expression, false otherwise.
 String toString()
           
 int type()
          Result type.
 Number value()
          Return the constant value of this CONST expression.
 
Methods inherited from class harpoon.IR.Tree.Exp
build, isDoubleWord, isFloatingPoint
 
Methods inherited from class harpoon.IR.Tree.Tree
clone, clone, getChild, getFactory, getFirstChild, getID, getLineNumber, getParent, getSibling, getSourceFile, hashCode, kids, rename, replace, setChild, unlink
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface harpoon.IR.Tree.Typed
isDoubleWord, isFloatingPoint
 
Methods inherited from interface harpoon.ClassFile.HDataElement
getID, getSourceFile
 

Field Detail

value

public final Number value
The constant value of this CONST expression.


type

public final int type
The type of this CONST expression.


isSmall

public final boolean isSmall
Constructor Detail

CONST

public CONST(TreeFactory tf,
             HCodeElement source,
             int ival)

CONST

public CONST(TreeFactory tf,
             HCodeElement source,
             long lval)

CONST

public CONST(TreeFactory tf,
             HCodeElement source,
             float fval)

CONST

public CONST(TreeFactory tf,
             HCodeElement source,
             double dval)

CONST

public CONST(TreeFactory tf,
             HCodeElement source)
Creates a CONST representing the constant null.


CONST

public CONST(TreeFactory tf,
             HCodeElement source,
             int bitwidth,
             boolean signed,
             int val)
Creates a CONST with a precisely defined type. For example, CONST(tf, src, 8, true, 0xFF) corresponds to the value -1, as a byte. CONST(tf, src, 8, true, -1) also corresponds to the value -1 as a byte.

Parameters:
bitwidth - the width in bits of this CONST's type. Fails unless 0 <= bitwidth < 32.
signed - whether this CONST is signed
val - the value of this CONST. Note that only the lower bitwidth bits of this parameter will actually be used.
Method Detail

value

public Number value()
Return the constant value of this CONST expression.


kind

public int kind()
Description copied from class: Tree
Return an integer enumeration of the kind of this Tree. The enumerated values are defined in TreeKind.

Specified by:
kind in class Tree

build

public Exp build(TreeFactory tf,
                 ExpList kids)
Specified by:
build in class Exp

type

public int type()
Description copied from class: Exp
Result type.

Specified by:
type in interface Typed
Specified by:
type in class Exp

isSmall

public boolean isSmall()
Returns true if this is a sub-integer expression.

Specified by:
isSmall in interface PreciselyTyped

bitwidth

public int bitwidth()
Returns the size of the expression, in bits. Only valid if the isSmall()==true.

Specified by:
bitwidth in interface PreciselyTyped

signed

public boolean signed()
Returns true if this is a signed expression, false otherwise. Only valid if the isSmall()==true.

Specified by:
signed in interface PreciselyTyped

accept

public void accept(TreeVisitor v)
Accept a visitor

Specified by:
accept in class Tree

rename

public Tree rename(TreeFactory tf,
                   TempMap tm,
                   Tree.CloneCallback cb)
Description copied from class: Tree
Rename while cloning a subtree. This node and all child nodes are cloned; the 'temp' information of all TEMP nodes are renamed according to the supplied TempMap. Note that Temps not belonging to this.getFactory().tempFactory() are not affected. The callback() method of the supplied CloneCallback is invoked once on each subtree cloned, starting from the leaves and working back to the root in a post-order depth-first manner.

Specified by:
rename in class Tree

toString

public String toString()
Overrides:
toString in class Object