internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
     if (op == Operators.None) {
         return ag.AddDebugInfoAndVoid(
             Binders.Set(
                 ag.BinderState,
                 typeof(object),
                 SymbolTable.IdToString(_name),
                 ag.Transform(_target),
                 right
             ),
             span
         );
     } else {
         MSAst.ParameterExpression temp = ag.GetTemporary("inplace");
         return ag.AddDebugInfo(
             Ast.Block(
                 Ast.Assign(temp, ag.Transform(_target)),
                 SetMemberOperator(ag, right, op, temp),
                 Ast.Empty()
             ),
             Span.Start,
             span.End
         );
     }
 }
        internal override MSAst.Expression Transform(AstGenerator ag) {
            ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();

            for (int i = 0; i < _names.Length; i++) {
                statements.Add(
                    // _references[i] = PythonOps.Import(<code context>, _names[i])
                    ag.AddDebugInfoAndVoid(
                        GlobalAllocator.Assign(
                            ag.Globals.GetVariable(ag, _variables[i]), 
                            Ast.Call(
                                AstGenerator.GetHelperMethod(                           // helper
                                    _asNames[i] == null ? "ImportTop" : "ImportBottom"
                                ),
                                ag.LocalContext,                                        // 1st arg - code context
                                AstUtils.Constant(_names[i].MakeString()),                   // 2nd arg - module name
                                AstUtils.Constant(_forceAbsolute ? 0 : -1)                   // 3rd arg - absolute or relative imports
                            )
                        ),
                        _names[i].Span
                    )
                );
            }

            statements.Add(AstUtils.Empty());
            return ag.AddDebugInfo(Ast.Block(statements.ToReadOnlyCollection()), Span);
        }
Exemple #3
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.Expression result;

            if (_else != null) {
                result = ag.Transform(_else);
            } else {
                result = AstUtils.Empty();
            }

            // Now build from the inside out
            int i = _tests.Length;
            while (i-- > 0) {
                IfStatementTest ist = _tests[i];

                result = ag.AddDebugInfoAndVoid(
                    Ast.Condition(
                        ag.TransformAndDynamicConvert(ist.Test, typeof(bool)),
                        ag.TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start), 
                        result
                    ),
                    new SourceSpan(ist.Start, ist.Header)
                );
            }

            return result;
        }
 internal override MSAst.Expression Transform(AstGenerator ag, MSAst.Expression body) {
     return ag.AddDebugInfoAndVoid(
         AstUtils.If(
             ag.TransformAndDynamicConvert(_test, typeof(bool)),
             body
         ),
         Span
     );
 }
        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.Expression expression = ag.Transform(_expression);

            if (ag.PrintExpressions) {
                expression = Ast.Call(
                    AstGenerator.GetHelperMethod("PrintExpressionValue"),
                    ag.LocalContext,
                    AstGenerator.ConvertIfNeeded(expression, typeof(object))
                );
            }

            return ag.AddDebugInfoAndVoid(expression, _expression.Span);
        }
Exemple #6
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            // Only the body is "in the loop" for the purposes of break/continue
            // The "else" clause is outside
            MSAst.LabelTarget breakLabel, continueLabel;

            ConstantExpression constTest = _test as ConstantExpression;
            if (constTest != null && constTest.Value is int) {
                // while 0: / while 1:
                int val = (int)constTest.Value;
                if (val == 0) {
                    // completely optimize the loop away
                    if (_else == null) {
                        return MSAst.Expression.Empty();
                    } else {
                        return ag.Transform(_else);
                    }
                }

                MSAst.Expression test = MSAst.Expression.Constant(true);
                MSAst.Expression res = AstUtils.While(
                    test,
                    ag.TransformLoopBody(_body, SourceLocation.Invalid, out breakLabel, out continueLabel),
                    ag.Transform(_else),
                    breakLabel,
                    continueLabel
                );

                if (_test.Start.Line != _body.Start.Line) {
                    res = ag.AddDebugInfoAndVoid(res, _test.Span);
                }

                return res;
            }

            return AstUtils.While(
                ag.AddDebugInfo(
                    ag.TransformAndDynamicConvert(_test, typeof(bool)),
                    Header
                ),
                ag.TransformLoopBody(_body, _test.Start, out breakLabel, out continueLabel), 
                ag.Transform(_else),
                breakLabel,
                continueLabel
            );
        }
