Пример #1
0
        // <summary>
        // Common copy path for all SetOps
        // </summary>
        // <param name="op"> The SetOp to Copy (must be one of ExceptOp, IntersectOp, UnionAllOp) </param>
        // <param name="n"> The Node that references the Op </param>
        // <returns> A copy of the original Node that references a copy of the original Op </returns>
        private Node CopySetOp(SetOp op, Node n)
        {
            // Visit the Node's children and map their Vars
            var children = ProcessChildren(n);

            var leftMap  = new VarMap();
            var rightMap = new VarMap();

            foreach (var kv in op.VarMap[0])
            {
                // Create a new output Var that is a copy of the original output Var
                Var outputVar = m_destCmd.CreateSetOpVar(kv.Key.Type);

                // Add a mapping for the new output var we've just created
                SetMappedVar(kv.Key, outputVar);

                // Add this output var's entries to the new VarMaps
                leftMap.Add(outputVar, GetMappedVar(kv.Value));
                rightMap.Add(outputVar, GetMappedVar((op.VarMap[1])[kv.Key]));
            }

            SetOp newSetOp = null;

            switch (op.OpType)
            {
            case OpType.UnionAll:
            {
                var branchDiscriminator = ((UnionAllOp)op).BranchDiscriminator;
                if (null != branchDiscriminator)
                {
                    branchDiscriminator = GetMappedVar(branchDiscriminator);
                }
                newSetOp = m_destCmd.CreateUnionAllOp(leftMap, rightMap, branchDiscriminator);
            }
            break;

            case OpType.Intersect:
            {
                newSetOp = m_destCmd.CreateIntersectOp(leftMap, rightMap);
            }
            break;

            case OpType.Except:
            {
                newSetOp = m_destCmd.CreateExceptOp(leftMap, rightMap);
            }
            break;

            default:
            {
                Debug.Assert(false, "Unexpected SetOpType");
            }
            break;
            }

            return(m_destCmd.CreateNode(newSetOp, children));
        }