Ejemplo n.º 1
0
        public static IEnumerable <IJsmInstruction> Flatten(this IJsmInstruction e)
        {
            bool checkType(IJsmInstruction inst)
            {
                return
                    (inst is Control.While.WhileSegment ||
                     inst is Control.If.ElseIfSegment ||
                     inst is Control.If.ElseSegment ||
                     inst is Control.If.IfSegment ||
                     inst is ExecutableSegment);
            }

            if (checkType(e))
            {
                var es = ((ExecutableSegment)e);
                foreach (var child in es.Where(checkType).Select(x => (ExecutableSegment)x))
                {
                    foreach (var i in Flatten(child))
                    {
                        yield return(i);
                    }
                }
                foreach (var child in es.Where(x => !checkType(x)))
                {
                    yield return(child);
                }
            }
            else
            {
                yield return(e);
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <IJsmInstruction> Flatten(this IJsmInstruction e)
        {
            bool checktype(IJsmInstruction inst)
            {
                return
                    (typeof(Control.While.WhileSegment) == inst.GetType() ||
                     typeof(Control.If.ElseIfSegment) == inst.GetType() ||
                     typeof(Control.If.ElseSegment) == inst.GetType() ||
                     typeof(Control.If.IfSegment) == inst.GetType() ||
                     typeof(Jsm.ExecutableSegment) == inst.GetType());
            }

            if (checktype(e))
            {
                ExecutableSegment es = ((ExecutableSegment)e);
                foreach (ExecutableSegment child in es.Where(x => checktype(x)).Select(x => (ExecutableSegment)x))
                {
                    foreach (IJsmInstruction i in Flatten(child))
                    {
                        yield return(i);
                    }
                }
                foreach (IJsmInstruction child in es.Where(x => !checktype(x)))
                {
                    yield return(child);
                }
            }
            else
            {
                yield return(e);
            }
        }
Ejemplo n.º 3
0
 public void Add(IJsmInstruction value)
 {
     _list.Add(value);
 }