示例#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();
        }
示例#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);
            }
        }
示例#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);
            }
        }
示例#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();
        }
示例#5
0
 private IGate Convert(GateConverter gc, int stage, IGate c)
 {
     //return gc.ConvertToGate(stage, c);
     return c;
 }
示例#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));
        }
示例#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();
        }
示例#8
0
 protected CodeGenerator(CodeWriter writer)
 {
     this._writer = writer;
     _gc = null;
     Parameters = new CodeParameters();
 }
示例#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();
        }
示例#10
0
 protected CodeGenerator(CodeWriter writer)
 {
     this._writer = writer;
     _gc          = null;
     Parameters   = new CodeParameters();
 }
示例#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);*/
        }