cetus.hir
Class Declarator

java.lang.Object
  extended by cetus.hir.Declarator
All Implemented Interfaces:
Printable, Traversable, java.lang.Cloneable
Direct Known Subclasses:
NestedDeclarator, ProcedureDeclarator, VariableDeclarator

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

Represents the part of a declaration that is the name of the symbol, some type information, and initial values. This class actually is more similar to what the C++ grammar calls an init-declarator. Many different constructors are provided because Java does not have default arguments.


Field Summary
protected  java.util.LinkedList<Traversable> children
           
protected  java.util.List<Specifier> leading_specs
           
protected  java.lang.reflect.Method object_print_method
           
protected  Traversable parent
           
protected  java.util.List<Specifier> trailing_specs
           
 
Constructor Summary
protected Declarator()
           
protected Declarator(int size)
           
 
Method Summary
 void addParameter(Declaration decl)
           
 void addParameterAfter(Declaration ref, Declaration decl)
           
 void addParameterBefore(Declaration ref, Declaration decl)
           
 void addTrailingSpecifier(Specifier spec)
           
 java.lang.Object clone()
           
static void defaultPrint(Declarator decl, java.io.OutputStream stream)
          Prints a declarator to a stream.
 java.util.List<Specifier> getArraySpecifiers()
          Returns a List of ArraySpecifier
 java.util.List<Traversable> getChildren()
          Provides access to the children of this object as a list.
 Initializer getInitializer()
           
 java.util.List getParameters()
          Returns a List of Function Parameter
 Traversable getParent()
          Provides access to the parent of this object.
 java.util.List<Specifier> getSpecifiers()
           
 IDExpression getSymbol()
          Returns the symbol declared by this declarator.
 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 setInitializer(Initializer init)
          Sets the initial value of the variable.
 void setParent(Traversable t)
          Sets the parent of this object.
 java.lang.String toString()
           
 
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.LinkedList<Traversable> children

leading_specs

protected java.util.List<Specifier> leading_specs

trailing_specs

protected java.util.List<Specifier> trailing_specs
Constructor Detail

Declarator

protected Declarator()

Declarator

protected Declarator(int size)
Method Detail

addParameter

public void addParameter(Declaration decl)

addParameterBefore

public void addParameterBefore(Declaration ref,
                               Declaration decl)

addParameterAfter

public void addParameterAfter(Declaration ref,
                              Declaration decl)

addTrailingSpecifier

public void addTrailingSpecifier(Specifier spec)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

defaultPrint

public static void defaultPrint(Declarator decl,
                                java.io.OutputStream stream)
Prints a declarator to a stream.

Parameters:
decl - The declarator to print.
stream - The stream on which to print the declarator.

toString

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

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 LinkedList. 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.

getInitializer

public Initializer getInitializer()

getParameters

public java.util.List getParameters()
Returns a List of Function Parameter

Returns:
List null is returned when there is no Function Parameter in the Declarator

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.

getArraySpecifiers

public java.util.List<Specifier> getArraySpecifiers()
Returns a List of ArraySpecifier

Returns:
An empty list if there is no ArraySpecifier for this Declarator.

getSpecifiers

public java.util.List<Specifier> getSpecifiers()

getSymbol

public IDExpression getSymbol()
Returns the symbol declared by this declarator.


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.

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

setInitializer

public void setInitializer(Initializer init)
Sets the initial value of the variable. The initial value cannot be set in the constructor, for the purpose of limiting the number of constructors.

Parameters:
init - An initial value for the variable.

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