Package ptolemy.data.type

Examples of ptolemy.data.type.Type


    public final Token multiply(Token rightArgument)
            throws IllegalActionException {
        // MatrixType type = (MatrixType)getType();
        // Get the corresponding element type for this matrix type,
        // and try a scalar operation.
        Type elementType = getElementType();
        int typeInfo = TypeLattice.compare(elementType, rightArgument);

        if (typeInfo == CPO.SAME) {
            Token result = _multiplyElement(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token convertedArgument = elementType.convert(rightArgument);

            try {
                Token result = _multiplyElement(convertedArgument);
                return result;
            } catch (IllegalActionException ex) {
                // If the type-specific operation fails, then create a better
                // error message that has the types of the arguments that were
                // passed in.
                throw new IllegalActionException(null, ex, notSupportedMessage(
                        "multiply", this, rightArgument));
            }
        }

        // Argument must be a matrix or incomparable.
        typeInfo = TypeLattice.compare(getType(), rightArgument);

        if (typeInfo == CPO.SAME) {
            Token result = _doMultiply(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    rightArgument);

            try {
                Token result = _doMultiply(convertedArgument);
                return result;
            } catch (IllegalActionException ex) {
                // If the type-specific operation fails, then create a
                // better error message that has the types of the
                // arguments that were passed in.
                throw new IllegalActionException(null, ex, notSupportedMessage(
                        "multiply", this, rightArgument));
            }
        } else if (typeInfo == CPO.LOWER) {
            Token result = rightArgument.multiplyReverse(this);
            return result;
        } else {
            // Items being multiplied are incomparable.
            // However, multiplication may still be possible because
            // the LUB of the types might support it. E.g., [double]*complex,
            // where the LUB is [complex].
            Type lubType = (Type) TypeLattice.lattice().leastUpperBound(
                    getType(), rightArgument.getType());

            // If the LUB is a new type, try it.
            if (!lubType.equals(getType())) {
                Token lub = lubType.convert(this);

                // Caution: convert() might return this again, e.g.
                // if lubType is general.  Only proceed if the conversion
                // returned a new type.
                if (!(lub.getType().equals(getType()))) {
View Full Code Here


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

        ArrayList args = new ArrayList();

        Type type = actor.output.getType();
        if (isPrimitive(type)) {
            args.add(targetType(type));
            _codeStream.appendCodeBlock("CommonPreinitBlock", args);
        } else {
            throw new IllegalActionException("Non-primitive types " + type
View Full Code Here

                            preferredForegroundColor(attribute), heightValue,
                            widthValue);
                    attachParameter(attribute, name);
                    foundStyle = true;
                } else if (attribute instanceof Variable) {
                    Type declaredType = ((Variable) attribute)
                            .getDeclaredType();
                    Token current = ((Variable) attribute).getToken();

                    if (declaredType == BaseType.BOOLEAN) {
                        // NOTE: If the expression is something other than
View Full Code Here

            //int nextIndex = _fireCode.length();

            tokens[i] = _evaluateChild(node, i);

            Type valueType = tokens[i].getType();

            if (CodeGeneratorHelper.isPrimitive(valueType)) {
                //_fireCode.insert(nextIndex, "$new(" + CodeGeneratorHelper.codeGenType(valueType) + "(");
                //_fireCode.append("))");
                result += "$new(" + CodeGeneratorHelper.codeGenType(valueType)
View Full Code Here

        String result = "";

        // First check to see if the name references a valid variable.

        ptolemy.data.Token value = null;
        Type type = null;
        String functionName = node.getFunctionName();

        if ((functionName != null) && (_scope != null)) {
            value = _scope.get(node.getFunctionName());
            type = _scope.getType(node.getFunctionName());
View Full Code Here

        _childCode = "(" + result + ")";

        ptolemy.data.Token token1 = _evaluatedChildToken;
        ptolemy.data.Token token2 = _evaluatedChildToken;

        Type conversionType = (Type) TypeLattice.lattice().leastUpperBound(
                token1.getType(), token2.getType());

        _evaluatedChildToken = conversionType.convert(token1);

        //if (node.isConstant()) {
        //    node.setToken(_evaluatedChildToken);
        //}
View Full Code Here

                    int index = (i * column) + j;

                    //int nextIndex = _fireCode.length();
                    tokens[index] = _evaluateChild(node, index);

                    Type valueType = tokens[index].getType();

                    if (CodeGeneratorHelper.isPrimitive(valueType)) {
                        //_fireCode.insert(nextIndex, "$new(" + CodeGeneratorHelper.codeGenType(valueType) + "(");
                        //_fireCode.append("))");
                        result += "$new("
View Full Code Here

        _evaluateChild(node, 1);

        //_fireCode.append(")");
        result += _childCode + ")";

        Type elementType = ((ArrayType) type).getElementType();

        //_fireCode.append(".payload." + CodeGeneratorHelper.codeGenType(elementType));
        _childCode = result + ".payload."
                + CodeGeneratorHelper.codeGenType(elementType);
    }
View Full Code Here

        StringBuffer code = new StringBuffer();

        Iterator channels = _getTypeConvertChannels().iterator();
        while (channels.hasNext()) {
            Channel channel = (Channel) channels.next();
            Type portType = ((TypedIOPort) channel.port).getType();

            if (isPrimitive(portType)) {

                code.append("static ");
                code.append(targetType(portType));
View Full Code Here

        try {
            if (tokenClass.equals(ptolemy.data.Token.class)) {
                return BaseType.GENERAL;
            } else if (ptolemy.data.ArrayToken.class
                    .isAssignableFrom(tokenClass)) {
                Type type = new ArrayType(BaseType.GENERAL);
                return type;
            } else if (ptolemy.data.RecordToken.class
                    .isAssignableFrom(tokenClass)) {
                Type type = new RecordType(new String[0], new Type[0]);
                return type;
            } else if (ptolemy.data.Token.class.isAssignableFrom(tokenClass)) {
                Type type = BaseType.forClassName(tokenClass.getName());

                if (type == null) {
                    throw new IllegalActionException(
                            "Could not return type for class " + tokenClass);
                }
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.