/// <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 List <Node> children = ProcessChildren(n); VarMap leftMap = new VarMap(); VarMap rightMap = new VarMap(); foreach (KeyValuePair <Var, 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)); }
/// <summary> /// Set the "cloned" var for a given Var /// WARNING: If a mapping already exists, an exception is raised /// </summary> /// <param name="v">The original Var</param> /// <param name="mappedVar">The cloned Var</param> private void SetMappedVar(Var v, Var mappedVar) { m_varMap.Add(v, mappedVar); }