cetus.hir
Class ClassDeclaration

java.lang.Object
  extended by cetus.hir.Declaration
      extended by cetus.hir.ClassDeclaration
All Implemented Interfaces:
Printable, SymbolTable, Traversable, java.lang.Cloneable

public class ClassDeclaration
extends Declaration
implements SymbolTable

Represents a class, struct, or union. These are actually specifiers in C and C++, since variables can be declared immediately following the class declaration, but that's mostly syntactic sugar. We assume it can be split into a class declaration followed by a variable declaration. We have a single class representing all three (class, struct, union) because they are fundamentally the same except for default access levels and storage layout, which do not make a significant difference to source-to-source compilers. Anonymous structs should be given a unique name (most compilers do this internally anyway).


Nested Class Summary
static class ClassDeclaration.Key
           
 
Field Summary
static ClassDeclaration.Key CLASS
           
static ClassDeclaration.Key INTERFACE
           
static java.lang.reflect.Method print_as_cpp
           
static java.lang.reflect.Method print_as_java
           
static ClassDeclaration.Key STRUCT
           
static ClassDeclaration.Key UNION
           
 
Fields inherited from class cetus.hir.Declaration
children, object_print_method, parent
 
Constructor Summary
ClassDeclaration(ClassDeclaration.Key type, IDExpression name)
          Creates an empty class.
ClassDeclaration(ClassDeclaration.Key type, IDExpression name, boolean no_body)
          Creates a class.
ClassDeclaration(java.util.List class_specs, ClassDeclaration.Key type, IDExpression name)
           
 
Method Summary
 void addBaseClass(IDExpression name)
           
 void addBaseClass(Specifier access, Identifier name)
           
 void addBaseInterface(IDExpression name)
           
 void addDeclaration(Declaration decl)
          Add a declaration to the end of the set of declarations and place the declared symbols in the symbol table.
 void addDeclarationAfter(Declaration ref, Declaration decl)
          Add a declaration after the reference declaration.
 void addDeclarationBefore(Declaration ref, Declaration decl)
          Add a declaration before the reference declaration.
static void defaultPrint(ClassDeclaration decl, java.io.OutputStream stream)
          Prints a class to a stream.
 Declaration findSymbol(IDExpression name)
          Retrieves the declaration for a symbol, possibly searching through parent symbol tables.
 java.util.List getDeclaredSymbols()
          Returns a list of IDExpressions that are the symbols introduced by this declaration.
 ClassDeclaration.Key getKey()
           
 IDExpression getName()
           
 java.util.List getParentTables()
          Returns a list of symbol tables that are parents of this table in the distributed symbol table graph.
 java.util.HashMap getTable()
          Provides direct access to the symbol table; it's generally not a good idea to modify this directly.
static void printCpp(ClassDeclaration decl, java.io.OutputStream stream)
          Prints a C++ class to a stream.
static void printJava(ClassDeclaration decl, java.io.OutputStream stream)
          Prints a Java class to a stream.
 void removeChild(Traversable child)
          Removes the specified child.
static void setClassPrintMethod(java.lang.reflect.Method m)
          Overrides the class print method, so that all subsequently created objects will use the supplied method.
 java.lang.String toString()
           
 
Methods inherited from class cetus.hir.Declaration
clone, detach, getChildren, getParent, print, setChild, setParent, setPrintMethod, verify
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

print_as_cpp

public static final java.lang.reflect.Method print_as_cpp

print_as_java

public static final java.lang.reflect.Method print_as_java

CLASS

public static final ClassDeclaration.Key CLASS

STRUCT

public static final ClassDeclaration.Key STRUCT

UNION

public static final ClassDeclaration.Key UNION

INTERFACE

public static final ClassDeclaration.Key INTERFACE
Constructor Detail

ClassDeclaration

public ClassDeclaration(java.util.List class_specs,
                        ClassDeclaration.Key type,
                        IDExpression name)

ClassDeclaration

public ClassDeclaration(ClassDeclaration.Key type,
                        IDExpression name)
Creates an empty class.

Parameters:
type - Must be one of CLASS, STRUCT, UNION, or INTERFACE.
name - The name for the class.

ClassDeclaration

public ClassDeclaration(ClassDeclaration.Key type,
                        IDExpression name,
                        boolean no_body)
Creates a class.

Parameters:
type - Must be one of CLASS, STRUCT, UNION, or INTERFACE.
name - The name for the class.
no_body - True if this a forward declaration.
Method Detail

addBaseClass

public void addBaseClass(IDExpression name)

addBaseClass

public void addBaseClass(Specifier access,
                         Identifier name)

addBaseInterface

public void addBaseInterface(IDExpression name)

addDeclaration

public void addDeclaration(Declaration decl)
Description copied from interface: SymbolTable
Add a declaration to the end of the set of declarations and place the declared symbols in the symbol table.

Specified by:
addDeclaration in interface SymbolTable
Parameters:
decl - The declaration to add.

addDeclarationBefore

public void addDeclarationBefore(Declaration ref,
                                 Declaration decl)
Description copied from interface: SymbolTable
Add a declaration before the reference declaration.

Specified by:
addDeclarationBefore in interface SymbolTable
Parameters:
ref - The reference point.
decl - The declaration to add.

addDeclarationAfter

public void addDeclarationAfter(Declaration ref,
                                Declaration decl)
Description copied from interface: SymbolTable
Add a declaration after the reference declaration.

Specified by:
addDeclarationAfter in interface SymbolTable
Parameters:
ref - The reference point.
decl - The declaration to add.

defaultPrint

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

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

findSymbol

public Declaration findSymbol(IDExpression name)
Description copied from interface: SymbolTable
Retrieves the declaration for a symbol, possibly searching through parent symbol tables.

Specified by:
findSymbol in interface SymbolTable
Parameters:
name - The name of the symbol.

getDeclaredSymbols

public java.util.List getDeclaredSymbols()
Description copied from class: Declaration
Returns a list of IDExpressions that are the symbols introduced by this declaration.

Specified by:
getDeclaredSymbols in class Declaration
Returns:
a list of IDExpressions. The list will not be null but may be empty.

getKey

public ClassDeclaration.Key getKey()

getName

public IDExpression getName()

getParentTables

public java.util.List getParentTables()
Description copied from interface: SymbolTable
Returns a list of symbol tables that are parents of this table in the distributed symbol table graph. A list is necessary because representing multiple inheritence in C++ requires it. Note that the parent tables are not necessarily tables of the immediate parent. The list is all symbol tables enclosing this object which appear at the same level such that no other symbol tables appear between this object and those tables.

Specified by:
getParentTables in interface SymbolTable
Returns:
a List of SymbolTables.

getTable

public java.util.HashMap getTable()
Description copied from interface: SymbolTable
Provides direct access to the symbol table; it's generally not a good idea to modify this directly.

Specified by:
getTable in interface SymbolTable
Returns:
a map of IDExpressions to Declarations.

printCpp

public static void printCpp(ClassDeclaration decl,
                            java.io.OutputStream stream)
Prints a C++ class to a stream.

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

toString

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

printJava

public static void printJava(ClassDeclaration decl,
                             java.io.OutputStream stream)
Prints a Java class to a stream.

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

removeChild

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

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

setClassPrintMethod

public static void setClassPrintMethod(java.lang.reflect.Method m)
Overrides the class print method, so that all subsequently created objects will use the supplied method.

Parameters:
m - The new print method.