oscript.data
Class Function

java.lang.Object
  extended byoscript.data.Value
      extended byoscript.data.Type
          extended byoscript.data.Function
All Implemented Interfaces:
java.io.Serializable

public class Function
extends Type

A script function/constructor. Since native (and other) objects that behave as a function can re-use some functionality (ie checking number of args, type casting, etc., the stuff specific to a script function/ constructor is pushed out into a seperate class.

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Nested Class Summary
static class Function.FunctionData
          In order to keep function instances more lightweight, the values that will be the same for any instance of a function representing the same portion of the parse tree have been split out into this class, in order to be shared between different function instances.
 
Field Summary
 Function.FunctionData fd
          The shared function data...
static java.lang.String[] MEMBER_NAMES
           
static java.lang.String PARENT_TYPE_NAME
           
static Value TYPE
          The type object for an script function.
static java.lang.String TYPE_NAME
           
 
Fields inherited from class oscript.data.Type
HIDDEN_TYPE
 
Fields inherited from class oscript.data.Value
DEBUG, NULL, UNDEFINED
 
Constructor Summary
Function(Scope enclosingScope, Value superFxn, Function.FunctionData fd)
          Class Constructor.
 
Method Summary
 Value bopCast(Value val)
          Perform the cast operation, (a)b is equivalent to a.bopCast(b)
 Value callAsConstructor(StackFrame sf, MemberTable args)
          Call this object as a constructor.
 Value callAsExtends(StackFrame sf, Scope scope, MemberTable args)
          Call this object as a parent class constructor.
 Value callAsFunction(StackFrame sf, MemberTable args)
          Call this object as a function.
 java.lang.String castToString()
          Convert this object to a native java String value.
static Value extractJavadocComment(java.lang.String str, Value name, Value[] argNames)
           
static Value extractJavadocComment(java.util.Vector specials, Value name, int[] argIds)
           
static Value extractJavadocCommentBody(java.lang.String str, Value name, Value[] argNames)
           
 Value[] getArgNames()
          Get the names of the arguments to the function, in order.
 Value getComment()
          Get the comment block.
 Value getMember(int id, boolean exception)
          Get a member of this object.
 int getMinimumArgCount()
          Get the minimum number of args that should be passed to this function.
 Value getName()
          Get the name of this function.
protected  Value getTypeImpl()
          Get the type of this object.
protected  Value getTypeMember(Value obj, int id)
          Get a member of this type.
 boolean isA(Value type)
          If this object is a type, determine if an instance of this type is an instance of the specified type, ie.
protected  void populateMemberSet(java.util.Set s, boolean debugger)
          Derived classes that implement getMember(int, boolean) should also implement this.
protected  void populateTypeMemberSet(java.util.Set s, boolean debugger)
          Derived classes that implement getTypeMember(oscript.data.Value, int) should also implement this.
 boolean takesVarArgs()
          Can this function be called with a variable number of arguments?
 
Methods inherited from class oscript.data.Value
_getTypeMember, _populateTypeMemberSet, bopBitwiseAnd, bopBitwiseAndR, bopBitwiseOr, bopBitwiseOrR, bopBitwiseXor, bopBitwiseXorR, bopCastR, bopDivide, bopDivideR, bopEquals, bopEqualsR, bopGreaterThan, bopGreaterThanOrEquals, bopGreaterThanOrEqualsR, bopGreaterThanR, bopInstanceOf, bopInstanceOfR, bopLeftShift, bopLeftShiftR, bopLessThan, bopLessThanOrEquals, bopLessThanOrEqualsR, bopLessThanR, bopLogicalAnd, bopLogicalAndR, bopLogicalOr, bopLogicalOrR, bopMinus, bopMinusR, bopMultiply, bopMultiplyR, bopNotEquals, bopNotEqualsR, bopPlus, bopPlusR, bopRemainder, bopRemainderR, bopSignedRightShift, bopSignedRightShiftR, bopUnsignedRightShift, bopUnsignedRightShiftR, callAsConstructor, callAsConstructor, callAsExtends, callAsExtends, callAsFunction, callAsFunction, castToBoolean, castToExactNumber, castToInexactNumber, castToJavaObject, elementAt, elementsAt, getMember, getMember, getMember, getMember, getMember, getMonitor, getType, getTypeMember, length, memberSet, noSuchMember, opAssign, readExternal, toString, unhand, uopBitwiseNot, uopDecrement, uopIncrement, uopLogicalNot, uopMinus, uopPlus, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Value TYPE
The type object for an script function.


PARENT_TYPE_NAME

public static final java.lang.String PARENT_TYPE_NAME
See Also:
Constant Field Values

TYPE_NAME

public static final java.lang.String TYPE_NAME
See Also:
Constant Field Values

MEMBER_NAMES

public static final java.lang.String[] MEMBER_NAMES

fd

public final Function.FunctionData fd
The shared function data... parameters that are shared by all instances of the same function.

public for StackFrame.evalNode(oscript.NodeEvaluator, oscript.data.Scope)

Constructor Detail

Function

public Function(Scope enclosingScope,
                Value superFxn,
                Function.FunctionData fd)
Class Constructor. Construct an anonymous function.

Parameters:
enclosingScope - the context the function was declared in
superFxn - the function this function extends, or null
fd - the shared function data, for all instances of this function
Method Detail

getTypeImpl

protected Value getTypeImpl()
Get the type of this object. The returned type doesn't have to take into account the possibility of a script type extending a built-in type, since that is handled by Value.getType().

Specified by:
getTypeImpl in class Value
Returns:
the object's type

getName

public Value getName()
Get the name of this function. An anonymous function will have the name "anon".

Returns:
the function's name

getComment

public Value getComment()
Get the comment block. If there was a javadoc comment block preceding the definition of this function in the src file, it can be accessed with this method.

Returns:
the function's comment, or null

getMinimumArgCount

public int getMinimumArgCount()
Get the minimum number of args that should be passed to this function. If #isVarArgs returns true, then it is possible to pass more arguments to this function, otherwise, you should pass exactly this number of args to the function.

Returns:
minimum number of args to pass when calling this function
See Also:
#isVarArgs, getArgNames()

takesVarArgs

public boolean takesVarArgs()
Can this function be called with a variable number of arguments?

See Also:
getMinimumArgCount(), getArgNames()

getArgNames

public Value[] getArgNames()
Get the names of the arguments to the function, in order. If this function takes a variable number of arguments, the last name in the array is the "var-arg" variable, to which the array of all remaining arguments are bound.


isA

public boolean isA(Value type)
If this object is a type, determine if an instance of this type is an instance of the specified type, ie. if this is type, or a subclass.

Overrides:
isA in class Type
Parameters:
type - the type to compare this type to
Returns:
true or false
Throws:
PackagedScriptObjectException(NoSuchMemberException)

bopCast

public Value bopCast(Value val)
              throws PackagedScriptObjectException
Perform the cast operation, (a)b is equivalent to a.bopCast(b)

Overrides:
bopCast in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

castToString

public java.lang.String castToString()
                              throws PackagedScriptObjectException
Convert this object to a native java String value.

Overrides:
castToString in class Value
Returns:
a String value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

callAsFunction

public Value callAsFunction(StackFrame sf,
                            MemberTable args)
                     throws PackagedScriptObjectException
Call this object as a function.

Overrides:
callAsFunction in class Value
Parameters:
sf - the current stack frame
args - the arguments to the function, or null if none
Returns:
the value returned by the function
Throws:
PackagedScriptObjectException
See Also:
Function

callAsConstructor

public Value callAsConstructor(StackFrame sf,
                               MemberTable args)
                        throws PackagedScriptObjectException
Call this object as a constructor.

Overrides:
callAsConstructor in class Value
Parameters:
sf - the current stack frame
args - the arguments to the function, or null if none
Returns:
the newly constructed object
Throws:
PackagedScriptObjectException
See Also:
Function

callAsExtends

public Value callAsExtends(StackFrame sf,
                           Scope scope,
                           MemberTable args)
                    throws PackagedScriptObjectException
Call this object as a parent class constructor.

Overrides:
callAsExtends in class Value
Parameters:
sf - the current stack frame
scope - the object
args - the arguments to the function, or null if none
Returns:
the value returned by the function
Throws:
PackagedScriptObjectException
See Also:
Function

getMember

public Value getMember(int id,
                       boolean exception)
                throws PackagedScriptObjectException
Get a member of this object.

Overrides:
getMember in class Value
Parameters:
id - the id of the symbol that maps to the member
exception - whether an exception should be thrown if the member object is not resolved
Returns:
a reference to the member
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

getTypeMember

protected Value getTypeMember(Value obj,
                              int id)
Get a member of this type. This is used to interface to the java method of having members be attributes of a type. Regular object- script object's members are attributes of the object, but in the case of java types (including built-in types), the members are attributes of the type.

Overrides:
getTypeMember in class Value
Parameters:
obj - an object of this type
id - the id of the symbol that maps to the member
Returns:
a reference to the member, or null
See Also:
Value.populateTypeMemberSet(java.util.Set, boolean)

populateMemberSet

protected void populateMemberSet(java.util.Set s,
                                 boolean debugger)
Derived classes that implement getMember(int, boolean) should also implement this.

Overrides:
populateMemberSet in class Value
Parameters:
s - the set to populate
debugger - true if being used by debugger, in which case both public and private/protected field names should be returned
See Also:
getMember(int, boolean)

populateTypeMemberSet

protected void populateTypeMemberSet(java.util.Set s,
                                     boolean debugger)
Derived classes that implement getTypeMember(oscript.data.Value, int) should also implement this.

Overrides:
populateTypeMemberSet in class Value
Parameters:
s - the set to populate
debugger - true if being used by debugger, in which case both public and private/protected field names should be returned
See Also:
getTypeMember(oscript.data.Value, int)

extractJavadocComment

public static Value extractJavadocComment(java.util.Vector specials,
                                          Value name,
                                          int[] argIds)

extractJavadocComment

public static Value extractJavadocComment(java.lang.String str,
                                          Value name,
                                          Value[] argNames)

extractJavadocCommentBody

public static Value extractJavadocCommentBody(java.lang.String str,
                                              Value name,
                                              Value[] argNames)