Exemple #7
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            // If debugging is off, return empty statement
            if (ag.Optimize) {
                return AstUtils.Empty();
            }

            // Transform into:
            // if (_test) {
            // } else {
            //     RaiseAssertionError(_message);
            // }
            return ag.AddDebugInfoAndVoid(
                AstUtils.Unless(                                 // if
                    ag.TransformAndDynamicConvert(_test, typeof(bool)), // _test
                    Ast.Call(                                           // else branch
                        AstGenerator.GetHelperMethod("RaiseAssertionError"),
                        ag.TransformOrConstantNull(_message, typeof(object))
                    )
                ),
                Span
            );
        }
 internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
     if (op == PythonOperationKind.None) {
         return ag.AddDebugInfoAndVoid(
             ag.Set(
                 typeof(object),
                 _name,
                 ag.Transform(_target),
                 right
             ),
             span
         );
     } else {
         MSAst.ParameterExpression temp = ag.GetTemporary("inplace");
         return ag.AddDebugInfo(
             Ast.Block(
                 Ast.Assign(temp, ag.Transform(_target)),
                 SetMemberOperator(ag, right, op, temp),
                 AstUtils.Empty()
             ),
             Span.Start,
             span.End
         );
     }
 }
Exemple #9
0
        /// <summary>
        /// WithStatement is translated to the DLR AST equivalent to
        /// the following Python code snippet (from with statement spec):
        /// 
        /// mgr = (EXPR)
        /// exit = mgr.__exit__  # Not calling it yet
        /// value = mgr.__enter__()
        /// exc = True
        /// try:
        ///     VAR = value  # Only if "as VAR" is present
        ///     BLOCK
        /// except:
        ///     # The exceptional case is handled here
        ///     exc = False
        ///     if not exit(*sys.exc_info()):
        ///         raise
        ///     # The exception is swallowed if exit() returns true
        /// finally:
        ///     # The normal and non-local-goto cases are handled here
        ///     if exc:
        ///         exit(None, None, None)
        /// 
        /// </summary>
        internal override MSAst.Expression Transform(AstGenerator ag) {            
            MSAst.ParameterExpression lineUpdated = ag.GetTemporary("$lineUpdated_with", typeof(bool));
            // Five statements in the result...
            ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>(6);
            

            //******************************************************************
            // 1. mgr = (EXPR)
            //******************************************************************
            MSAst.ParameterExpression manager = ag.GetTemporary("with_manager");
            statements.Add(
                ag.MakeAssignment(
                    manager,
                    ag.Transform(_contextManager),
                    new SourceSpan(Start, _header)
                )
            );

            //******************************************************************
            // 2. exit = mgr.__exit__  # Not calling it yet
            //******************************************************************
            MSAst.ParameterExpression exit = ag.GetTemporary("with_exit");
            statements.Add(
                AstGenerator.MakeAssignment(
                    exit,
                    ag.Get(
                        typeof(object),
                        "__exit__",
                        manager
                    )
                )
            );

            //******************************************************************
            // 3. value = mgr.__enter__()
            //******************************************************************
            MSAst.ParameterExpression value = ag.GetTemporary("with_value");
            statements.Add(
                ag.AddDebugInfoAndVoid(
                    AstGenerator.MakeAssignment(
                        value,
                        ag.Invoke(
                            typeof(object),
                            new CallSignature(0),
                            ag.Get(
                                typeof(object),
                                "__enter__",
                                manager
                            )
                        )
                    ),
                    new SourceSpan(Start, _header)
                )
            );

            //******************************************************************
            // 4. exc = True
            //******************************************************************
            MSAst.ParameterExpression exc = ag.GetTemporary("with_exc", typeof(bool));
            statements.Add(
                AstGenerator.MakeAssignment(
                    exc,
                    AstUtils.Constant(true)
                )
            );

            //******************************************************************
            //  5. The final try statement:
            //
            //  try:
            //      VAR = value  # Only if "as VAR" is present
            //      BLOCK
            //  except:
            //      # The exceptional case is handled here
            //      exc = False
            //      if not exit(*sys.exc_info()):
            //          raise
            //      # The exception is swallowed if exit() returns true
            //  finally:
            //      # The normal and non-local-goto cases are handled here
            //      if exc:
            //          exit(None, None, None)
            //******************************************************************

            MSAst.ParameterExpression exception = ag.GetTemporary("exception", typeof(Exception));
            MSAst.ParameterExpression nestedFrames = ag.GetTemporary("$nestedFrames", typeof(List<DynamicStackFrame>));
            statements.Add(
                // try:
                AstUtils.Try(
                    AstUtils.Try(// try statement body
                        ag.PushLineUpdated(false, lineUpdated),
                        _var != null ?
                            Ast.Block(
                                // VAR = value
                                _var.TransformSet(ag, SourceSpan.None, value, PythonOperationKind.None),
                                // BLOCK
                                ag.Transform(_body),
                                AstUtils.Empty()
                            ) :
                            // BLOCK
                            ag.Transform(_body) // except:, // try statement location
                    ).Catch(exception,
                    // Python specific exception handling code
                        TryStatement.GetTracebackHeader(                        
                            ag,
                            exception,
                            ag.AddDebugInfoAndVoid(
                                Ast.Block(
                                    // exc = False
                                    AstGenerator.MakeAssignment(
                                        exc,
                                        AstUtils.Constant(false)
                                    ),
                                    Ast.Assign(
                                        nestedFrames,
                                        Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
                                    ),
                                    //  if not exit(*sys.exc_info()):
                                    //      raise
                                    AstUtils.IfThen(
                                        ag.Convert(
                                            typeof(bool),
                                            ConversionResultKind.ExplicitCast,
                                            ag.Operation(
                                                typeof(bool),
                                                PythonOperationKind.Not,
                                                MakeExitCall(ag, exit, exception)
                                            )
                                        ),
                                        ag.UpdateLineUpdated(true),
                                        Ast.Call(
                                            AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
                                            nestedFrames
                                        ),
                                        Ast.Throw(
                                            Ast.Call(
                                                AstGenerator.GetHelperMethod("MakeRethrowExceptionWorker"),
                                                exception
                                            )
                                        )
                                    )
                                ),
                                _body.Span
                            )
                        ),
                        Ast.Call(
                            AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
                            nestedFrames
                        ),
                        ag.PopLineUpdated(lineUpdated),
                        Ast.Empty()
                    )
                // finally:                    
                ).Finally(
                //  if exc:
                //      exit(None, None, None)
                    AstUtils.IfThen(
                        exc,
                        ag.AddDebugInfoAndVoid(
                            Ast.Block(
                                Ast.Dynamic(
                                    ag.PyContext.Invoke(
                                        new CallSignature(3)        // signature doesn't include function
                                    ),
                                    typeof(object),
                                    new MSAst.Expression[] {
                                        ag.LocalContext,
                                        exit,
                                        AstUtils.Constant(null),
                                        AstUtils.Constant(null),
                                        AstUtils.Constant(null)
                                    }
                                ),                                    
                                Ast.Empty()
                            ),
                            _contextManager.Span
                        )
                    )
                )
            );

            statements.Add(AstUtils.Empty());
            return Ast.Block(statements.ToReadOnlyCollection());
        }
