Package ptolemy.data.type

Examples of ptolemy.data.type.Type


        ptolemy.actor.lib.MultiplyDivide actor = (ptolemy.actor.lib.MultiplyDivide) getComponent();

        ArrayList args = new ArrayList();

        Type type = actor.output.getType();
        args.add(targetType(type));

        if (_codeStream.isEmpty()) {
            _codeStream.append(_eol
                    + _codeGenerator.comment("preinitialize "
View Full Code Here


            if (childTypes[i] == null) {
                throw new RuntimeException("node " + node + " has null type.");
            }
        }

        Type baseType = null;

        if ((_scope != null) && (functionName != null)) {
            baseType = _scope.getType(functionName);
        }

        if ((baseType != null) || (functionName == null)) {
            baseType = _inferChild(node, 0);

            // Handle as an array or matrix index into a named
            // variable reference.
            if (baseType instanceof FunctionType) {
                _setType(node, ((FunctionType) baseType).getReturnType());
                return;
            } else if (argCount == 1) {
                if (baseType instanceof ArrayType) {
                    _setType(node, ((ArrayType) baseType).getElementType());
                    return;
                } else {
                    _assert(true, node, "Cannot use array " + "indexing on '"
                            + node.getFunctionName()
                            + "' because it does not have an array type.");
                }
            } else if (argCount == 2) {
                if (baseType instanceof MatrixType) {
                    _setType(node, ((MatrixType) baseType).getElementType());
                    return;
                } else {
                    _assert(true, node, "Cannot use matrix " + "indexing on '"
                            + node.getFunctionName()
                            + "' because it does not have a matrix type.");
                }
            }

            throw new IllegalActionException("Wrong number of indices "
                    + "when referencing " + functionName);
        }

        // Psuedo-temporary hack for casts....
        if ((functionName.compareTo("cast") == 0) && (argCount == 2)) {
            ASTPtRootNode castTypeNode = ((ASTPtRootNode) node
                    .jjtGetChild(0 + 1));
            ParseTreeEvaluator parseTreeEvaluator = new ParseTreeEvaluator();

            try {
                ptolemy.data.Token t = parseTreeEvaluator.evaluateParseTree(
                        castTypeNode, _scope);
                _setType(node, t.getType());
            } catch (IllegalActionException ex) {
                _setType(node, childTypes[0]);
            }

            return;

            // Note: We used to just do this, but in some case is it
            // useful to have functions which are type constructors...
            // Hence the above code.
            //  _setType(node,
            //     ((ASTPtRootNode) node.jjtGetChild(0 + 1)).getType());
            //  return;
        }

        // A hack, because the result of the 'fix' function is
        // dependent on its arguments, which should be constant.
        if ((functionName.compareTo("fix") == 0) && (argCount == 3)) {
            ASTPtRootNode lengthNode = ((ASTPtRootNode) node.jjtGetChild(1 + 1));
            ASTPtRootNode integerBitsNode = ((ASTPtRootNode) node
                    .jjtGetChild(2 + 1));
            ParseTreeEvaluator parseTreeEvaluator = new ParseTreeEvaluator();

            try {
                ptolemy.data.Token length = parseTreeEvaluator
                        .evaluateParseTree(lengthNode, _scope);

                ptolemy.data.Token integerBits = parseTreeEvaluator
                        .evaluateParseTree(integerBitsNode, _scope);
                _setType(node, new FixType(new Precision(((ScalarToken) length)
                        .intValue(), ((ScalarToken) integerBits).intValue())));
                return;
            } catch (Throwable throwable) {
                // Do nothing... rely on the regular method resolution
                // to generate the right type.
            }
        }

        if (functionName.compareTo("eval") == 0) {
            // We can't infer the type of eval expressions...
            _setType(node, BaseType.GENERAL);
            return;
        }

        if (functionName.compareTo("matlab") == 0) {
            // We can't infer the type of matlab expressions...
            _setType(node, BaseType.GENERAL);
            return;
        }

        // Otherwise, try to reflect the method name.
        CachedMethod cachedMethod;

        try {
            cachedMethod = CachedMethod.findMethod(functionName, childTypes,
                    CachedMethod.FUNCTION);
        } catch (Exception ex) {
            // Deal with what happens if the method is not found.
            // FIXME: hopefully this is monotonic???
            _setType(node, BaseType.UNKNOWN);
            return;
        }

        if (cachedMethod.isValid()) {
            Type type = cachedMethod.getReturnType();
            _setType(node, type);
        } else {
            // If we reach this point it means the function was not found on
            // the search path.
            StringBuffer buffer = new StringBuffer();
View Full Code Here

            public ptolemy.data.Token get(String name) {
                return null;
            }

            public Type getType(String name) throws IllegalActionException {
                Type type = (Type) map.get(name);

                if ((type == null) && (currentScope != null)) {
                    return currentScope.getType(name);
                } else {
                    return type;
                }
            }

            public InequalityTerm getTypeTerm(String name)
                    throws IllegalActionException {
                Type type = (Type) map.get(name);

                if ((type == null) && (currentScope != null)) {
                    return currentScope.getTypeTerm(name);
                } else {
                    return new TypeConstant(type);
                }
            }

            public Set identifierSet() throws IllegalActionException {
                Set set = currentScope.identifierSet();
                set.addAll(map.keySet());
                return set;
            }
        };

        _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

     @param node The specified node.
     *  @exception IllegalActionException If an inference error occurs.
     */
    public void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
            throws IllegalActionException {
        Type conditionalType = _inferChild(node, 0);

        if (conditionalType != BaseType.BOOLEAN) {
            throw new IllegalActionException(
                    "Functional-if must branch on a boolean, "
                            + "but instead type was " + conditionalType);
        }

        Type trueType = _inferChild(node, 1);
        Type falseType = _inferChild(node, 2);

        _setType(node, (Type) TypeLattice.lattice().leastUpperBound(trueType,
                falseType));
    }
View Full Code Here

        }

        String name = node.getName();

        if (_scope != null) {
            Type type = _scope.getType(name);

            if (type != null) {
                _setType(node, type);
                return;
            }
View Full Code Here

        //             args.set(0, Integer.valueOf(i));
        //             fireCode.append(_generateBlockCode("fireBlock", args));
        //         }

        ArrayList args2 = new ArrayList();
        Type type = actor.output.getType();
        if (isPrimitive(type)) {
            args2.add(codeGenType(type));
            fireCode.append(_generateBlockCode("fireBlock2", args2));
        } else {
            fireCode.append(_generateBlockCode("fireBlock2"));
View Full Code Here

     */
    public void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
            throws IllegalActionException {
        Type[] childTypes = _inferAllChildren(node);

        Type elementType = (Type) TypeLattice.lattice().leastUpperBound(
                childTypes);

        Type matrixType = MatrixType.getMatrixTypeForElementType(elementType);
        _setType(node, matrixType);
    }
View Full Code Here

        CachedMethod cachedMethod = CachedMethod.findMethod(node
                .getMethodName(), childTypes, CachedMethod.METHOD);

        if (cachedMethod.isValid()) {
            Type type = cachedMethod.getReturnType();
            _setType(node, type);
        } else {
            // If we reach this point it means the function was not found on
            // the search path.
            StringBuffer buffer = new StringBuffer();
View Full Code Here

    public void visitPowerNode(ASTPtPowerNode node)
            throws IllegalActionException {
        Type[] childTypes = _inferAllChildren(node);

        // FIXME: Check that exponents are valid??
        Type baseType = childTypes[0];
        _setType(node, baseType);
    }
View Full Code Here

        Type[] childTypes = _inferAllChildren(node);

        List lexicalTokenList = node.getLexicalTokenList();
        int numChildren = node.jjtGetNumChildren();

        Type resultType = childTypes[0];
        for (int i = 1; i < numChildren; i++) {
            Token operator = (Token) lexicalTokenList.get(i - 1);
            Type nextType = childTypes[i];
            if (operator.kind == PtParserConstants.MULTIPLY) {
                resultType = resultType.multiply(nextType);
            } else if (operator.kind == PtParserConstants.DIVIDE) {
                resultType = resultType.divide(nextType);
            } else if (operator.kind == PtParserConstants.MODULO) {
View Full Code Here

TOP

Related Classes of ptolemy.data.type.Type

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.