org.norecess.citkit.tir.expressions
Class IfETIR

java.lang.Object
  extended by org.norecess.citkit.tir.expressions.IfETIR
All Implemented Interfaces:
IIfETIR, ExpressionTIR, HobbesTIR

public class IfETIR
extends java.lang.Object
implements IIfETIR

The TIR for an if statement.

Author:
Jeremy D. Frens

Constructor Summary
IfETIR(ExpressionTIR test, ExpressionTIR thenClause)
          Basic constructor.
IfETIR(ExpressionTIR test, ExpressionTIR thenClause, ExpressionTIR elseClause)
          Basic constructor.
IfETIR(IPosition position, ExpressionTIR test, ExpressionTIR thenClause)
          Constructs an if statement without an else clause.
IfETIR(IPosition position, ExpressionTIR test, ExpressionTIR thenClause, ExpressionTIR elseClause)
          Constructs an if statement.
 
Method Summary
<T> T
accept(ExpressionTIRVisitor<T> visitor)
          Implements the visitor pattern with ExpressionTIRVisitor.
 boolean equals(java.lang.Object o)
           
 ExpressionTIR getElseClause()
          Returns the else clause of the if statement.
 IPosition getPosition()
          Retrieves the position of the code that generated the TIR.
 ExpressionTIR getTest()
          Returns the test of the if statement.
 ExpressionTIR getThenClause()
          Returns the then clause of the if statement.
 HobbesType getType()
          By default, this returns the type of the then clause.
 int hashCode()
           
 boolean isSingleBranch()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfETIR

public IfETIR(IPosition position,
              ExpressionTIR test,
              ExpressionTIR thenClause,
              ExpressionTIR elseClause)
Constructs an if statement. Use the other constructor if there's no else clause.

Parameters:
position - the position of the if statement in the source code.
test - the test of the if statement.
thenClause - the then clause.
elseClause - the else clause.

IfETIR

public IfETIR(IPosition position,
              ExpressionTIR test,
              ExpressionTIR thenClause)
Constructs an if statement without an else clause.

Parameters:
position - the position of the if statement in the source code.
test - the test of the if statement.
thenClause - the then clause.

IfETIR

public IfETIR(ExpressionTIR test,
              ExpressionTIR thenClause,
              ExpressionTIR elseClause)
Basic constructor.

Parameters:
test - the test.
thenClause - the then clause.
elseClause - the else clause.

IfETIR

public IfETIR(ExpressionTIR test,
              ExpressionTIR thenClause)
Basic constructor.

Parameters:
test - the test.
thenClause - the then clause.
Method Detail

getElseClause

public ExpressionTIR getElseClause()
Returns the else clause of the if statement.

Specified by:
getElseClause in interface IIfETIR
Returns:
the else clause of the if statement (could be null).

getTest

public ExpressionTIR getTest()
Returns the test of the if statement.

Specified by:
getTest in interface IIfETIR
Returns:
the test of the if statement.

getThenClause

public ExpressionTIR getThenClause()
Returns the then clause of the if statement.

Specified by:
getThenClause in interface IIfETIR
Returns:
the then clause of the if statement.

getType

public HobbesType getType()
By default, this returns the type of the then clause. This could be an error if this type is more restrictive that the type of the else clause.

Specified by:
getType in interface ExpressionTIR
Returns:
the type of the code.
See Also:
ExpressionTIR.getType()

accept

public <T> T accept(ExpressionTIRVisitor<T> visitor)
Description copied from interface: ExpressionTIR
Implements the visitor pattern with ExpressionTIRVisitor.

Specified by:
accept in interface ExpressionTIR
Parameters:
visitor - the visitor object.
Returns:
the result of visiting the AST with the visitor.

isSingleBranch

public boolean isSingleBranch()
Specified by:
isSingleBranch in interface IIfETIR

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getPosition

public IPosition getPosition()
Retrieves the position of the code that generated the TIR.

Specified by:
getPosition in interface HobbesTIR
Returns:
the position of the code in the source code.