Package ptolemy.data.type

Examples of ptolemy.data.type.FunctionType


     *  the type of the function parameter.
     */
    public void preinitialize() throws IllegalActionException {
        super.preinitialize();

        FunctionType type = (FunctionType) function.getType();
        output.setTypeEquals(type.getReturnType());
    }
View Full Code Here


     *  the type of the function parameter.
     */
    public void preinitialize() throws IllegalActionException {
        super.preinitialize();

        FunctionType type = (FunctionType) function.getType();

        if (type.getReturnType() instanceof ArrayType) {
            output.setTypeEquals(((ArrayType) type.getReturnType())
                    .getElementType());
            _outputRate = DFUtilities.getTokenProductionRate(output);
        } else {
            output.setTypeEquals(type.getReturnType());
            _outputRate = -1;
        }

        int i = 0;
        _rate = new int[inputPortList().size() - 1];

        Iterator ports = inputPortList().iterator();

        // Skip the function port.
        ports.next();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();
            Type portType = type.getArgType(i);

            if (portType instanceof ArrayType) {
                port.setTypeEquals(((ArrayType) portType).getElementType());
                _rate[i] = DFUtilities.getTokenConsumptionRate(port);
            } else {
View Full Code Here

            _typeInference = new ParseTreeTypeInference();
        }

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);
View Full Code Here

            _typeInference = new ParseTreeTypeInference();
        }

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);
        return;
View Full Code Here

     */
    public static Type filterReturnType(Type predicateType,
            Type arrayTokenType, Type sizeLimitType)
            throws IllegalActionException {
        if (predicateType instanceof FunctionType) {
            FunctionType castPredicateType = (FunctionType) predicateType;

            if (castPredicateType.getArgCount() != 1) {
                throw new IllegalActionException(
                        "filter() can only be used on functions that take "
                                + "one argument.");
            } else {
                Type argType = castPredicateType.getArgType(0);
                int comparison = TypeLattice.compare(
                        ((ArrayType) arrayTokenType).getElementType(), argType);

                if ((comparison != CPO.LOWER) && (comparison != CPO.SAME)) {
                    throw new IllegalActionException(
View Full Code Here

     *   is not compatible with the other arguments.
     */
    public static Type iterateReturnType(Type functionType, Type lengthType,
            Type initialType) throws IllegalActionException {
        if (functionType instanceof FunctionType) {
            FunctionType castFunctionType = (FunctionType) functionType;

            if (castFunctionType.getArgCount() != 1) {
                throw new IllegalActionException(
                        "iterate() can only be used on functions that take "
                                + "one argument.");
            } else {
                Type argType = castFunctionType.getArgType(0);
                int comparison = TypeLattice.compare(initialType, argType);

                if ((comparison != CPO.LOWER) && (comparison != CPO.SAME)) {
                    throw new IllegalActionException(
                            "iterate(): specified initial value is not "
                                    + "compatible with function argument type.");
                }

                Type resultType = castFunctionType.getReturnType();
                int comparison2 = TypeLattice.compare(resultType, argType);

                if ((comparison2 != CPO.LOWER) && (comparison2 != CPO.SAME)) {
                    throw new IllegalActionException(
                            "iterate(): invalid function: function return "
View Full Code Here

     *   function has different argument type.
     */
    public static Type mapReturnType(Type functionType, Type arrayTokenType)
            throws IllegalActionException {
        if (functionType instanceof FunctionType) {
            FunctionType castFunctionType = (FunctionType) functionType;

            if (castFunctionType.getArgCount() == 1) {
                Type argType = castFunctionType.getArgType(0);
                int comparison = TypeLattice.compare(
                        ((ArrayType) arrayTokenType).getElementType(), argType);

                if ((comparison != CPO.LOWER) && (comparison != CPO.SAME)) {
                    throw new IllegalActionException(
                            "map(): specified array token is not compatible "
                                    + "with function argument type.");
                }
            } else if (castFunctionType.getArgCount() > 1) {
                Type firstArgType = castFunctionType.getArgType(0);
                boolean flag = true;

                for (int i = 1; i < castFunctionType.getArgCount(); i++) {
                    Type argType = castFunctionType.getArgType(i);

                    if (argType != firstArgType) {
                        i = castFunctionType.getArgCount();
                        flag = false;
                        throw new IllegalActionException("map() can only work "
                                + "for functions whose arguments are all of "
                                + "the same type.");
                    }
                }

                if (flag) {
                    Type argType = castFunctionType.getArgType(0);
                    Type elementType = ((ArrayType) arrayTokenType)
                            .getElementType();

                    if (!(elementType instanceof ArrayType)) {
                        throw new IllegalActionException(
                                "map(): specified array token is not "
                                        + "compatible with function arity.");
                    } else {
                        int comparison = TypeLattice.compare(
                                ((ArrayType) elementType).getElementType(),
                                argType);

                        if ((comparison != CPO.LOWER)
                                && (comparison != CPO.SAME)) {
                            throw new IllegalActionException(
                                    "map(): specified array token is not "
                                            + "compatible with function "
                                            + "argument type.");
                        }
                    }
                }
            }

            Type resultType = castFunctionType.getReturnType();
            return new ArrayType(resultType);
        } else {
            return BaseType.UNKNOWN;
        }
    }
View Full Code Here

        _scope = functionScope;
        node.getExpressionTree().visit(this);

        Type returnType = _inferredChildType;
        FunctionType type = new FunctionType(node._argTypes, returnType);
        _setType(node, type);
        _scope = currentScope;
        return;
    }
View Full Code Here

            _typeInference = new ParseTreeTypeInference();
        }

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);
View Full Code Here

                            "collection.");
                }

                Function function = new LoopFunction(_pattern, _matchResult,
                        current, startValue, boundVariable, collection);
                FunctionType functionType = new FunctionType(
                        new Type[] { BaseType.OBJECT }, BaseType.GENERAL);
                _evaluatedChildToken =
                    new FunctionToken(function, functionType);
            } else if (functionName == null) {
                Token token = null;
View Full Code Here

TOP

Related Classes of ptolemy.data.type.FunctionType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.