Exemple #1
0
        private void BeginHandler(Event e)
        {
            // code generation start here
            EmitHandlerHeader(e.Name);
            EmitEnterBlock();

            _gc = new GateConverter();

            // process labels before they are added ...
            _gc.OnBeforeAddLabel = EvaluateCodeLabelBefore;

            _guards        = new GuardCollection();
            _effectsbefore = new EffectsCollection();
            _effectsafter  = new EffectsCollection();
        }
Exemple #2
0
        internal CodeLabel(GateConverter gc, int stage, int index, string name, IGate g)
            : this(index, name)
        {
            _gc = gc;
            _originalgate = _gate = g;

            Stage = stage;

            Debug.Assert(!(g is CodeLabel));

            // if (g is IVariableCondition)
            {
                _gate = new LabelGate(this);
            }
        }
Exemple #3
0
        internal CodeLabel(GateConverter gc, int stage, int index, string name, IGate g)
            : this(index, name)
        {
            _gc           = gc;
            _originalgate = _gate = g;

            Stage = stage;

            Debug.Assert(!(g is CodeLabel));

            // if (g is IVariableCondition)
            {
                _gate = new LabelGate(this);
            }
        }
Exemple #4
0
        private void EndHandler()
        {
            if (TraceFlags.ShowLabel)
            {
                Trace("labels:\n{0}", _gc.ToDebugString());
            }

            _guards        = null;
            _effectsbefore = null;
            _effectsafter  = null;

            _gc.Dispose();
            _gc = null;

            EmitLeaveBlock();
            Writer.AppendComment();
        }
Exemple #5
0
 private IGate Convert(GateConverter gc, int stage, IGate c)
 {
     //return gc.ConvertToGate(stage, c);
     return c;
 }
Exemple #6
0
        /*internal IGate EvaluateAndCompose(GateConverter gc, IGate pre, IGate post)
        {
            switch (GuardType)
            {
                case GuardType.LEAVE:
                    pre = Gate.ComposeAND(pre, PreCondition);
                    break;

                case GuardType.TRANSITION:
                    c = Gate.ComposeAND(c, Convert(gc, 0, PreCondition));
                    c = Gate.ComposeAND(c, Convert(gc, 1, PostCondition));
                    break;

                case GuardType.ENTER:
                    c = Gate.ComposeAND(c, Convert(gc, 1, PostCondition));
                    break;

                default:
                    throw new ArgumentException("invalid guard type.");
            }

            return c;
        }*/
        private IGate Compose(GateConverter gc, IGate c, IGate a)
        {
            return Gate.ComposeAND(c, a);
            //return Gate.ComposeAND(c, Convert(gc, 0, a));
        }
Exemple #7
0
        private void EndHandler()
        {
            if(TraceFlags.ShowLabel)
            {
                Trace("labels:\n{0}", _gc.ToDebugString());
            }

            _guards = null;
            _effectsbefore = null;
            _effectsafter = null;

            _gc.Dispose();
            _gc = null;

            EmitLeaveBlock();
            Writer.AppendComment();
        }
Exemple #8
0
 protected CodeGenerator(CodeWriter writer)
 {
     this._writer = writer;
     _gc = null;
     Parameters = new CodeParameters();
 }
Exemple #9
0
        private void BeginHandler(Event e)
        {
            // code generation start here
            EmitHandlerHeader(e.Name);
            EmitEnterBlock();

            _gc = new GateConverter();

            // process labels before they are added ...
            _gc.OnBeforeAddLabel = EvaluateCodeLabelBefore;

            _guards = new GuardCollection();
            _effectsbefore = new EffectsCollection();
            _effectsafter = new EffectsCollection();
        }
Exemple #10
0
 protected CodeGenerator(CodeWriter writer)
 {
     this._writer = writer;
     _gc          = null;
     Parameters   = new CodeParameters();
 }
Exemple #11
0
        public void SMG_04_03_CodeLabels()
        {
            GateCache.Instance.Purge();

            var cc = new StateMachineCompiler();
            var sm = cc.CompileString(
                "SMG test " +
                "DECLARE State (a, b, c) s, t " +
                "TRIGGER e WHEN s(a => b) AND t(b) " +
                "GUARD WHEN s(* => b) AND t(b) CALL m1 " +
                ""
                );

            sm.Calculate();

            PrintEventEffectConditions(sm);

            var ev = sm.Events.Where(e => e.Name == "e").First();

            using (var gc = new GateConverter())
            {
                ev.EffectsAfter.Schedule(gc);

                var cle = new SimpleCodeLabelEvaluator();

                // Trace("gc: \n{0}", gc.ToDebugString());
                gc.Emit(cle, 0);
            }

            var eclist = ev.EffectsAfter.GetEffectConditions();
            var ec = eclist.Where(a => a.Effect.UniqueID == "CALL m1").First();

            Assert.AreEqual("<_c0><_c1>", ec.ConditionLabel.ToString());

            /*var sb = new StringBuilder();
            using (var w = new StringWriter(sb))
            {
                w.Write(sm.GenerateCode());
            }

            Trace("code:\n{0}", sb);*/
        }