public final class TranslationUnit extends java.lang.Object implements SymbolTable, Traversable
| Constructor and Description |
|---|
TranslationUnit(java.lang.String input_filename)
Create an empty translation unit associated with a file.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
addDeclarationFirst(Declaration decl)
Adds a new declaration decl at the head of the child list.
|
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(TranslationUnit tu,
java.io.PrintWriter o) |
static void |
defaultPrint2(TranslationUnit t,
java.io.PrintWriter o)
Prints a translation unit to a stream without skipping the included
headers.
|
Declaration |
findSymbol(IDExpression name)
Retrieves the declaration for a symbol, possibly searching
through parent symbol tables.
|
java.util.List<Traversable> |
getChildren()
Provides access to the children of this object as a list.
|
java.util.Set<Declaration> |
getDeclarations()
Returns the set of declarations declared within the symbol table object.
|
Declaration |
getFirstDeclaration()
Returns the first declaration that comes right after
header files.
|
java.lang.String |
getInputFilename()
Returns the original filename for the translation unit.
|
java.lang.String |
getOutputFilename()
Returns the new filename for the translation unit to be written to.
|
Traversable |
getParent()
Provides access to the parent of this object.
|
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.
|
void |
print(java.io.File outDir)
Prints this translation unit to the output file with which it is
associated.
|
void |
print(java.io.PrintWriter o)
Prints this translation unit to the given print writer.
|
void |
removeChild(Traversable child)
Removes the specified child.
|
void |
setChild(int index,
Traversable t)
Sets the indexth child of this object to t.
|
static void |
setClassPrintMethod(java.lang.reflect.Method m)
Overrides the class print method, so that all subsequently
created objects will use the supplied method.
|
void |
setOutputFilename(java.lang.String output_filename)
Sets the output filename for the translation unit.
|
void |
setParent(Traversable t)
Sets the parent program for this translation unit.
|
void |
setPrintMethod(java.lang.reflect.Method m)
Overrides the print method for this object only.
|
java.lang.String |
toString()
Returns a string representation of this translation unit.
|
public TranslationUnit(java.lang.String input_filename)
input_filename - The file name for this TranslationUnitpublic void addDeclaration(Declaration decl)
SymbolTableaddDeclaration in interface SymbolTabledecl - The declaration to add.public void addDeclarationFirst(Declaration decl)
decl - the new declaration to be added.NotAnOrphanException - if decl has a parent object.public void addDeclarationBefore(Declaration ref, Declaration decl)
SymbolTableaddDeclarationBefore in interface SymbolTableref - The reference point.decl - The declaration to add.public void addDeclarationAfter(Declaration ref, Declaration decl)
SymbolTableaddDeclarationAfter in interface SymbolTableref - The reference point.decl - The declaration to add.public Declaration getFirstDeclaration()
public java.lang.String toString()
toString in class java.lang.Objectpublic Declaration findSymbol(IDExpression name)
SymbolTablefindSymbol in interface SymbolTablename - The name of the symbol.public java.util.List<Traversable> getChildren()
TraversablegetChildren in interface Traversablepublic java.lang.String getInputFilename()
public java.lang.String getOutputFilename()
public Traversable getParent()
TraversablegetParent in interface Traversablepublic java.util.List<SymbolTable> getParentTables()
SymbolTablegetParentTables in interface SymbolTablepublic static void defaultPrint2(TranslationUnit t, java.io.PrintWriter o)
t - The translation unit to print.o - The writer on which to print the translation unit.public static void defaultPrint(TranslationUnit tu, java.io.PrintWriter o)
public void print(java.io.File outDir)
throws java.io.FileNotFoundException
outDir - the target directory.java.io.FileNotFoundException - if an output file could not be opened.public void print(java.io.PrintWriter o)
public void removeChild(Traversable child)
TraversableremoveChild in interface Traversablechild - a reference to a child object that must match with ==.public void setChild(int index,
Traversable t)
TraversablesetChild in interface Traversablepublic static void setClassPrintMethod(java.lang.reflect.Method m)
m - The new print method.public void setOutputFilename(java.lang.String output_filename)
output_filename - The output filename for the translation unit.public void setParent(Traversable t)
setParent in interface Traversablet - The parent program.public void setPrintMethod(java.lang.reflect.Method m)
m - The new print method.public java.util.Set<Symbol> getSymbols()
SymbolTablegetSymbols in interface SymbolTablepublic java.util.Set<Declaration> getDeclarations()
SymbolTablegetDeclarations in interface SymbolTablepublic boolean containsSymbol(Symbol symbol)
SymbolTablecontainsSymbol in interface SymbolTablepublic boolean containsDeclaration(Declaration decl)
SymbolTablecontainsDeclaration in interface SymbolTable