Exemple #10
0
 internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
     if (op != Operators.None) {
         right = Binders.Operation(
             ag.BinderState,
             typeof(object),
             StandardOperators.FromOperator(op),
             Binders.Operation(
                 ag.BinderState,
                 typeof(object),
                 GetOperatorString,
                 ArrayUtils.RemoveFirst(GetActionArgumentsForGetOrDelete(ag))
             ),
             right
         );                
     }
     
     return ag.AddDebugInfoAndVoid(
         Binders.Operation(
             ag.BinderState,
             typeof(object),
             SetOperatorString,
             ArrayUtils.RemoveFirst(GetActionArgumentsForSet(ag, right))
         ),
         Span
     );
 }
        private MSAst.Expression AssignComplex(AstGenerator ag, MSAst.Expression right) {
            // Python assignment semantics:
            // - only evaluate RHS once. 
            // - evaluates assignment from left to right
            // - does not evaluate getters.
            // 
            // So 
            //   a=b[c]=d=f() 
            // should be:
            //   $temp = f()
            //   a = $temp
            //   b[c] = $temp
            //   d = $temp

            List<MSAst.Expression> statements = new List<MSAst.Expression>();

            // 1. Create temp variable for the right value
            MSAst.ParameterExpression right_temp = ag.GetTemporary("assignment");

            // 2. right_temp = right
            statements.Add(
                AstGenerator.MakeAssignment(right_temp, right)
                );

            // Do left to right assignment
            foreach (Expression e in _left) {
                if (e == null) {
                    continue;
                }

                // 3. e = right_temp
                MSAst.Expression transformed = e.TransformSet(ag, Span, right_temp, PythonOperationKind.None);

                statements.Add(transformed);
            }

            // 4. Create and return the resulting suite
            statements.Add(AstUtils.Empty());
            return ag.AddDebugInfoAndVoid(
                Ast.Block(statements.ToArray()),
                Span
            );
        }
