Package ptolemy.domains.fsm.kernel

Examples of ptolemy.domains.fsm.kernel.Transition


                }

                // Determine the next state in this state.
                for (Iterator transitions = state.outgoingPort
                        .linkedRelationList().iterator(); transitions.hasNext();) {
                    Transition transition = (Transition) transitions.next();
                    System.out.println("transition = " + transition);

                    String guardExpression = transition.getGuardExpression();

                    Local guardLocal = DataUtilities.generateExpressionCode(
                            entity, entityInstanceClass, guardExpression,
                            nameToField, nameToType, body);

                    // Test the guard.
                    units
                            .add(Jimple
                                    .v()
                                    .newAssignStmt(
                                            tokenLocal,
                                            Jimple
                                                    .v()
                                                    .newCastExpr(
                                                            guardLocal,
                                                            RefType
                                                                    .v(PtolemyUtilities.booleanTokenClass))));
                    units.add(Jimple.v().newAssignStmt(
                            flagLocal,
                            Jimple.v().newVirtualInvokeExpr(
                                    tokenLocal,
                                    PtolemyUtilities.booleanValueMethod
                                            .makeRef())));

                    Stmt skipStmt = Jimple.v().newNopStmt();

                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(flagLocal, IntConstant.v(0)),
                            skipStmt));
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(transitionTakenLocal,
                                    IntConstant.v(1)), errorStmt));

                    // If transition taken, then store the next state
                    units.add(Jimple.v().newAssignStmt(transitionTakenLocal,
                            IntConstant.v(1)));
                    units.add(Jimple.v().newAssignStmt(
                            nextTransitionLocal,
                            IntConstant.v(entity.relationList().indexOf(
                                    transition))));

                    int nextStateIndex = entity.entityList().indexOf(
                            transition.destinationState());
                    units.add(Jimple.v().newAssignStmt(nextStateLocal,
                            IntConstant.v(nextStateIndex)));

                    // Generate code for the outputExpression of the guard.
                    for (Iterator actions = transition.choiceActionList()
                            .iterator(); actions.hasNext();) {
                        AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                                .next();
                        System.out.println("action = " + action);
                        _generateActionCode(entity, entityInstanceClass,
                                nameToField, nameToType, body, action);
                    }

                    units.add(skipStmt);
                }

                units.add(Jimple.v().newGotoStmt(finishedStmt));
            }

            units.add(errorStmt);

            // throw an exception.
            units.add(finishedStmt);

            Local exceptionLocal = SootUtilities.createRuntimeException(body,
                    errorStmt, "state error");
            units.insertBefore(Jimple.v().newThrowStmt(exceptionLocal),
                    errorStmt);

            // Store the next state.
            units.add(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            currentStateField.makeRef()), nextStateLocal));

            // And the next Transition.
            units.add(Jimple.v()
                    .newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    nextTransitionField.makeRef()),
                            nextTransitionLocal));

            // return void
            units.add(Jimple.v().newReturnVoidStmt());

            LocalNameStandardizer.v().transform(body, "at.lns");
            LocalSplitter.v().transform(body, "at.ls");
        }
        // populate the postfire method.
        {
            System.out.println("create postfire()");

            SootMethod postfireMethod = new SootMethod("postfire",
                    Collections.EMPTY_LIST, BooleanType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(postfireMethod);

            JimpleBody body = Jimple.v().newBody(postfireMethod);
            postfireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Map transitionToStartStmt = new HashMap();
            List transitionStmtList = new LinkedList();
            int numberOfTransitions = entity.relationList().size();

            // Figure out what transition we are in.
            for (Iterator transitions = entity.relationList().iterator(); transitions
                    .hasNext();) {
                Transition transition = (Transition) transitions.next();
                Stmt startStmt = Jimple.v().newNopStmt();

                transitionToStartStmt.put(transition, startStmt);
                transitionStmtList.add(startStmt);
            }

            Local nextTransitionLocal = Jimple.v().newLocal(
                    "nextTransitionLocal", IntType.v());
            body.getLocals().add(nextTransitionLocal);

            units.add(Jimple.v().newAssignStmt(
                    nextTransitionLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            nextTransitionField.makeRef())));

            Stmt finishedStmt = Jimple.v().newNopStmt();
            Stmt errorStmt = Jimple.v().newNopStmt();

            // Get the current transition..
            units.add(Jimple.v().newTableSwitchStmt(nextTransitionLocal, 0,
                    numberOfTransitions - 1, transitionStmtList, errorStmt));

            // Generate code for each transition
            for (Iterator transitions = entity.relationList().iterator(); transitions
                    .hasNext();) {
                Transition transition = (Transition) transitions.next();
                Stmt startStmt = (Stmt) transitionToStartStmt.get(transition);
                units.add(startStmt);

                // Generate code for the commitExpression of the guard.
                for (Iterator actions = transition.commitActionList()
                        .iterator(); actions.hasNext();) {
                    AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                            .next();
                    _generateActionCode(entity, entityInstanceClass,
                            nameToField, nameToType, body, action);
                }

                // Generate code to reinitialize the target state, if
                // reset is true.
                TypedActor[] refinements = null;

                try {
                    BooleanToken resetToken = (BooleanToken) transition.reset
                            .getToken();

                    if (resetToken.booleanValue()) {
                        refinements = (transition.destinationState())
                                .getRefinement();
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex.getMessage());
                }
View Full Code Here


            } else {
                codeBuffer.append("else if (");
            }
            transitionCount++;

            Transition transition = (Transition) transitions.next();

            // generate code for guard expression
            String guard = transition.getGuardExpression();
            PtParser parser = new PtParser();
            ASTPtRootNode guardParseTree = parser.generateParseTree(guard);
            ParseTreeCodeGenerator parseTreeCodeGenerator = controllerHelper
                    .getParseTreeCodeGenerator();
            parseTreeCodeGenerator.evaluateParseTree(guardParseTree,
                    controllerHelper._scope);
            codeBuffer.append(parseTreeCodeGenerator.generateFireCode());
            codeBuffer.append(") {" + _eol);

            // generate code for commit action
            Iterator actions = transition.commitActionList().iterator();
            while (actions.hasNext()) {
                AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                        .next();
                Iterator destinationNameList = action.getDestinationNameList()
                        .iterator();

                while (destinationNameList.hasNext()) {
                    String destinationName = (String) destinationNameList
                            .next();
                    NamedObj destination = action
                            .getDestination(destinationName);
                    ASTPtRootNode parseTree = action
                            .getParseTree(destinationName);
                    if (destination instanceof Variable) {
                        codeBuffer.append(_codeGenerator
                                .generateVariableName((Variable) destination)
                                + " = ");
                    } else {
                        throw new IllegalActionException("No output can be"
                                + " produced in any action for "
                                + "MultirateFSMDirector.");
                    }
                    parseTreeCodeGenerator = controllerHelper
                            .getParseTreeCodeGenerator();
                    parseTreeCodeGenerator.evaluateParseTree(parseTree,
                            controllerHelper._scope);
                    codeBuffer
                            .append(parseTreeCodeGenerator.generateFireCode());
                    codeBuffer.append(";" + _eol);
                }
            }

            // All contained actors must be initialized before the
            // configuration number of the container actor can be
            // updated.
            codeBuffer.append(super.generateInitializeCode());

            // Generate code for updating current state.
            // This overrides using initial state as the current state in
            // the initialize code of the controller.
            State destinationState = transition.destinationState();
            controllerHelper._updateCurrentState(codeBuffer, destinationState,
                    0);

            // Generate code for updating configuration number of this
            // FSMActor's container actor.
View Full Code Here

        accelState.refinementName.setExpression("AccelCTSub");
        cruise1State.refinementName.setExpression("Cruise1CTSub");
        climbState.refinementName.setExpression("ClimbCTSub");
        cruise2State.refinementName.setExpression("Cruise2CTSub");

        Transition tr1 = new Transition(hsctrl, "tr1");
        hoverState.outgoingPort.link(tr1);
        accelState.incomingPort.link(tr1);
        tr1.setGuardExpression("inputAction");

        Transition tr2 = new Transition(hsctrl, "tr2");
        accelState.outgoingPort.link(tr2);
        cruise1State.incomingPort.link(tr2);
        tr2.setGuardExpression("(outputV >= 5.0) && (inputPz > -2.05) "
                + "&& (inputPz < -1.95)");

        Transition tr3 = new Transition(hsctrl, "tr3");
        cruise1State.outgoingPort.link(tr3);
        climbState.incomingPort.link(tr3);
        tr3.setGuardExpression("(outputV > 4.9) && (outputV < 5.1) "
                + "&& (outputR > -0.01) && (outputR < 0.01)");

        Transition tr4 = new Transition(hsctrl, "tr4");
        climbState.outgoingPort.link(tr4);
        cruise2State.incomingPort.link(tr4);

        //
        tr4.setGuardExpression("(outputV > 4.9) && (outputV < 5.1) "
                + "&& (inputPz > -10.05) && (inputPz < -9.95)");

        TypedIORelation rSubPx = new TypedIORelation(sub, "rSubPx");
        TypedIORelation rSubDPx = new TypedIORelation(sub, "rSubDPx");
        TypedIORelation rSubDDPx = new TypedIORelation(sub, "rSubDDPx");
View Full Code Here

                MessageHandler
                        .error("Can only add refinements to transitions.");
                return;
            }

            Transition transition = (Transition) target;

            // Check that all these containers exist.
            Nameable immediateContainer = transition.getContainer();

            if (immediateContainer == null) {
                MessageHandler.error("Transition has no container!");
                return;
            }

            final CompositeEntity container = (CompositeEntity) immediateContainer
                    .getContainer();

            if (container == null) {
                MessageHandler.error("Transition container has no container!");
                return;
            }

            // Open a dialog to get the refinement name and class.
            Query query = new Query();
            String defaultName = container.uniqueName(transition.getName());
            query.addLine("Name", "Name", defaultName);

            // See whether the configuration offers transition refinements.
            Configuration configuration = ((FSMGraphController) getController())
                    .getConfiguration();
            Entity refinements = configuration
                    .getEntity("_transitionRefinements");

            // Default choices.
            String[] choiceClasses = { "ptolemy.domains.fsm.modal.TransitionRefinement" };
            String[] choiceNames = { "Default Refinement" };

            // Check the configuration to see whether the default is overridden.
            if (refinements instanceof CompositeEntity) {
                // There is a specification.
                List refinementList = ((CompositeEntity) refinements)
                        .entityList();
                choiceNames = new String[refinementList.size()];
                choiceClasses = new String[refinementList.size()];

                Iterator iterator = refinementList.iterator();
                int count = 0;

                while (iterator.hasNext()) {
                    Entity entity = (Entity) iterator.next();
                    choiceNames[count] = entity.getName();
                    choiceClasses[count++] = entity.getClass().getName();
                }
            }

            query
                    .addChoice("Class", "Class", choiceNames, choiceNames[0],
                            true);

            // FIXME: Need a frame owner for first arg.
            // Perhaps calling getController(), which returns a GraphController
            // will be a good start.
            ComponentDialog dialog = new ComponentDialog(null,
                    "Specify Refinement", query);

            if (!dialog.buttonPressed().equals("OK")) {
                return;
            }

            final String newName = query.getStringValue("Name");

            if (container.getEntity(newName) != null) {
                MessageHandler.error("There is already a refinement with name "
                        + newName + ".");
                return;
            }

            int choiceIndex = query.getIntValue("Class");
            String newClass = choiceClasses[choiceIndex];

            String currentRefinements = transition.refinementName
                    .getExpression();

            if ((currentRefinements == null) || currentRefinements.equals("")) {
                currentRefinements = newName;
            } else {
                currentRefinements = currentRefinements.trim() + ", " + newName;
            }

            String moml;

            // The MoML we create depends on whether the configuration
            // specified a set of prototype refinements.
            if (refinements instanceof CompositeEntity) {
                String choiceName = choiceNames[choiceIndex];
                Entity template = ((CompositeEntity) refinements)
                        .getEntity(choiceName);
                String templateDescription = template.exportMoML(newName);
                moml = "<group>" + templateDescription + "<relation name=\""
                        + transition.getName(container)
                        + "\"><property name=\"refinementName\" value=\""
                        + currentRefinements + "\"/></relation></group>";
            } else {
                moml = "<group><entity name=\"" + newName + "\" class=\""
                        + newClass + "\"/>" + "<relation name=\""
                        + transition.getName(container)
                        + "\"><property name=\"refinementName\" value=\""
                        + currentRefinements + "\"/></relation></group>";
            }

            MoMLChangeRequest change = new MoMLChangeRequest(this, container,
View Full Code Here

                MessageHandler
                        .error("Can only remove refinements from transitions.");
                return;
            }

            Transition transition = (Transition) target;

            // Check that all these containers exist.
            CompositeEntity immediateContainer = (CompositeEntity) transition
                    .getContainer();

            if (immediateContainer == null) {
                MessageHandler.error("Transition has no container!");
                return;
            }

            final CompositeEntity container = (CompositeEntity) immediateContainer
                    .getContainer();

            if (container == null) {
                MessageHandler.error("Transition container has no container!");
                return;
            }

            TypedActor[] refinements;

            try {
                refinements = transition.getRefinement();
            } catch (Exception ex) {
                MessageHandler.error("Invalid refinements.", ex);
                return;
            }

            if ((refinements == null) || (refinements.length < 1)) {
                MessageHandler.error("No refinements to remove.");
                return;
            }

            String[] choices = new String[refinements.length];

            for (int i = 0; i < refinements.length; i++) {
                choices[i] = ((Nameable) refinements[i]).getName();
            }

            // Open a dialog to get the refinement name and class.
            Query query = new Query();
            query.addChoice("Refinement", "Refinement", choices, choices[0],
                    false);

            // FIXME: Need a frame owner for first arg.
            // Perhaps calling getController(), which returns a GraphController
            // will be a good start.
            ComponentDialog dialog = new ComponentDialog(null,
                    "Specify Refinement", query);

            if (!dialog.buttonPressed().equals("OK")) {
                return;
            }

            String refinementName = query.getStringValue("Refinement");
            StringBuffer newRefinements = new StringBuffer();
            String currentRefinements = transition.refinementName
                    .getExpression();
            StringTokenizer tokenizer = new StringTokenizer(currentRefinements,
                    ",");

            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();

                if (!token.trim().equals(refinementName)) {
                    if (newRefinements.length() > 0) {
                        newRefinements.append(", ");
                    }

                    newRefinements.append(token.trim());
                }
            }

            // Check to see whether any other transition has
            // this refinment, and if not, remove it from its container.
            Iterator transitions = immediateContainer.relationList().iterator();
            boolean foundOne = false;

            while (transitions.hasNext()) {
                NamedObj other = (NamedObj) transitions.next();

                if ((other != transition) && other instanceof Transition) {
                    String refinementList = ((Transition) other).refinementName
                            .getExpression();

                    if (refinementList == null) {
                        continue;
                    }

                    tokenizer = new StringTokenizer(refinementList, ",");

                    while (tokenizer.hasMoreTokens()) {
                        String token = tokenizer.nextToken();

                        if (token.equals(refinementName)) {
                            foundOne = true;
                            break;
                        }
                    }

                    if (foundOne) {
                        break;
                    }
                }
            }

            if (!foundOne) {
                Iterator states = immediateContainer.entityList().iterator();

                while (states.hasNext()) {
                    NamedObj other = (NamedObj) states.next();

                    if (other instanceof State) {
                        String refinementList = ((State) other).refinementName
                                .getExpression();

                        if (refinementList == null) {
                            continue;
                        }

                        tokenizer = new StringTokenizer(refinementList, ",");

                        while (tokenizer.hasMoreTokens()) {
                            String token = tokenizer.nextToken();

                            if (token.equals(refinementName)) {
                                foundOne = true;
                                break;
                            }
                        }

                        if (foundOne) {
                            break;
                        }
                    }
                }
            }

            String removal = "";

            if (!foundOne) {
                removal = "<deleteEntity name=\"" + refinementName + "\"/>";
            }

            String moml = "<group><relation name=\""
                    + transition.getName(container)
                    + "\"><property name=\"refinementName\" value=\""
                    + newRefinements.toString() + "\"/></relation>" + removal
                    + "</group>";
            MoMLChangeRequest change = new MoMLChangeRequest(this, container,
                    moml);
