ptolemy.data.expr
Class ExpressionFunction

java.lang.Object
  extended by ptolemy.data.expr.ExpressionFunction
All Implemented Interfaces:
Function

public class ExpressionFunction
extends java.lang.Object
implements Function

An implementation of a function closure that encapsulates an expression tree. Instances of this class are created during the evaluation of function closure expressions in the expression language, like "function(x:int, y:int) x+y".

Since:
Ptolemy II 2.1
Version:
$Id: ExpressionFunction.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer, Xiaojun Liu
See Also:
ASTPtRootNode
Accepted Rating:
Red (neuendor)
Proposed Rating:
Yellow (neuendor)

Field Summary
private  java.util.List _argumentNames
           
private  Type[] _argumentTypes
           
private  ASTPtRootNode _exprRoot
           
 
Constructor Summary
ExpressionFunction(java.util.List argumentNames, Type[] argumentTypes, ASTPtRootNode exprRoot)
          Construct a function closure that encapsulates an expression tree.
 
Method Summary
 Token apply(Token[] arguments)
          Apply the function to the list of arguments, which are tokens.
 int getNumberOfArguments()
          Return the number of arguments of the function.
 boolean isCongruent(Function function)
          Return true if this function is congruent to the given function.
 java.lang.String toString()
          Return a string representation of this function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_exprRoot

private ASTPtRootNode _exprRoot

_argumentNames

private java.util.List _argumentNames

_argumentTypes

private Type[] _argumentTypes
Constructor Detail

ExpressionFunction

public ExpressionFunction(java.util.List argumentNames,
                          Type[] argumentTypes,
                          ASTPtRootNode exprRoot)
Construct a function closure that encapsulates an expression tree.

Parameters:
argumentNames - The names of the arguments.
argumentTypes - The types of the arguments.
exprRoot - The Expression tree that describes the function.
Method Detail

apply

public Token apply(Token[] arguments)
            throws IllegalActionException
Apply the function to the list of arguments, which are tokens.

Specified by:
apply in interface Function
Parameters:
arguments - The list of arguments.
Returns:
The result of applying the function to the given arguments.
Throws:
IllegalActionException - If thrown during evaluating the function.

getNumberOfArguments

public int getNumberOfArguments()
Return the number of arguments of the function.

Specified by:
getNumberOfArguments in interface Function
Returns:
The number of arguments of the function.

isCongruent

public boolean isCongruent(Function function)
Return true if this function is congruent to the given function. Classes should implement this method so that two functions are congruent under any renaming of the bound variables of the function. For simplicity, a function need only be congruent to other functions of the same class.

Specified by:
isCongruent in interface Function
Parameters:
function - The function to check congruency against.
Returns:
True if this function is congruent.

toString

public java.lang.String toString()
Return a string representation of this function.

Specified by:
toString in interface Function
Overrides:
toString in class java.lang.Object
Returns:
A string representation of this function.