cetus.hir
Class Statement

java.lang.Object
  extended by cetus.hir.Statement
All Implemented Interfaces:
Annotatable, Printable, Traversable, java.lang.Cloneable
Direct Known Subclasses:
AnnotationStatement, BreakStatement, Case, CompoundStatement, ContinueStatement, DeclarationStatement, Default, DoLoop, ExpressionStatement, ForLoop, GotoStatement, IfStatement, Label, NullStatement, ReturnStatement, SwitchStatement, WhileLoop

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

Base class for all statements. Statement is the base class of numerous specific statement classes. Use the Java instanceof operator to determine the specific type of a Statement.


Field Summary
protected  java.util.List<Annotation> annotations
           
protected  java.util.LinkedList<Traversable> children
           
protected  int line_number
           
protected  java.lang.reflect.Method object_print_method
           
protected  Traversable parent
           
 
Constructor Summary
protected Statement()
          Constructor for derived classes.
protected Statement(int size)
          Constructor for derived classes that preallocates space for multiple children.
 
Method Summary
 void annotate(Annotation annotation)
          Annotates with the given annotation.
 void annotateAfter(Annotation annotation)
           
 void annotateBefore(Annotation annotation)
           
 java.lang.String annotationToString(int position)
          Returns the string representation of the annotations with the given relative position.
 java.lang.Object clone()
           
 boolean containsAnnotation(java.lang.Class<? extends Annotation> type, java.lang.String key)
          Checks if this annotatable contains the specified annotation type and key.
 void detach()
          Detaches this statement from it's parent, if it has one.
<T extends Annotation>
T
getAnnotation(java.lang.Class<T> type, java.lang.String key)
          Returns the annotation with the specified type and key.
 java.util.List<Annotation> getAnnotations()
          Returns the list of annotations.
<T extends Annotation>
java.util.List<T>
getAnnotations(java.lang.Class<T> type)
          Returns the list of annotations with the given type.
 java.util.List<Annotation> getAnnotations(int position)
          Returns the list of annotations with the given relative position.
 java.util.List<Traversable> getChildren()
          Provides access to the children of this object as a list.
 Traversable getParent()
          Provides access to the parent of this object.
 Procedure getProcedure()
          Returns the procedure in which this statement is located.
 void print(java.io.OutputStream stream)
          Print the code for the IR represented by the object.
 void removeAnnotations()
          Remove all annotations.
 void removeAnnotations(java.lang.Class<?> type)
          Remove all annotations of the given type.
 void removeChild(Traversable child)
          Removes a specific child of this statement; some statements do not support this method.
 void setChild(int index, Traversable t)
          Sets the indexth child of this object to t.
 void setLineNumber(int line)
          Sets the line number of this statement This function is to be used only for parser development
 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.
 void swapWith(Statement stmt)
          Swaps two statements on the IR tree.
 java.lang.String toAnnotatedString()
          Returns the string representation of the object with annotations being printed as well.
abstract  java.lang.String toString()
          Returns a string representation of this statement; every child class should implement this method.
 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.
 int where()
          Returns the line number of this statement if the statement was present in the original source file.
 
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

line_number

protected int line_number

annotations

protected java.util.List<Annotation> annotations
Constructor Detail

Statement

protected Statement()
Constructor for derived classes.


Statement

protected Statement(int size)
Constructor for derived classes that preallocates space for multiple children.

Parameters:
size - The expected number of children for this statement.
Method Detail

clone

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

detach

public void detach()
Detaches this statement 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 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.

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.

getProcedure

public Procedure getProcedure()
Returns the procedure in which this statement is located.

Returns:
the procedure in which this statement is located, or null if it is not in a procedure. It is possible for a DeclarationStatement to be located somewhere other than a procedure.

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)
Removes a specific child of this statement; some statements do not support this method.

Specified by:
removeChild in interface Traversable
Parameters:
child - The child to remove.

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.

swapWith

public void swapWith(Statement stmt)
Swaps two statements on the IR tree. If neither this statement nor stmt has a parent, then this function has no effect. Otherwise, each statement ends up with the other's parent.

Parameters:
stmt - The statement with which to swap this statement.
Throws:
java.lang.IllegalArgumentException - if stmt is null.
java.lang.IllegalStateException - if the types of the statements are such that they would create inconsistent IR when swapped.

setLineNumber

public void setLineNumber(int line)
Sets the line number of this statement This function is to be used only for parser development

Parameters:
line - The line number

toString

public abstract java.lang.String toString()
Returns a string representation of this statement; every child class should implement this method.

Overrides:
toString in class java.lang.Object

where

public int where()
Returns the line number of this statement if the statement was present in the original source file. Line numbers are not available for statements that are added by compiler passes.

Returns:
the line number of this statement.

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.

annotate

public void annotate(Annotation annotation)
Description copied from interface: Annotatable
Annotates with the given annotation.

Specified by:
annotate in interface Annotatable

annotateAfter

public void annotateAfter(Annotation annotation)
Specified by:
annotateAfter in interface Annotatable

annotateBefore

public void annotateBefore(Annotation annotation)
Specified by:
annotateBefore in interface Annotatable

getAnnotations

public java.util.List<Annotation> getAnnotations()
Description copied from interface: Annotatable
Returns the list of annotations.

Specified by:
getAnnotations in interface Annotatable

getAnnotations

public <T extends Annotation> java.util.List<T> getAnnotations(java.lang.Class<T> type)
Description copied from interface: Annotatable
Returns the list of annotations with the given type.

Specified by:
getAnnotations in interface Annotatable

containsAnnotation

public boolean containsAnnotation(java.lang.Class<? extends Annotation> type,
                                  java.lang.String key)
Description copied from interface: Annotatable
Checks if this annotatable contains the specified annotation type and key.

Specified by:
containsAnnotation in interface Annotatable

getAnnotation

public <T extends Annotation> T getAnnotation(java.lang.Class<T> type,
                                              java.lang.String key)
Description copied from interface: Annotatable
Returns the annotation with the specified type and key.

Specified by:
getAnnotation in interface Annotatable

getAnnotations

public java.util.List<Annotation> getAnnotations(int position)
Description copied from interface: Annotatable
Returns the list of annotations with the given relative position.

Specified by:
getAnnotations in interface Annotatable

removeAnnotations

public void removeAnnotations()
Description copied from interface: Annotatable
Remove all annotations.

Specified by:
removeAnnotations in interface Annotatable

removeAnnotations

public void removeAnnotations(java.lang.Class<?> type)
Description copied from interface: Annotatable
Remove all annotations of the given type.

Specified by:
removeAnnotations in interface Annotatable

annotationToString

public java.lang.String annotationToString(int position)
Description copied from interface: Annotatable
Returns the string representation of the annotations with the given relative position.

Specified by:
annotationToString in interface Annotatable

toAnnotatedString

public java.lang.String toAnnotatedString()
Description copied from interface: Annotatable
Returns the string representation of the object with annotations being printed as well.

Specified by:
toAnnotatedString in interface Annotatable