Exemple #12
0
        internal override MSAst.Expression Transform(AstGenerator ag) {
            string className = _name;
            AstGenerator classGen = new AstGenerator(ag, className, false, "class " + className);
            classGen.Parameter(_parentContextParam);
            // we always need to create a nested context for class defs
            classGen.CreateNestedContext();

            List<MSAst.Expression> init = new List<MSAst.Expression>();
            
            classGen.AddHiddenVariable(ArrayGlobalAllocator._globalContext);
            init.Add(Ast.Assign(ArrayGlobalAllocator._globalContext, Ast.Call(typeof(PythonOps).GetMethod("GetGlobalContext"), _parentContextParam)));
            init.AddRange(classGen.Globals.PrepareScope(classGen));

            CreateVariables(classGen, _parentContextParam, init, true, false);

            List<MSAst.Expression> statements = new List<MSAst.Expression>();
            // Create the body
            MSAst.Expression bodyStmt = classGen.Transform(_body);
            
            // __module__ = __name__
            MSAst.Expression modStmt = GlobalAllocator.Assign(
                classGen.Globals.GetVariable(classGen, _modVariable), 
                classGen.Globals.GetVariable(classGen, _modNameVariable));

            string doc = classGen.GetDocumentation(_body);
            if (doc != null) {
                statements.Add(
                    GlobalAllocator.Assign(
                        classGen.Globals.GetVariable(classGen, _docVariable),
                        AstUtils.Constant(doc)
                    )
                );
            }

            FunctionCode funcCodeObj = new FunctionCode(
                ag.PyContext,
                null,
                null,
                Name,
                ag.GetDocumentation(_body),
                ArrayUtils.EmptyStrings,
                FunctionAttributes.None,
                Span,
                ag.Context.SourceUnit.Path,
                ag.EmitDebugSymbols,
                ag.ShouldInterpret,
                FreeVariables,
                GlobalVariables,
                CellVariables,
                AppendVariables(new List<string>()),
                Variables == null ? 0 : Variables.Count,
                classGen.LoopLocationsNoCreate,
                classGen.HandlerLocationsNoCreate
            );
            MSAst.Expression funcCode = classGen.Globals.GetConstant(funcCodeObj);
            classGen.FuncCodeExpr = funcCode;

            if (_body.CanThrow && ag.PyContext.PythonOptions.Frames) {
                bodyStmt = AstGenerator.AddFrame(classGen.LocalContext, funcCode, bodyStmt);
                classGen.AddHiddenVariable(AstGenerator._functionStack);
            }

            bodyStmt = classGen.WrapScopeStatements(
                Ast.Block(
                    statements.Count == 0 ?
                        AstGenerator.EmptyBlock :
                        Ast.Block(new ReadOnlyCollection<MSAst.Expression>(statements)),
                    modStmt,
                    bodyStmt,
                    classGen.LocalContext    // return value
                )
            );

            var lambda = Ast.Lambda<Func<CodeContext, CodeContext>>(
                classGen.MakeBody(_parentContextParam, init.ToArray(), bodyStmt),
                classGen.Name + "$" + _classId++,
                classGen.Parameters
            );
            
            funcCodeObj.Code = lambda;

            MSAst.Expression classDef = Ast.Call(
                AstGenerator.GetHelperMethod("MakeClass"),
                ag.EmitDebugSymbols ? 
                    (MSAst.Expression)lambda : 
                    Ast.Convert(funcCode, typeof(object)),
                ag.LocalContext,
                AstUtils.Constant(_name),
                Ast.NewArrayInit(
                    typeof(object),
                    ag.TransformAndConvert(_bases, typeof(object))
                ),
                AstUtils.Constant(FindSelfNames())
            );

            classDef = ag.AddDecorators(classDef, _decorators);

            return ag.AddDebugInfoAndVoid(GlobalAllocator.Assign(ag.Globals.GetVariable(ag, _variable), classDef), new SourceSpan(Start, Header));
        }
