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

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.IfStatement
All Implemented Interfaces:
IExpParent, IStatementParent, Disposable, Serializable, Cloneable

public class IfStatement
extends Statement
implements IExpParent, IStatementParent

The if statement AST.

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

Field Summary
protected  Statement elseStmt
          Holds the optional else's statement.
protected  Exp exp
          Holds the condition.
protected  ArrayList<Exp> exps
          Holds the optional elseif's conditions.
protected  Statement stmt
          Holds the statement.
protected  ArrayList<Statement> stmts
          Holds the optional elseif's statements.
 
Fields inherited from class edu.ksu.cis.projects.bogor.ast.Node
ILLEGAL_LOCAL_ID_CHAR
 
Constructor Summary
IfStatement(Exp exp, Statement stmt, List<? extends Exp> exps, List<? extends Statement> stmts, Statement elseStmt)
          Default constructor.
 
Method Summary
 IfStatement clone()
          Clones this object (deep clone); including location info.
 void dispose()
          Disposes exp and stmt.
 Statement getElse()
          Gets the else statement.
 Exp getElseIfCondition(int index)
          Gets an elseif condition at a specified index.
 int getElseIfCount()
          Gets the number of elseifs.
 Statement getElseIfStatement(int index)
          Gets an elseif statement at a specified index.
 Exp getExp()
          Gets the condition.
 Statement getStatement()
          Gets the statement.
 void setElse(Statement stmt)
          Sets the else statement.
 void setElseIfs(List<? extends Exp> exps, List<? extends Statement> stmts)
          Sets the elseifs.
 void setExp(Exp exp)
          Sets the condition.
 void setStatement(Statement stmt)
          Sets the statement.
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

exp

protected Exp exp
Holds the condition. Must be non-null.


stmt

protected Statement stmt
Holds the statement. Must be non-null.


exps

protected ArrayList<Exp> exps
Holds the optional elseif's conditions. Must be non-null.


stmts

protected ArrayList<Statement> stmts
Holds the optional elseif's statements. Must be non-null.


elseStmt

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

Constructor Detail

IfStatement

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

Parameters:
exp - The condition. Must be non-null.
stmt - The statement. Must be non-null.
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 IfStatement 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

getExp

public Exp getExp()
Gets the condition.

Returns:
The condition. Non-null.

setExp

public void setExp(Exp exp)
Sets the condition. Sets this object as the exp's parent.

Parameters:
exp - The condition. Must be non-null.

getStatement

public Statement getStatement()
Gets the statement.

Returns:
The statement. Non-null.

setStatement

public void setStatement(Statement stmt)
Sets the statement. Sets this object as the stmt's parent.

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

setElseIfs

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

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

getElseIfCondition

public Exp getElseIfCondition(int index)
Gets an elseif condition at a specified index.

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

getElseIfStatement

public Statement getElseIfStatement(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 getElseIfCount() - 1, inclusive.
Returns:
The elseif's statement at the given index. Non-null.

getElseIfCount

public int getElseIfCount()
Gets the number of elseifs.

Returns:
The number of elseifs.

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:
 
  
   
               "if exp1 do\n" + 
               "    stmt1\n" + 
               "elseif exp2 do\n" + 
               "    stmt2\n" + 
               "..." + 
               "elseif expN do\n" + 
               "    stmtN\n" + 
               "[else do\n" + 
               "    stmt\n]" + 
               "end\n".