cetus.hir
Class Declaration

java.lang.Object
  extended by cetus.hir.Declaration
All Implemented Interfaces:
Printable, Traversable, java.lang.Cloneable
Direct Known Subclasses:
AccessLevel, Annotation, ClassDeclaration, Enumeration, LinkageSpecification, Namespace, NamespaceAlias, Procedure, TemplateDeclaration, UsingDeclaration, UsingDirective, VariableDeclaration

public abstract class Declaration
extends java.lang.Object
implements java.lang.Cloneable, Traversable

Base class for all declarations (special objects that result in new symbol table entries when they are added to an instance of a class that implements SymbolTable).


Field Summary
protected  java.util.ArrayList<Traversable> children
           
protected  java.lang.reflect.Method object_print_method
           
protected  Traversable parent
           
 
Constructor Summary
protected Declaration()
          Base constructor for derived classes.
protected Declaration(int size)
          Base constructor for derived classes; sets an initial size for the list of children of this declaration.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a deep copy of this declaration.
 void detach()
          Detaches this declaration from it's parent, if it has one.
 java.util.List<Traversable> getChildren()
          Provides access to the children of this object as a list.
abstract  java.util.List getDeclaredSymbols()
          Returns a list of IDExpressions that are the symbols introduced by this declaration.
 Traversable getParent()
          Provides access to the parent of this object.
 void print(java.io.OutputStream stream)
          Print the code for the IR represented by the object.
 void removeChild(Traversable child)
          Removes the specified child.
 void setChild(int index, Traversable t)
          Sets the indexth child of this object to t.
 void setParent(Traversable t)
          Sets the parent of this object.
 void setPrintMethod(java.lang.reflect.Method m)
          Overrides the print method for this object only.
 java.lang.String toString()
           
 void verify()
          Verifies three properties of this object: (1) All children are not null, (2) the parent object has this object as a child, (3) all children have this object as the parent.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

object_print_method

protected java.lang.reflect.Method object_print_method

parent

protected Traversable parent

children

protected java.util.ArrayList<Traversable> children
Constructor Detail

Declaration

protected Declaration()
Base constructor for derived classes.


Declaration

protected Declaration(int size)
Base constructor for derived classes; sets an initial size for the list of children of this declaration.

Parameters:
size - The initial size for the child list.
Method Detail

clone

public java.lang.Object clone()
Creates and returns a deep copy of this declaration.

Overrides:
clone in class java.lang.Object
Returns:
a deep copy of this declaration.

detach

public void detach()
Detaches this declaration from it's parent, if it has one.


getChildren

public java.util.List<Traversable> getChildren()
Description copied from interface: Traversable
Provides access to the children of this object as a list. This object is free to internally implement its list as a LinkedList or an ArrayList. It is generally not good practice to call this method yourself; the ordering of children is not guaranteed so instead you should use the methods of the particular class whose children you wish to access.

Specified by:
getChildren in interface Traversable
Returns:
the children as a list.

getDeclaredSymbols

public abstract java.util.List getDeclaredSymbols()
Returns a list of IDExpressions that are the symbols introduced by this declaration.

Returns:
a list of IDExpressions. The list will not be null but may be empty.

getParent

public Traversable getParent()
Description copied from interface: Traversable
Provides access to the parent of this object. Every IR object has at most one parent. (The parent relationship is the same as the parent relationship in the parse tree, and is not to be confused with the base class of a derived class declaration.)

Specified by:
getParent in interface Traversable
Returns:
the parent of this object.

print

public void print(java.io.OutputStream stream)
Description copied from interface: Printable
Print the code for the IR represented by the object. Always calls object_print_method(this, stream). If the object's print method is null, nothing is printed; this provides an easy mechanism to temporarily hide something.

Specified by:
print in interface Printable
Parameters:
stream - The stream on which to print the data.

toString

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

removeChild

public void removeChild(Traversable child)
Description copied from interface: Traversable
Removes the specified child.

Specified by:
removeChild in interface Traversable
Parameters:
child - a reference to a child object that must match with ==.

setChild

public void setChild(int index,
                     Traversable t)
Description copied from interface: Traversable
Sets the indexth child of this object to t. It is generally not good practice to call this method yourself; the ordering of children is not guaranteed so instead you should use the methods of the particular class whose children you wish to access. There are checks to prevent such actions as making a statement a child of an expression, but you still may be able to do some damage with this method if you are not careful.

Specified by:
setChild in interface Traversable

setParent

public void setParent(Traversable t)
Description copied from interface: Traversable
Sets the parent of this object. Cetus checks that the parent already considers this object a child. The intent is to maintain an ordering where first this object becomes a child of another object, and then this object is told who its parent is. Enforcing this order makes it easier for Cetus to enforce other invariants and ensure the IR is correct.

Specified by:
setParent in interface Traversable

setPrintMethod

public void setPrintMethod(java.lang.reflect.Method m)
Overrides the print method for this object only.

Parameters:
m - The new print method.

verify

public void verify()
            throws java.lang.IllegalStateException
Verifies three properties of this object: (1) All children are not null, (2) the parent object has this object as a child, (3) all children have this object as the parent.

Throws:
java.lang.IllegalStateException - if any of the properties are not true.