IronPython.Compiler.Ast.AssignmentStatement.AssignOne C# (CSharp) Method

AssignOne() private method

private AssignOne ( ) : Expression
return System.Linq.Expressions.Expression
        private MSAst.Expression AssignOne() {
            Debug.Assert(_left.Length == 1);

            SequenceExpression seLeft = _left[0] as SequenceExpression;
            SequenceExpression seRight = _right as SequenceExpression;

            if (seLeft != null && seRight != null && seLeft.Items.Count == seRight.Items.Count) {
                int cnt = seLeft.Items.Count;
                
                // a, b = 1, 2, or [a,b] = 1,2 - not something like a, b = range(2)
                // we can do a fast parallel assignment
                MSAst.ParameterExpression[] tmps = new MSAst.ParameterExpression[cnt];
                MSAst.Expression[] body = new MSAst.Expression[cnt * 2 + 1];

                // generate the body, the 1st n are the temporary assigns, the
                // last n are the assignments to the left hand side
                // 0: tmp0 = right[0]
                // ...
                // n-1: tmpn-1 = right[n-1]
                // n: right[0] = tmp0
                // ...
                // n+n-1: right[n-1] = tmpn-1

                // allocate the temps first before transforming so we don't pick up a bad temp...
                for (int i = 0; i < cnt; i++) {
                    MSAst.Expression tmpVal = seRight.Items[i];
                    tmps[i] = Ast.Variable(tmpVal.Type, "parallelAssign");

                    body[i] = Ast.Assign(tmps[i], tmpVal);
                }

                // then transform which can allocate more temps
                for (int i = 0; i < cnt; i++) {
                    body[i + cnt] = seLeft.Items[i].TransformSet(SourceSpan.None, tmps[i], PythonOperationKind.None);
                }
                
                // 4. Create and return the resulting suite
                body[cnt * 2] = AstUtils.Empty();
                return GlobalParent.AddDebugInfoAndVoid(Ast.Block(tmps, body), Span);
            }

            return _left[0].TransformSet(Span, _right, PythonOperationKind.None);
        }