edu.ksu.cis.projects.bogor.ast
Class ChooseStatement

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.ast.Node
      extended by edu.ksu.cis.projects.bogor.ast.Statement
          extended by edu.ksu.cis.projects.bogor.ast.ChooseStatement
All Implemented Interfaces:
IExpParent, IStatementParent, Disposable, Serializable, Cloneable

public class ChooseStatement
extends Statement
implements IExpParent, IStatementParent

The choose statement AST.

Version:
CVS $Revision: 1.4 $ $Date: 2005/05/01 20:03:27 $
Author:
Robby
See Also:
Serialized Form

Field Summary
protected  Statement elseStmt
          Holds the optional else's statement.
protected  ArrayList<Exp> exps
          Holds the choose conditions.
protected  ArrayList<Statement> stmts
          Holds the choose statements.
 
Fields inherited from class edu.ksu.cis.projects.bogor.ast.Node
ILLEGAL_LOCAL_ID_CHAR
 
Constructor Summary
ChooseStatement(List<? extends Exp> exps, List<? extends Statement> stmts, Statement elseStmt)
          Default constructor.
 
Method Summary
 ChooseStatement clone()
          Clones this object (deep clone); including location info.
 void dispose()
          Disposes exp and stmt.
 Exp getChooseGuard(int index)
          Gets a choose guard at a specified index.
 Statement getChooseStatement(int index)
          Gets an elseif statement at a specified index.
 Statement getElse()
          Gets the else statement.
 int getWhenCount()
          Gets the number of whens.
 void setElse(Statement stmt)
          Sets the else statement.
 void setWhens(List<? extends Exp> exps, List<? extends Statement> stmts)
          Sets the choose guards and statements.
protected  String toString(String indent)
          Returns the string representation of this object.
 void visit(ASTVisitor visitor)
           
 
Methods inherited from class edu.ksu.cis.projects.bogor.ast.Statement
getParent, setParent, toString
 
Methods inherited from class edu.ksu.cis.projects.bogor.ast.Node
getLocationInfo, getProperty, putProperty, setLocationInfo
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

exps

protected ArrayList<Exp> exps
Holds the choose conditions. Must be non-null.


stmts

protected ArrayList<Statement> stmts
Holds the choose statements. Must be non-null.


elseStmt

protected Statement elseStmt
Holds the optional else's statement. Must be non-null.

Constructor Detail

ChooseStatement

public ChooseStatement(List<? extends Exp> exps,
                       List<? extends Statement> stmts,
                       Statement elseStmt)
Default constructor. Sets this object as the parent of each of the choose's exp and stmt. Sets this object as the elseStmt's parent.

Parameters:
exps - The elseif conditions. Must be either null or at least one element.
stmts - The elseif statements. Must agree with exps.
elseStmt - The else statement.
Method Detail

clone

public ChooseStatement clone()
Clones this object (deep clone); including location info.

Specified by:
clone in class Statement
Returns:
The clone of this object. Non-null.

dispose

public void dispose()
Disposes exp and stmt. Can be called repeatedly. Once called, avoid using this object.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class Statement

setWhens

public void setWhens(List<? extends Exp> exps,
                     List<? extends Statement> stmts)
Sets the choose guards and statements. Sets this object as each of the exp's and stmt's parent.

Parameters:
exps - The guards of the choose. Must be non-null. Each element must be non-null. There must be at least one element.
stmts - The statements of the choose. Must be non-null. Each element must be non-null. Should be the same size as exps.

getChooseGuard

public Exp getChooseGuard(int index)
Gets a choose guard at a specified index.

Parameters:
index - The index of the the choose's guard. Must be between 0 and getWhenCount() - 1, inclusive.
Returns:
The choose's guard at the given index. Non-null.

getChooseStatement

public Statement getChooseStatement(int index)
Gets an elseif statement at a specified index.

Parameters:
index - The index of the the elseif's statement. Must be between 0 and getWhenCount() - 1, inclusive.
Returns:
The choose's statement at the given index. Non-null.

getWhenCount

public int getWhenCount()
Gets the number of whens.

Returns:
The number of whens.

setElse

public void setElse(Statement stmt)
Sets the else statement.

Parameters:
stmt - The else statement. Must be non-null.

getElse

public Statement getElse()
Gets the else statement.

Returns:
The else statement.

visit

public void visit(ASTVisitor visitor)
Specified by:
visit in class Node

toString

protected String toString(String indent)
Returns the string representation of this object.

Specified by:
toString in class Statement
Parameters:
indent - The indentation for this statement.
Returns:
 
  
     
                 "choose\n" + 
                 "    when exp1 do\n" + 
                 "        stmt1\n" + 
                 "    when exp2 do\n" + 
                 "        stmt2\n" + 
                 "    ..." + 
                 "    when expN do\n" + 
                 "        stmtN\n" + 
                 "    [else do\n" + 
                 "        stmt\n]" + 
                 "end\n".