Package ptolemy.data.expr

Examples of ptolemy.data.expr.Variable


        }
    }

    public InequalityTerm getTypeTerm(String name)
            throws IllegalActionException {
        Variable result = getScopedVariable(null, _container, name);

        if (result != null) {
            return result.getTypeTerm();
        } else {
            return null;
        }
    }
View Full Code Here


     @return The variable with the specified name in the given port.
     *  @exception IllegalActionException Not thrown in this method.
     *  @see #setRateVariable(Port, String, int)
     */
    public static Variable getRateVariable(Port port, String name) {
        Variable parameter = (Variable) port.getAttribute(name);

        if (parameter == null) {
            String altName = "_" + name;
            parameter = (Variable) port.getAttribute(altName);
        }
View Full Code Here

     @exception IllegalActionException If the variable does not contain
     *  a valid token, or the token is not an IntToken.
     */
    public static int getRateVariableValue(Port port, String name,
            int defaultValue) throws IllegalActionException {
        Variable parameter = getRateVariable(port, name);

        if (parameter == null) {
            return defaultValue;
        }

        Token token = parameter.getToken();

        if (token instanceof IntToken) {
            return ((IntToken) token).intValue();
        } else {
            throw new IllegalActionException("Variable "
                    + parameter.getFullName() + " was expected "
                    + "to contain an IntToken, but instead " + "contained a "
                    + token.getType() + ".");
        }
    }
View Full Code Here

     @exception IllegalActionException If a new parameter can not be
     *  created for the give port.
     */
    public static void setExpressionIfNotDefined(Port port, String name,
            String value) throws IllegalActionException {
        Variable rateParameter = (Variable) port.getAttribute(name);

        if (rateParameter == null) {
            try {
                String altName = "_" + name;
                rateParameter = (Variable) port.getAttribute(altName);

                if (rateParameter == null) {
                    rateParameter = new Parameter(port, altName);
                    rateParameter.setVisibility(Settable.NOT_EDITABLE);
                    rateParameter.setPersistent(false);
                }

                rateParameter.setExpression(value);
            } catch (KernelException ex) {
                throw new InternalErrorException(port, ex, "Should not occur");
            }
        }
    }
View Full Code Here

     @exception IllegalActionException If a new parameter can not be
     *  created for the given port, or the given value is not an acceptable.
     */
    public static void setIfNotDefined(Port port, String name, int value)
            throws IllegalActionException {
        Variable rateParameter = (Variable) port.getAttribute(name);

        if (rateParameter == null) {
            try {
                String altName = "_" + name;
                rateParameter = (Variable) port.getAttribute(altName);

                if (rateParameter == null) {
                    rateParameter = new Parameter(port, altName);
                    rateParameter.setVisibility(Settable.NOT_EDITABLE);
                    rateParameter.setPersistent(false);
                }

                rateParameter.setToken(new IntToken(value));
            } catch (KernelException ex) {
                throw new InternalErrorException(port, ex, "Should not occur");
            }
        }
    }
View Full Code Here

     @param context The context for the preference.
     *  @param preferenceName The name of the preference.
     *  @return The value of the preference, or null if it is not set.
     */
    public static Token preferenceValue(NamedObj context, String preferenceName) {
        Variable result = ModelScope.getScopedVariable(null, context,
                preferenceName);

        if (result != null) {
            try {
                return result.getToken();
            } catch (IllegalActionException ex) {
                System.out.println("Warning: Invalid preference: " + ex);
            }
        }

View Full Code Here

        // Make the current global variables conform with any
        // overridden preference values.
        Iterator parameters = attributeList(Variable.class).iterator();

        while (parameters.hasNext()) {
            Variable parameter = (Variable) parameters.next();
            Token token = parameter.getToken();
            Constants.add(parameter.getName(), token);
        }
    }
View Full Code Here

                if (child instanceof ActorScopeExtender) {
                    continue;
                }

                try {
                    Variable variable = NamedObjVariable.getNamedObjVariable(
                            child, true);
                    if (variable != null) {
                        _attributeList.add(variable);
                    }
                } catch (IllegalActionException e) {
View Full Code Here

        if (child == null) {
            return super.getAttribute(name);
        }

        try {
            Variable actorVariable = NamedObjVariable.getNamedObjVariable(
                    child, true);
            return actorVariable;
        } catch (IllegalActionException e) {
            throw new InternalErrorException(e);
        }
View Full Code Here

        // Next, compute the set of variable names defined in this container.
        Set variableNames = new HashSet();

        for (Iterator variables = model.attributeList(Variable.class)
                .iterator(); variables.hasNext();) {
            Variable variable = (Variable) variables.next();
            variableNames.add(variable.getName());
        }

        variableNames = Collections.unmodifiableSet(variableNames);

        // Free variables of contained actors that are defined in this
        // container are not free variables of this container.
        set.removeAll(variableNames);

        // Iterate over all the variables of this container, and add in
        // any free variables they reference.
        PtParser parser = new PtParser();
        ParseTreeFreeVariableCollector collector = new ParseTreeFreeVariableCollector();

        for (Iterator variables = model.attributeList(Variable.class)
                .iterator(); variables.hasNext();) {
            Variable variable = (Variable) variables.next();
            String expression = variable.getExpression();
            ASTPtRootNode root;

            if (variable.isStringMode()) {
                root = parser.generateStringParseTree(expression);
            } else {
                root = parser.generateParseTree(expression);
            }

            Set freeIdentifiers = new HashSet(collector
                    .collectFreeVariables(root));

            // Identifiers that reference other variables in the same container
            // are bound, not free.
            Set tempSet = new HashSet(variableNames);
            tempSet.remove(variable.getName());
            freeIdentifiers.removeAll(tempSet);

            set.addAll(freeIdentifiers);
        }
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.