Exemple #13
0
 internal override MSAst.Expression TransformDelete(AstGenerator ag) {
     return ag.AddDebugInfoAndVoid(
         Binders.Operation(
             ag.BinderState,
             typeof(object),
             DeleteOperatorString,
             ArrayUtils.RemoveFirst(GetActionArgumentsForGetOrDelete(ag))
         ),
         Span
     );
 }
Exemple #14
0
        internal override MSAst.Expression TransformDelete(AstGenerator ag) {
            MSAst.Expression index;
            if (IsSlice) {
                index = ag.DeleteSlice(typeof(object), GetActionArgumentsForGetOrDelete(ag));
            } else {
                index = ag.DeleteIndex(typeof(void), GetActionArgumentsForGetOrDelete(ag));
            }

            return ag.AddDebugInfoAndVoid(index, Span);
        }
        internal override MSAst.Expression Transform(AstGenerator ag) {
            Debug.Assert(_variable != null, "Shouldn't be called by lambda expression");

            MSAst.Expression function = TransformToFunctionExpression(ag);
            return ag.AddDebugInfoAndVoid(GlobalAllocator.Assign(ag.Globals.GetVariable(ag, _variable), function), new SourceSpan(Start, Header));
        }
Exemple #16
0
        internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
            MSAst.Expression assignment;

            if (op != PythonOperationKind.None) {
                right = ag.Operation(
                    typeof(object),
                    op,
                    Transform(ag, typeof(object)),
                    right
                );
            }

            if (_reference.PythonVariable != null) {
                assignment = ag.Globals.Assign(
                    ag.Globals.GetVariable(_reference.PythonVariable), 
                    AstGenerator.ConvertIfNeeded(right, typeof(object))
                );
            } else {
                assignment = Ast.Call(
                    null,
                    typeof(ScriptingRuntimeHelpers).GetMethod("SetName"),
                    new [] {
                        ag.LocalContext, 
                        ag.Globals.GetSymbol(_name),
                        AstUtils.Convert(right, typeof(object))
                        }
                );
            }

            SourceSpan aspan = span.IsValid ? new SourceSpan(Span.Start, span.End) : SourceSpan.None;
            return ag.AddDebugInfoAndVoid(assignment, aspan);
        }
