Beispiel #1
0
        internal void CheckSubst(ChildType cur)
        {
            parentstate ps = parents_.Peek();

            if (ps.parent == null)
            {
                throw new ArgumentException("Can't substitute the root node");
            }

            IList proposed = (IList)subst_(cur);

            // note: we only visit children if no substitution
            // is performed.
            if (proposed == null)
            {
                VisitChildren(cur);
            }
            else if (!ps.is_list && proposed.Count == 1)
            {
                ps.field.SetValue(ps.parent, proposed[0]);
            }
            else if (ps.is_list)
            {
                IList thelist = (IList)ps.field.GetValue(ps.parent);
                thelist.RemoveAt(ps.pos);
                for (int i = 0; i < proposed.Count; ++i)
                {
                    thelist.Insert(ps.pos + i, proposed[i]); // may throw
                }
            }
        }
Beispiel #2
0
        internal void VisitChildren(object cur)
        {
            parents_.Push(new parentstate()
            {
                parent = cur, is_list = false
            });
            parentstate ps = parents_.Peek();

            foreach (var f in TreeInfo.ChildEntries(cur))
            {
                ps.field = f;
                gen.Visit(this, f.GetValue(cur), true);
            }
            ps.is_list = true;
            foreach (var f in TreeInfo.ChildListEntries(cur))
            {
                ps.field = f;
                ps.pos   = 0;
                var enumerator = (System.Collections.IList)f.GetValue(cur);
                for (ps.pos = 0; ps.pos < enumerator.Count; ++ps.pos)
                {
                    gen.Visit(this, enumerator[ps.pos], true);
                }
            }
            parents_.Pop();
        }
Beispiel #3
0
        internal void CheckSubst(ChildType cur)
        {
            parentstate ps = parents_.Peek();

            if (ps.parent == null)
            {
                throw new ArgumentException("Can't substitute the root node");
            }

            ChildType proposed = subst_(cur) as ChildType;

            // note: we only visit children if no substitution
            // is performed.
            if (proposed == null)
            {
                VisitChildren(cur);
            }
            else if (!ps.is_list)
            {
                ps.field.SetValue(ps.parent, proposed);
            }
            else if (ps.is_list)
            {
                IList thelist = (IList)ps.field.GetValue(ps.parent);
                thelist[ps.pos] = proposed;
            }
        }