public class ClassDeclaration extends Declaration implements SymbolTable
Modifier and Type | Class and Description |
---|---|
static class |
ClassDeclaration.Key
Class for representing the four different types of class declarations,
class, struct, union, and interface.
|
Modifier and Type | Field and Description |
---|---|
static ClassDeclaration.Key |
CLASS
Keyword for class type declaration.
|
static ClassDeclaration.Key |
INTERFACE
Keyword for interface type declaration.
|
static ClassDeclaration.Key |
STRUCT
Keyword for struct type declaration.
|
static ClassDeclaration.Key |
UNION
Keyword for union type declaration.
|
Constructor and Description |
---|
ClassDeclaration(ClassDeclaration.Key type,
IDExpression name)
Constructs an empty class declaration with the given type and name ID.
|
ClassDeclaration(ClassDeclaration.Key type,
IDExpression name,
boolean no_body)
Constructs a class declaration with the given type, name ID, and the flag
for forward declaration.
|
ClassDeclaration(java.util.List class_specs,
ClassDeclaration.Key type,
IDExpression name)
Constructs a class declaration from the given list of specifiers, type
keyword, and name ID.
|
Modifier and Type | Method and Description |
---|---|
void |
addBaseClass(IDExpression name)
Adds the name of the base class - not used in C
|
void |
addBaseClass(Specifier access,
IDExpression name)
Adds the name of the base class with the specifier - not used in C
|
void |
addBaseInterface(IDExpression name)
Adds the name of the interface - not used in C
|
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.
|
ClassDeclaration |
clone()
Returns a clone of this class declaration.
|
boolean |
containsDeclaration(Declaration decl)
Checks if the symbol table contains the specified declaration.
|
boolean |
containsSymbol(Symbol symbol)
Checks if the symbol table contains the specified symbol.
|
static void |
defaultPrint(ClassDeclaration d,
java.io.PrintWriter o)
Prints a class to a stream.
|
Declaration |
findSymbol(IDExpression name)
Retrieves the declaration for a symbol, possibly searching
through parent symbol tables.
|
java.util.Set<Declaration> |
getDeclarations()
Returns the set of declarations declared within the symbol table object.
|
java.util.List<IDExpression> |
getDeclaredIDs()
Returns the IDs declared by this class declaration; the returned list
contains one ID which gives the type and the name.
|
ClassDeclaration.Key |
getKey()
Returns the type keyword for the class declaration
|
IDExpression |
getName()
Returns the name ID of the class declaration
|
java.util.List<SymbolTable> |
getParentTables()
Returns a list of symbol tables that are parents
of this table in the distributed symbol table graph.
|
java.util.Set<Symbol> |
getSymbols()
Returns the set of declared symbols in the symbol table object.
|
boolean |
matches(java.lang.Object otherObj) |
static void |
printCpp(ClassDeclaration d,
java.io.PrintWriter o)
Prints a C++ class to a stream.
|
static void |
printJava(ClassDeclaration d,
java.io.PrintWriter o)
Prints a Java class to a stream.
|
void |
removeChild(Traversable child)
This operation is not allowed.
|
static void |
setClassPrintMethod(java.lang.reflect.Method m)
Overrides the class print method, so that all subsequently
created objects will use the supplied method.
|
annotate, annotateAfter, annotateBefore, containsAnnotation, detach, equals, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getChildren, getParent, hashCode, print, removeAnnotations, removeAnnotations, setChild, setParent, setPrintMethod, setSemiColon, toString, verify
getChildren, getParent, setChild, setParent
public static final ClassDeclaration.Key CLASS
public static final ClassDeclaration.Key STRUCT
public static final ClassDeclaration.Key UNION
public static final ClassDeclaration.Key INTERFACE
public ClassDeclaration(java.util.List class_specs, ClassDeclaration.Key type, IDExpression name)
public ClassDeclaration(ClassDeclaration.Key type, IDExpression name)
type
- Must be one of CLASS, STRUCT, UNION, or INTERFACE.name
- The name ID for the class.public ClassDeclaration(ClassDeclaration.Key type, IDExpression name, boolean no_body)
type
- Must be one of CLASS, STRUCT, UNION, or INTERFACE.name
- The name for the class.no_body
- True if this a forward declaration.public void addBaseClass(IDExpression name)
public void addBaseClass(Specifier access, IDExpression name)
public void addBaseInterface(IDExpression name)
public void addDeclaration(Declaration decl)
SymbolTable
addDeclaration
in interface SymbolTable
decl
- The declaration to add.public void addDeclarationBefore(Declaration ref, Declaration decl)
SymbolTable
addDeclarationBefore
in interface SymbolTable
ref
- The reference point.decl
- The declaration to add.public void addDeclarationAfter(Declaration ref, Declaration decl)
SymbolTable
addDeclarationAfter
in interface SymbolTable
ref
- The reference point.decl
- The declaration to add.public static void defaultPrint(ClassDeclaration d, java.io.PrintWriter o)
d
- The class to print.o
- The writer on which to print the class.public Declaration findSymbol(IDExpression name)
SymbolTable
findSymbol
in interface SymbolTable
name
- The name of the symbol.public java.util.List<IDExpression> getDeclaredIDs()
getDeclaredIDs
in class Declaration
public ClassDeclaration.Key getKey()
public IDExpression getName()
public java.util.List<SymbolTable> getParentTables()
SymbolTable
getParentTables
in interface SymbolTable
public static void printCpp(ClassDeclaration d, java.io.PrintWriter o)
d
- The class to print.o
- The writer on which to print the class.public static void printJava(ClassDeclaration d, java.io.PrintWriter o)
d
- The class to print.o
- The writer on which to print the class.public void removeChild(Traversable child)
Declaration
removeChild
in interface Traversable
removeChild
in class Declaration
child
- a reference to a child object that must match with ==.public static void setClassPrintMethod(java.lang.reflect.Method m)
m
- The new print method.public ClassDeclaration clone()
clone
in class Declaration
public boolean matches(java.lang.Object otherObj)
public java.util.Set<Symbol> getSymbols()
SymbolTable
getSymbols
in interface SymbolTable
public java.util.Set<Declaration> getDeclarations()
SymbolTable
getDeclarations
in interface SymbolTable
public boolean containsSymbol(Symbol symbol)
SymbolTable
containsSymbol
in interface SymbolTable
public boolean containsDeclaration(Declaration decl)
SymbolTable
containsDeclaration
in interface SymbolTable