Exemple #17
0
        internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
            if (op != PythonOperationKind.None) {
                right = ag.Operation(
                    typeof(object),
                    op,
                    Transform(ag, typeof(object)),
                    right
                );                
            }

            MSAst.Expression index;
            if (IsSlice) {
                index = ag.SetSlice(typeof(object), GetActionArgumentsForSet(ag, right));
            } else {
                index = ag.SetIndex(typeof(object), GetActionArgumentsForSet(ag, right));
            }
            
            return ag.AddDebugInfoAndVoid(index, Span);
        }
        private MSAst.Expression AssignOne(AstGenerator ag) {
            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 = ag.Transform(seRight.Items[i]);
                    tmps[i] = ag.GetTemporary("parallelAssign", tmpVal.Type);

                    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(ag, SourceSpan.None, tmps[i], PythonOperationKind.None);
                }

                // finally free the temps.
                foreach (MSAst.ParameterExpression variable in tmps) {
                    ag.FreeTemp(variable);
                }

                // 4. Create and return the resulting suite
                body[cnt * 2] = AstUtils.Empty();
                return ag.AddDebugInfoAndVoid(Ast.Block(body), Span);
            }

            return _left[0].TransformSet(ag, Span, ag.Transform(_right), PythonOperationKind.None);
        }
        internal override MSAst.Expression Transform(AstGenerator ag) {            
            if (_names == _star) {
                // from a[.b] import *
                return ag.AddDebugInfo(
                    Ast.Call(
                        AstGenerator.GetHelperMethod("ImportStar"),
                        ag.LocalContext, 
                        AstUtils.Constant(_root.MakeString()), 
                        AstUtils.Constant(GetLevel())
                    ),
                    Span
                );
            } else {
                // from a[.b] import x [as xx], [ y [ as yy] ] [ , ... ]

                ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();
                MSAst.ParameterExpression module = ag.GetTemporary("module");

                // Create initializer of the array of names being passed to ImportWithNames
                MSAst.Expression[] names = new MSAst.Expression[_names.Length];
                for (int i = 0; i < names.Length; i++) {
                    names[i] = AstUtils.Constant(_names[i]);
                }

                // module = PythonOps.ImportWithNames(<context>, _root, make_array(_names))
                statements.Add(
                    ag.AddDebugInfoAndVoid(
                        GlobalAllocator.Assign(
                            module, 
                            Ast.Call(
                                AstGenerator.GetHelperMethod("ImportWithNames"),
                                ag.LocalContext,
                                AstUtils.Constant(_root.MakeString()),
                                Ast.NewArrayInit(typeof(string), names),
                                AstUtils.Constant(GetLevel())
                            )
                        ),
                        _root.Span
                    )
                );

                // now load all the names being imported and assign the variables
                for (int i = 0; i < names.Length; i++) {
                    statements.Add(
                        ag.AddDebugInfoAndVoid(
                            GlobalAllocator.Assign(
                                ag.Globals.GetVariable(ag, _variables[i]), 
                                Ast.Call(
                                    AstGenerator.GetHelperMethod("ImportFrom"),
                                    ag.LocalContext,
                                    module,
                                    names[i]
                                )
                            ),
                            Span
                        )
                    );
                }

                statements.Add(AstUtils.Empty());
                return ag.AddDebugInfo(Ast.Block(statements.ToArray()), Span);
            }
        }
Exemple #20
0
        internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
            MSAst.Expression variable = _reference.Variable;
            MSAst.Expression assignment;

            Type vt = variable != null ? variable.Type : typeof(object);

            if (op != Operators.None) {
                right = Binders.Operation(
                    ag.BinderState,
                    vt,
                    StandardOperators.FromOperator(op),
                    Transform(ag, vt),
                    right
                );
            }

            if (variable != null) {
                assignment = AstUtils.Assign(variable, AstGenerator.ConvertIfNeeded(right, variable.Type));
            } else {
                assignment = AstUtils.Assign(_name, right);
            }

            SourceSpan aspan = span.IsValid ? new SourceSpan(Span.Start, span.End) : SourceSpan.None;
            return ag.AddDebugInfoAndVoid(assignment, aspan);
        }