Example #1
0
        public void Schedule()
        {
            var first = 0 == _schedulecount;

            _schedulecount++;

            if (first)
            {
                if (!TraceFlags.DisableNestedCodeLabelScheduling)
                {
                    foreach (var e in _originalgate.SelectAll(e => e is LabelGate))
                    {
                        if (e is LabelGate)
                        {
                            ((LabelGate)e).Schedule();
                        }
                        else if (e.Type.IsLogical())
                        {
                            _gc.Schedule(e);
                        }
                    }
                }

                _gc.Queue(this);
            }
        }
Example #2
0
        /// <summary>
        /// Emits code for a single event handler.
        /// </summary>
        /// <param name="e"></param>
        private void EmitEventHandler(Event e)
        {
            BeginHandler(e);

            PrepareTransitionSet(e);

            // use gate converter to schedule condition evaluation
            ConvertConditions(e);

            // stage 0: preconditions and LEAVE handlers
            _guards.AddLeaveEffects(_effectsbefore);
            _guards.AddEnterEffects(_effectsafter);
            AddTriggerEffects(e.Triggers);

            foreach (var t in e.Triggers)
            {
                var c = _gc.ConvertToGate(0, t.PreCondition);
                _gc.Schedule(c);
            }

            _effectsbefore.Schedule(_gc);
            _effectsafter.Schedule(_gc);

            // code output: precondition labels
            EmitCodeLabels(0);

            // pre-effects
            if (!_effectsbefore.IsEmpty)
            {
                Writer.AppendComment();
                Writer.AppendComment("state exit handler effects");

                EmitEffects(_effectsbefore.GetEffectConditions());
            }

            // emit state transition code
            EmitTriggerStateChange(_writer, e.Triggers);

            // stage 1: postconditions and other handlers.
            _gc.SetNextStage();

            // code output: postcondition labels
            EmitCodeLabels(1);

            // post-effects
            if (!_effectsafter.IsEmpty)
            {
                Writer.AppendComment();
                Writer.AppendComment("state entry handler effects");

                EmitEffects(_effectsafter.GetEffectConditions());
            }

            EndHandler();
        }