Exemplo n.º 1
0
        public static void Walk <T>(ref T node, AstVisitor prefix, AstVisitor postfix) where T : IAst
        {
            IAst first  = node;
            IAst second = node;

            if (first == null)
            {
                return;
            }

            if (prefix(ref first))
            {
                first.Walk(prefix, postfix);
            }
            if (second.Equals(first))
            {
                postfix(ref first);
            }
            if (second.Equals(first))
            {
                return;
            }

            if (!ReferenceEquals(first, null))
            {
                if (!(first is T))
                {
                    throw new Exception(
                              string.Format(
                                  "Node replaced not of the correct type {0}.",
                                  typeof(T).Name));
                }
                LinkParents.Link(first);
                first.ParentAst = node.ParentAst;
            }

            node = (T)first;
        }