Example #1
0
        protected void VisitAndXform(IAstTreeNode node, IAstTreeNode xform)
        {
            if (xform != null)
            {
                var parent = node.Parent;
                node.DetachFromParent();
                xform.AttachToParent(parent);

                // TODO. Introduce something more elegant here

                // The following line is necessary since node being replaced by xform can
                // also affect parent nodes, say, we had the following fragment in an xformer
                // that includes arity simplifier.
                // 
                // Original tree =  Or -> And + And
                //
                // After some xform one of Ands suddenly gets replaced by an Or. So if we 
                // short-mindedly assume that xform only affected the node being processed, we're
                // gonna fail, since Or -> Or + And has to be xformed to Or -> And.
                //
                // If you still aint here, uncomment a line below and run Sandbox::Program::MainestMain

//                throw new RestartTraversalException(xform);

                var topAffectedNode = xform.Parent is L1Expression ? xform : xform.Parent;
                throw new RestartTraversalException(topAffectedNode);
            }
        }