View Full Code Here

                        "Cannot handle both ends of an edge being dragged.");
            }

            // Make the arc rerender itself so that geometry is preserved
            Arc arc = (Arc) edge;
            Transition transition = (Transition) arc.getRelation();

            if ((transition != null) && c instanceof ArcConnector) {
                double angle = ((ArcConnector) c).getAngle();
                double gamma = ((ArcConnector) c).getGamma();

                // Set the new exitAngle and gamma parameter values based
                // on the current arc.
                String moml = "<group><property name=\"exitAngle\" value=\""
                        + angle + "\"/>" + "<property name=\"gamma\" value=\""
                        + gamma + "\"/></group>";
                MoMLChangeRequest request = new MoMLChangeRequest(this,
                        transition, moml);
                transition.requestChange(request);
            }

            // rerender the edge.  This is necessary for several reasons.
            // First, the edge is only associated with a relation after it
            // is fully connected.  Second, edges that aren't
View Full Code Here

            c.setHeadEnd(arrowhead);
            c.setLineWidth((float) 2.0);
            c.setUserObject(edge);

            Arc arc = (Arc) edge;
            Transition transition = (Transition) arc.getRelation();

            // When first dragging out a transition, the relation
            // may still be null.
            if (transition != null) {
                // Use a larger, unfilled arrowhead for a reset transition.
                try {
                    if (((BooleanToken) transition.reset.getToken())
                            .booleanValue()) {
                        arrowhead.setFilled(false);
                    }
                } catch (IllegalActionException e) {
                    // Ignore erroneous parameter value.
                }
                if (transition.isPreemptive()) {
                    Blob blob = new Blob(0, 0, 0, Blob.BLOB_CIRCLE, 4.0,
                            Color.red);
                    blob.setFilled(true);
                    c.setTailEnd(blob);
                }
                if (transition.isNondeterministic()) {
                    c.setStrokePaint(Color.RED);
                }

                c.setToolTipText(transition.getName());

                String labelStr = transition.getLabel();

                try {
                    double exitAngle = ((DoubleToken) (transition.exitAngle
                            .getToken())).doubleValue();
View Full Code Here

            // Reorder transitions so that default transitions are at
            // the end of the list.
            List reOrderedTransitions = new LinkedList();
            List defaultTransitions = new LinkedList();
            while (transitions.hasNext()) {
                Transition transition = (Transition) transitions.next();
                if (transition.getName().equals("default")) {
                    defaultTransitions.add(transition);
                } else {
                    reOrderedTransitions.add(transition);
                }
            }
            reOrderedTransitions.addAll(defaultTransitions);
            transitions = reOrderedTransitions.iterator();

            int transitionCount = 0;
            depth++;

            while (transitions.hasNext()) {
                if (transitionCount == 0) {
                    codeBuffer.append(_getIndentPrefix(depth));
                    codeBuffer.append("if (");
                } else {
                    codeBuffer.append("else if (");
                }
                transitionCount++;

                Transition transition = (Transition) transitions.next();
                // generate code for guard expression
                if (transition.getName().equals("default")) {
                    codeBuffer.append("true");
                } else {
                    String guard = transition.getGuardExpression();
                    PtParser parser = new PtParser();
                    ASTPtRootNode guardParseTree = parser
                            .generateParseTree(guard);
                    ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
                    parseTreeCodeGenerator.evaluateParseTree(guardParseTree,
                            _scope);
                    codeBuffer
                            .append(parseTreeCodeGenerator.generateFireCode());
                }
                codeBuffer.append(") {" + _eol);

                depth++;

                // generate code for choice action
                Iterator actions = transition.choiceActionList().iterator();

                while (actions.hasNext()) {
                    AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                            .next();
                    Iterator destinationNameList = action
                            .getDestinationNameList().iterator();
                    Iterator channelNumberList = action.getChannelNumberList()
                            .iterator();
                    Iterator parseTreeList = action.getParseTreeList()
                            .iterator();

                    while (destinationNameList.hasNext()) {
                        String destinationName = (String) destinationNameList
                                .next();
                        Integer channelNumber = (Integer) channelNumberList
                                .next();
                        ASTPtRootNode parseTree = (ASTPtRootNode) parseTreeList
                                .next();
                        NamedObj destination = action
                                .getDestination(destinationName);

                        int channel = -1;
                        if (channelNumber != null) {
                            channel = channelNumber.intValue();
                        }

                        codeBuffer.append(_getIndentPrefix(depth));

                        // Note in choice action only output can be generated
                        // and no parameter be changed.
                        if (channel >= 0) {
                            codeBuffer.append("$ref(" + destinationName + "#"
                                    + channel + ") = ");

                            // During choice action, an output port
                            // receives token sent by itself when it
                            // is also an input port, i.e., when this
                            // FSMActor is used as a modal controller.

                            if (((IOPort) destination).isInput()) {
                                ComponentCodeGenerator containerHelper = _getHelper(((IOPort) destination)
                                        .getContainer().getContainer());
                                StringBuffer containerReference = new StringBuffer();

                                containerReference.append("$ref("
                                        + destination.getName());

                                if (((IOPort) destination).isMultiport()) {
                                    containerReference.append("#" + channel);
                                }

                                containerReference.append(")");

                                codeBuffer
                                        .append(((CodeGeneratorHelper) containerHelper)
                                                .processCode(containerReference
                                                        .toString())
                                                + " = ");
                            }
                        } else { // broadcast

                            int width = ((IOPort) action
                                    .getDestination(destinationName))
                                    .getWidth();

                            for (int i = 0; i < width; i++) {
                                codeBuffer.append("$ref(" + destinationName
                                        + "#" + i + ") = ");

                                // During choice action, an output
                                // port receives token sent by itself
                                // when it is also an input port,
                                // i.e., when this FSMActor is used as
                                // a modal controller.

                                if (((IOPort) destination).isInput()) {
                                    ComponentCodeGenerator containerHelper = _getHelper(((IOPort) destination)
                                            .getContainer().getContainer());
                                    StringBuffer containerReference = new StringBuffer();

                                    containerReference.append("$ref("
                                            + destination.getName());

                                    if (((IOPort) destination).isMultiport()) {
                                        containerReference.append("#" + i);
                                    }

                                    containerReference.append(")");

                                    codeBuffer
                                            .append(((CodeGeneratorHelper) containerHelper)
                                                    .processCode(containerReference
                                                            .toString())
                                                    + " = ");
                                }
                            }
                        }

                        ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
                        parseTreeCodeGenerator.evaluateParseTree(parseTree,
                                _scope);
                        codeBuffer.append(parseTreeCodeGenerator
                                .generateFireCode());
                        codeBuffer.append(";" + _eol);
                    }
                }

                boolean inline = ((BooleanToken) _codeGenerator.inline
                        .getToken()).booleanValue();

                // generate code for transition refinement
                Actor[] actors = transition.getRefinement();

                if (actors != null) {
                    for (int i = 0; i < actors.length; i++) {
                        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[i]);
                        // fire the actor
                        if (inline) {
                            codeBuffer.append(helper.generateFireCode());
                            codeBuffer.append(helper
                                    .generateTypeConvertFireCode());
                        } else {
                            codeBuffer
                                    .append(generateName((NamedObj) actors[i])
                                            + "();" + _eol);
                        }
                    }
                }

                // generate code for commit action
                actions = transition.commitActionList().iterator();

                while (actions.hasNext()) {
                    AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                            .next();
                    Iterator destinationNameList = action
                            .getDestinationNameList().iterator();
                    Iterator channelNumberList = action.getChannelNumberList()
                            .iterator();
                    Iterator parseTreeList = action.getParseTreeList()
                            .iterator();

                    while (destinationNameList.hasNext()) {
                        String destinationName = (String) destinationNameList
                                .next();
                        Integer channelNumber = (Integer) channelNumberList
                                .next();
                        ASTPtRootNode parseTree = (ASTPtRootNode) parseTreeList
                                .next();
                        NamedObj destination = action
                                .getDestination(destinationName);

                        int channel = -1;
                        if (channelNumber != null) {
                            channel = channelNumber.intValue();
                        }

                        codeBuffer.append(_getIndentPrefix(depth));

                        if (destination instanceof IOPort) {
                            if (channel >= 0) {
                                codeBuffer.append("$ref(" + destinationName
                                        + "#" + channel + ") = ");
                            } else { // broadcast

                                int width = ((IOPort) action
                                        .getDestination(destinationName))
                                        .getWidth();

                                for (int i = 0; i < width; i++) {
                                    codeBuffer.append("$ref(" + destinationName
                                            + "#" + i + ") = ");
                                }
                            }
                        } else if (destination instanceof Variable) {
                            codeBuffer
                                    .append(_codeGenerator
                                            .generateVariableName((Variable) destination)
                                            + " = ");
                        }

                        ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
                        parseTreeCodeGenerator.evaluateParseTree(parseTree,
                                _scope);
                        codeBuffer.append(parseTreeCodeGenerator
                                .generateFireCode());
                        codeBuffer.append(";" + _eol);
                    }
                }

                // generate code for updating current state
                State destinationState = transition.destinationState();
                _updateCurrentState(codeBuffer, destinationState, depth);

                // generate code for reinitialization if reset is
                // true.  we assume the value of reset itself cannot
                // be changed dynamically
View Full Code Here

TOP

Related Classes of ptolemy.domains.fsm.kernel.Transition

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.