Package ptolemy.data.expr

Examples of ptolemy.data.expr.Variable


    private int _getTokenConsumptionRate(Receiver receiver)
            throws IllegalActionException {
        int tokenConsumptionRate;

        IOPort port = receiver.getContainer();
        Variable rateVariable = null;
        Token token = null;
        Receiver[][] portReceivers = null;

        // If DDF domain is inside another domain and the
        // receiver is contained by an opaque output port...
        // The default production rate is -1 which means all
        // tokens in the receiver are transferred to the outside.
        if (port.isOutput()) {
            rateVariable = DFUtilities.getRateVariable(port,
                    "tokenProductionRate");
            portReceivers = port.getInsideReceivers();

            if (rateVariable == null) {
                tokenConsumptionRate = -1;
                return tokenConsumptionRate;
            } else {
                token = rateVariable.getToken();

                if (token == null) {
                    tokenConsumptionRate = -1;
                    return tokenConsumptionRate;
                }
            }
        }

        if (port.isInput()) {
            rateVariable = DFUtilities.getRateVariable(port,
                    "tokenConsumptionRate");
            portReceivers = port.getReceivers();

            if (rateVariable == null) {
                tokenConsumptionRate = 1;
                return tokenConsumptionRate;
            } else {
                token = rateVariable.getToken();

                if (token == null) {
                    tokenConsumptionRate = 1;
                    return tokenConsumptionRate;
                }
View Full Code Here


        if (offset == null) {
            if (attribute instanceof Variable) {
                // FIXME: need to ensure that the returned string
                // is correct syntax for the target language.
                Variable variable = (Variable) attribute;

                /*
                 if (_codeGenerator._modifiedVariables.contains(variable)) {
                 return generateVariableName(variable);
                 } else if (variable.isStringMode()) {
                 return "\"" + variable.getExpression() + "\"";
                 }
                 */

                ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
                if (variable.isStringMode()) {
                    return _generateTypeConvertMethod("\""
                            + parseTreeCodeGenerator
                                    .escapeForTargetLanguage(variable
                                            .getExpression()) + "\"", castType,
                            "String");
                }

                PtParser parser = new PtParser();
                ASTPtRootNode parseTree = null;
                try {
                    parseTree = parser.generateParseTree(variable
                            .getExpression());
                } catch (Throwable throwable) {
                    throw new IllegalActionException(variable, throwable,
                            "Failed to generate parse tree for \"" + name
                                    + "\". in \"" + container + "\"");
                }
                parseTreeCodeGenerator.evaluateParseTree(parseTree,
                        new VariableScope(variable));

                String fireCode = processCode(parseTreeCodeGenerator
                        .generateFireCode());

                //if (castType == null && codeGenType(variable.getType()).equals("Array")) {
                // FIXME: this is a gross hack necessary for Case.
                // The problem is that if the refinement is named "{0}", then
                // we get into trouble because {0} is "false"?  sigh.
                //    return "Array_new(1, 1, " + fireCode + ");";
                //}
                return _generateTypeConvertMethod(fireCode, castType,
                        codeGenType(variable.getType()));

            } else /* if (attribute instanceof Settable)*/{
                return ((Settable) attribute).getExpression();
            }

View Full Code Here

        }

        int[] rate = new int[port.getWidthInside()];
        Arrays.fill(rate, -1);

        Variable rateVariable = DFUtilities.getRateVariable(port,
                "tokenProductionRate");

        if (rateVariable != null) {
            Token token = rateVariable.getToken();

            if (token != null) {
                // If token is ArrayToken, then each channel has a
                // corresponding output rate in the array.
                if (token instanceof ArrayToken) {
View Full Code Here

    public ConstVariableModelAnalysis(Entity model, Set variableSet)
            throws IllegalActionException {
        _variableToChangeContext = new HashMap();

        for (Iterator variables = variableSet.iterator(); variables.hasNext();) {
            Variable variable = (Variable) variables.next();
            _variableToChangeContext.put(variable, model);
        }

        _dependencyGraph = new DirectedGraph();
View Full Code Here

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////
    // Add the dependence information from the given attribute to the
    // dependence graph.
    private void _addDependencyDeclaration(DependencyDeclaration declaration) {
        Variable variable = (Variable) declaration.getContainer();
        Node targetNode = _getNode(variable);

        for (Iterator dependents = declaration.getDependents().iterator(); dependents
                .hasNext();) {
            Variable dependent = (Variable) dependents.next();
            Node dependentNode = _getNode(dependent);

            //  if (!_dependencyGraph.edgeExists(node, targetNode)) {
            _dependencyGraph.addEdge(dependentNode, targetNode);
View Full Code Here

        try {
            Set freeIdentifiers = variable.getFreeIdentifiers();

            for (Iterator names = freeIdentifiers.iterator(); names.hasNext();) {
                String name = (String) names.next();
                Variable dependent = ModelScope.getScopedVariable(variable,
                        variable, name);

                if (dependent != null) {
                    Node dependentNode = _getNode(dependent);
                    _dependencyGraph.addEdge(dependentNode, targetNode);
View Full Code Here

    // given map from each dynamic parameter deeply contained in the
    // given entity to the change context of that parameter.
    private void _collectConstraints(NamedObj container)
            throws IllegalActionException {
        if (container instanceof Variable) {
            Variable variable = (Variable) container;
            _collectVariableConstraints(variable);
        }

        if (container instanceof DependencyDeclaration) {
            DependencyDeclaration declaration = (DependencyDeclaration) container;
            _addDependencyDeclaration(declaration);
        }

        if (container instanceof PortParameter) {
            PortParameter parameter = (PortParameter) container;
            ParameterPort port = parameter.getPort();

            // Under what conditions is a PortParameter not associated
            // with a port?
            if ((port != null) && (port.getWidth() > 0)) {
                _updateChangeContext(parameter, (Entity) parameter
                        .getContainer());
            }
        }

        if (container instanceof ExplicitChangeContext) {
            List list = ((ExplicitChangeContext) container)
                    .getModifiedVariables();

            for (Iterator variables = list.iterator(); variables.hasNext();) {
                Variable variable = (Variable) variables.next();
                _updateChangeContext(variable,
                        ((ExplicitChangeContext) container).getContext());
            }
        }
View Full Code Here

    private void _analyzeAllVariables() {
        // Sets of variables used to track the fixed point iteration.
        LinkedList workList = new LinkedList(_variableToChangeContext.keySet());

        while (!workList.isEmpty()) {
            Variable variable = (Variable) workList.removeFirst();
            Node node = _dependencyGraph.node(variable);
            Entity changeContext = (Entity) _variableToChangeContext
                    .get(variable);

            for (Iterator outputEdges = _dependencyGraph.outputEdges(node)
                    .iterator(); outputEdges.hasNext();) {
                Node sinkNode = ((Edge) outputEdges.next()).sink();
                Variable targetVariable = (Variable) sinkNode.getWeight();

                if (_updateChangeContext(targetVariable, changeContext)
                        && !workList.contains(targetVariable)) {
                    workList.addLast(targetVariable);
                }
View Full Code Here

                        // then read and write positions in the buffer
                        // must return to the previous values after one
                        // iteration of the container actor in order to
                        // avoid using read and write offset variables.
                        if (inline) {
                            Variable firings = (Variable) ((NamedObj) actor)
                                    .getAttribute("firingsPerIteration");
                            int firingsPerIteration = ((IntToken) firings
                                    .getToken()).intValue();
                            readTokens = DFUtilities.getRate(inputPort)
                                    * firingsPerIteration;
                            writeTokens = readTokens;

View Full Code Here

        /** Look up and return the attribute with the specified name in the
         *  scope. Return null if such an attribute does not exist.
         *  @return The attribute with the specified name in the scope.
         */
        public Token get(String name) throws IllegalActionException {
            Variable result = getScopedVariable(null, ExpressionToToken.this,
                    name);

            if (result != null) {
                return result.getToken();
            }

            return null;
        }
View Full Code Here

TOP

Related Classes of ptolemy.data.expr.Variable

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.