public class ForLoop extends Statement implements Loop, SymbolTable
Constructor and Description |
---|
ForLoop(Statement init,
Expression condition,
Expression step,
Statement body)
Constructs a new for loop with the given initial expression init,
the condition expression condition, the step expression
step, and the body statement body.
|
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.
|
ForLoop |
clone()
Returns a clone of this for loop.
|
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(ForLoop l,
java.io.PrintWriter o)
Prints the for loop to the given print writer.
|
Declaration |
findSymbol(IDExpression name)
Retrieves the declaration for a symbol, possibly searching
through parent symbol tables.
|
Statement |
getBody()
Returns the statement that is the body of the loop.
|
Expression |
getCondition()
Returns the expression that determines the duration of the loop.
|
java.util.Set<Declaration> |
getDeclarations()
Returns the set of declarations declared within the symbol table object.
|
Statement |
getInitialStatement()
Returns the initial statement of the for loop allowing null.
|
java.util.List<SymbolTable> |
getParentTables()
Returns a list of symbol tables that are parents
of this table in the distributed symbol table graph.
|
Expression |
getStep()
Returns the step expression of the for loop allowing null.
|
java.util.Set<Symbol> |
getSymbols()
Returns the set of declared symbols in the symbol table object.
|
void |
setBody(Statement body)
Sets the body statement of the loop with the given statement body.
|
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 |
setCondition(Expression cond)
Sets the condition expression with the given expression cond.
|
void |
setInitialStatement(Statement stmt)
Sets the initial statement with the given statement stmt.
|
void |
setStep(Expression step)
Sets the step expression with the given expression step.
|
annotate, annotateAfter, annotateBefore, containsAnnotation, detach, equals, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getChildren, getParent, getProcedure, hashCode, print, removeAnnotations, removeAnnotations, removeChild, setChild, setLineNumber, setParent, setPrintMethod, swapWith, toString, verify, where
getChildren, getParent, removeChild, setChild, setParent
public ForLoop(Statement init, Expression condition, Expression step, Statement body)
init
- the initial statement.condition
- the condition expression.step
- the step expression.body
- the body statement.NotAnOrphanException
- if init, condition,
step, or body has a parent.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(ForLoop l, java.io.PrintWriter o)
l
- The loop to print.o
- The writer on which to print the loop.public Declaration findSymbol(IDExpression name)
SymbolTable
findSymbol
in interface SymbolTable
name
- The name of the symbol.public Statement getBody()
Loop
public Expression getCondition()
Loop
getCondition
in interface Loop
public Statement getInitialStatement()
public java.util.List<SymbolTable> getParentTables()
SymbolTable
getParentTables
in interface SymbolTable
public Expression getStep()
public void setBody(Statement body)
body
- the new body statement.NotAnOrphanException
- if body has a parent.public static void setClassPrintMethod(java.lang.reflect.Method m)
m
- The new print method.public void setCondition(Expression cond)
cond
- the new condition expression (null is allowed).NotAnOrphanException
- if cond has a parent object.public void setInitialStatement(Statement stmt)
stmt
- the new initial statement (null is allowed).NotAnOrphanException
- if stmt has a parent object.public void setStep(Expression step)
step
- the new step expression (null is allowed).NotAnOrphanException
- if step has a parent object.public ForLoop clone()
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