public class CompoundStatement extends Statement implements SymbolTable
Constructor and Description |
---|
CompoundStatement()
Creates an empty compound statement.
|
Modifier and Type | Method and Description |
---|---|
void |
addDeclaration(Declaration decl)
Adds a declaration after the last declaration; this models the C
language's requirement that all declarations appear at the beginning of a
block.
|
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 |
addStatement(Statement stmt)
Adds a statement to the end of this compound statement.
|
void |
addStatementAfter(Statement ref_stmt,
Statement new_stmt)
Add a new statement after the reference statement.
|
void |
addStatementBefore(Statement ref_stmt,
Statement new_stmt)
Add a new statement before the reference statement.
|
CompoundStatement |
clone()
Returns a clone of this compound statement.
|
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.
|
int |
countStatements()
Returns the total number of statements contained within
this CompoundStatement.
|
static void |
defaultPrint(CompoundStatement s,
java.io.PrintWriter o)
Prints a statement to the given print writer.
|
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<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 |
removeChild(Traversable child)
Removes the specified child object if it exists.
|
void |
removeStatement(Statement stmt)
Remove the given statement if it exists.
|
annotate, annotateAfter, annotateBefore, containsAnnotation, detach, equals, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getChildren, getParent, getProcedure, hashCode, print, removeAnnotations, removeAnnotations, setChild, setLineNumber, setParent, setPrintMethod, swapWith, toString, verify, where
getChildren, getParent, setChild, setParent
public CompoundStatement()
public void addDeclaration(Declaration decl)
addDeclaration
in interface SymbolTable
decl
- The declaration to add.NotAnOrphanException
- if decl has a parent.public void addDeclarationBefore(Declaration ref, Declaration decl)
SymbolTable
addDeclarationBefore
in interface SymbolTable
ref
- The reference point.decl
- The declaration to add.java.lang.IllegalArgumentException
- if ref is not found.NotAnOrphanException
- if decl has a parent.public void addDeclarationAfter(Declaration ref, Declaration decl)
SymbolTable
addDeclarationAfter
in interface SymbolTable
ref
- The reference point.decl
- The declaration to add.java.lang.IllegalArgumentException
- if ref is not found.NotAnOrphanException
- if decl has a parent.public void addStatement(Statement stmt)
addDeclaration(cetus.hir.Declaration)
.stmt
- The statement to add.java.lang.IllegalArgumentException
- If stmt is null.NotAnOrphanException
- if stmt has a parent.java.lang.UnsupportedOperationException
- if stmt is a declaration
statement.public void addStatementBefore(Statement ref_stmt, Statement new_stmt)
new_stmt
- the statement to be added.ref_stmt
- the reference statement.java.lang.IllegalArgumentException
- If ref_stmt is not found or
new_stmt is null.NotAnOrphanException
- if new_stmt has a parent.java.lang.UnsupportedOperationException
- If new_stmt is a declaration
statement.public void addStatementAfter(Statement ref_stmt, Statement new_stmt)
new_stmt
- the statement to be added.ref_stmt
- the reference statement.java.lang.IllegalArgumentException
- If ref_stmt is not found or
new_stmt is null.NotAnOrphanException
- if new_stmt has a parent.java.lang.UnsupportedOperationException
- If stmt is a declaration
statement.public void removeStatement(Statement stmt)
stmt
- the statement to be removed.public CompoundStatement clone()
public int countStatements()
public static void defaultPrint(CompoundStatement s, java.io.PrintWriter o)
s
- The statement to print.o
- The writer on which to print the statement.public Declaration findSymbol(IDExpression name)
SymbolTable
findSymbol
in interface SymbolTable
name
- The name of the symbol.public java.util.List<SymbolTable> getParentTables()
SymbolTable
getParentTables
in interface SymbolTable
public void removeChild(Traversable child)
removeChild
in interface Traversable
removeChild
in class Statement
child
- the child object to be removed.java.lang.IllegalArgumentException
- if child is not found.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