org.norecess.citkit.tir.declarations
Class FunctionDTIR

java.lang.Object
  extended by org.norecess.citkit.tir.declarations.FunctionDTIR
All Implemented Interfaces:
IFunctionDTIR, DeclarationTIR, HobbesTIR

public class FunctionDTIR
extends java.lang.Object
implements IFunctionDTIR

The TIR for a function or procedure declaration. A function returns a value; a procedure does not.

The parameters of a function are represented as a list of FieldTIRs. This slightly abuses the name since there's no implied order in a record of fields, but parameters are determined solely on their order.

Author:
Jeremy D. Frens

Constructor Summary
FunctionDTIR(IPosition position, java.lang.String name, java.util.List<IFieldTIR> parameters, ExpressionTIR body)
          Constructs a procedure declaration.
FunctionDTIR(IPosition position, java.lang.String name, java.util.List<IFieldTIR> parameters, INameTTIR result, ExpressionTIR body)
          Constructs a function declaration.
FunctionDTIR(java.lang.String name, java.util.List<IFieldTIR> parameters, ExpressionTIR body)
          Basic constructor for a procedure.
FunctionDTIR(java.lang.String name, java.util.List<IFieldTIR> parameters, INameTTIR result, ExpressionTIR body)
          Basic constructor for a function.
 
Method Summary
<T> T
accept(DeclarationTIRVisitor<T> visitor)
          Implements the visitor pattern with DeclarationTIRVisitor.
 boolean equals(java.lang.Object o)
           
 ExpressionTIR getBody()
          Returns the body of the function.
 java.lang.String getName()
          Returns the name of the function.
 java.util.List<IFieldTIR> getParameters()
          Returns the parameters of the function.
 IPosition getPosition()
          Retrieves the position of the code that generated the TIR.
 INameTTIR getResult()
          Returns the type of the returned value.
 int hashCode()
           
 boolean isFunction()
          Indicates if this TIR represents a function (i.e., there is a return type).
 boolean isProcedure()
          Indicates if this TIR represents a procedure (i.e., there's no return type).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FunctionDTIR

public FunctionDTIR(IPosition position,
                    java.lang.String name,
                    java.util.List<IFieldTIR> parameters,
                    INameTTIR result,
                    ExpressionTIR body)
Constructs a function declaration.

Parameters:
position - the position of the function declaration in the source code.
name - the name of the function.
parameters - the parameters of the function.
result - the type of the returned value (possibly null).
body - the body of the function.

FunctionDTIR

public FunctionDTIR(java.lang.String name,
                    java.util.List<IFieldTIR> parameters,
                    INameTTIR result,
                    ExpressionTIR body)
Basic constructor for a function.

Parameters:
name - the name of the function.
parameters - the parameters of the function.
result - the return type of the function.
body - the body of the function.

FunctionDTIR

public FunctionDTIR(IPosition position,
                    java.lang.String name,
                    java.util.List<IFieldTIR> parameters,
                    ExpressionTIR body)
Constructs a procedure declaration. A procedure does not return anything.

Parameters:
position - the position of the procedur declaration in the source code.
name - the name of the procedure.
parameters - the parameters of the procedure.
body - the body of the procedure.

FunctionDTIR

public FunctionDTIR(java.lang.String name,
                    java.util.List<IFieldTIR> parameters,
                    ExpressionTIR body)
Basic constructor for a procedure.

Parameters:
name - the name of the procedure.
parameters - the parameters of the procedure.
body - the body of the procedure.
Method Detail

getPosition

public IPosition getPosition()
Description copied from interface: DeclarationTIR
Retrieves the position of the code that generated the TIR.

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

getBody

public ExpressionTIR getBody()
Returns the body of the function.

Specified by:
getBody in interface IFunctionDTIR
Returns:
the body of the function.

getName

public java.lang.String getName()
Returns the name of the function.

Specified by:
getName in interface IFunctionDTIR
Returns:
the name of the function.

getParameters

public java.util.List<IFieldTIR> getParameters()
Returns the parameters of the function.

Specified by:
getParameters in interface IFunctionDTIR
Returns:
the parameters of the function.

getResult

public INameTTIR getResult()
Returns the type of the returned value.

Specified by:
getResult in interface IFunctionDTIR
Returns:
the type of the returned value.

accept

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

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

isProcedure

public boolean isProcedure()
Indicates if this TIR represents a procedure (i.e., there's no return type).

Specified by:
isProcedure in interface IFunctionDTIR

isFunction

public boolean isFunction()
Indicates if this TIR represents a function (i.e., there is a return type).

Specified by:
isFunction in interface IFunctionDTIR

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