当前位置: 首页>>代码示例>>C#>>正文


C# ReadOnlyCollectionBuilder.ToReadOnlyCollection方法代码示例

本文整理汇总了C#中ReadOnlyCollectionBuilder.ToReadOnlyCollection方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyCollectionBuilder.ToReadOnlyCollection方法的具体用法?C# ReadOnlyCollectionBuilder.ToReadOnlyCollection怎么用?C# ReadOnlyCollectionBuilder.ToReadOnlyCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReadOnlyCollectionBuilder的用法示例。


在下文中一共展示了ReadOnlyCollectionBuilder.ToReadOnlyCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reduce

        public override MSAst.Expression Reduce() {
            if (_statements.Length == 0) {
                return GlobalParent.AddDebugInfoAndVoid(AstUtils.Empty(), Span);
            }

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

            int curStart = -1;
            foreach (var statement in _statements) {
                // CPython debugging treats multiple statements on the same line as a single step, we
                // match that behavior here.
                if (statement.Start.Line == curStart) {
                    statements.Add(new DebugInfoRemovalExpression(statement, curStart));
                } else {
                    if (statement.CanThrow && statement.Start.IsValid) {
                        statements.Add(UpdateLineNumber(statement.Start.Line));
                    }

                    statements.Add(statement);
                }
                curStart = statement.Start.Line;
            }
            
            return Ast.Block(statements.ToReadOnlyCollection());
        }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:25,代码来源:SuiteStatement.cs

示例2: Reduce

        public override System.Linq.Expressions.Expression Reduce()
        {
            if (_statements.Length == 0)
                return GlobalParent.AddDebugInfoAndVoid(Utils.Empty(), Span);

            ReadOnlyCollectionBuilder<ParameterExpression> locals = new ReadOnlyCollectionBuilder<ParameterExpression>();
            List<Expression> init = new List<Expression>();

            init.Add(Expression.ClearDebugInfo(GlobalParent.Document));

            CreateVariables(locals, init);

            foreach (var statement in _statements)
            {
                int newline = GlobalParent.IndexToLocation(statement.StartIndex).Line;
                if (statement.CanThrow && newline != -1)
                    init.Add(UpdateLineNumber(newline));

                init.Add(statement);
            }

            return GlobalParent.AddDebugInfoAndVoid(
                Expression.Block(
                    locals.ToReadOnlyCollection(),
                    init
                ),
                Span
            );
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:29,代码来源:BlockStmt.cs

示例3: TotemArgs

        public TotemArgs(TotemContext context, string[] names, IList<object> args, Dictionary<string, object> kwargs)
            : base(context.GetType<Types.Arguments>())
        {
            _names = new ReadOnlyCollectionBuilder<string>(names).ToReadOnlyCollection();
            var vb = new ReadOnlyCollectionBuilder<object>();
            var nvb = new Dictionary<string, object>();
            var snb = new ReadOnlyCollectionBuilder<string>();

            for (var i = 0; i < args.Count; i++)
            {
                vb.Add(args[i]);
                if (i < names.Length)
                    nvb.Add(names[i], args[i]);
            }

            foreach (var arg in kwargs)
            {
                nvb.Add(arg.Key, arg.Value);
                snb.Add(arg.Key);
            }

            _values = vb.ToReadOnlyCollection();
            _namedValues = new ReadOnlyDictionary<string, object>(nvb);
            _named = snb.ToReadOnlyCollection();
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:25,代码来源:TotemArgs.cs

示例4: Transform

        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);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:26,代码来源:ImportStatement.cs

示例5: Reduce

        public override MSAst.Expression Reduce() {
            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])
                    GlobalParent.AddDebugInfoAndVoid(
                        AssignValue(
                            Parent.GetVariableExpression(_variables[i]),
                            LightExceptions.CheckAndThrow(
                                Expression.Call(
                                    _asNames[i] == null ? AstMethods.ImportTop : AstMethods.ImportBottom,
                                    Parent.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 GlobalParent.AddDebugInfo(Ast.Block(statements.ToReadOnlyCollection()), Span);
        }
开发者ID:jschementi,项目名称:iron,代码行数:26,代码来源:ImportStatement.cs

示例6: Reduce

        public override System.Linq.Expressions.Expression Reduce()
        {
            if (_statements.Length == 0)
                return GlobalParent.AddDebugInfoAndVoid(AstUtils.Empty(), Span);

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

            foreach (var stmt in _statements)
            {
                var line = GlobalParent.IndexToLocation(stmt.StartIndex).Line;
                if (stmt.CanThrow && line != -1)
                {
                    statements.Add(UpdateLineNumber(line));
                }

                statements.Add(stmt);
            }

            return Ast.Block(statements.ToReadOnlyCollection());
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:20,代码来源:SuiteStatement.cs

示例7: FinishBind

        internal override void FinishBind(TotemNameBinder binder)
        {
            if (_freeVars != null && _freeVars.Count > 0)
            {
                ReadOnlyCollectionBuilder<TotemVariable> closureVariables = new ReadOnlyCollectionBuilder<TotemVariable>();
                _closureType = MutableTuple.MakeTupleType(_freeVars.Select(v => typeof(ClosureCell)).ToArray());
                _localClosureTuple = Expression.Parameter(_closureType, "$closure");
                for (var i = 0; i < _freeVars.Count; i++)
                {
                    var variable = _freeVars[i];
                    _variableMapping[variable] = new ClosureExpression(variable, Expression.Property(_localClosureTuple, String.Format("Item{0:D3}", i)), null);
                    closureVariables.Add(variable);
                }
                _closureVariables = closureVariables.ToReadOnlyCollection();
            }

            if (_scopeVars != null)
                foreach (var local in _scopeVars)
                {
                    if (local.Kind == VariableKind.Parameter) // handled in subclass
                        continue;

                    // scope variables, defined in this scope
                    Debug.Assert(local.Kind == VariableKind.Local);
                    Debug.Assert(local.Scope == this);

                    if (local.AccessedInNestedScope)
                    {
                        // Closure variable
                        _variableMapping[local] = new ClosureExpression(local, Expression.Parameter(typeof(ClosureCell), local.Name), null);
                    }
                    else
                    {
                        // Not used in nested function-scopes
                        _variableMapping[local] = Expression.Parameter(typeof(object), local.Name);
                    }
                }
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:38,代码来源:CompilableStmt.cs

示例8: CreateFunctionLambda

        private LightLambdaExpression CreateFunctionLambda()
        {
            bool needsWrapperMethod = _parameters.Length > TotemCallTargets.MAX_ARGS;
            Delegate originalDelegate;
            Type delegateType = GetDelegateType(_parameters, needsWrapperMethod, out originalDelegate);

            ReadOnlyCollectionBuilder<ParameterExpression> locals = new ReadOnlyCollectionBuilder<ParameterExpression>();

            ParameterExpression[] parameters = CreateParameters(needsWrapperMethod, locals);

            List<Expression> init = new List<Expression>();
            foreach (var param in _parameters)
            {
                ITotemVariableExpression toVar = GetVariableExpression(param.TotemVariable) as ITotemVariableExpression;
                if (toVar != null)
                {
                    var varInit = toVar.Create();
                    if (varInit != null)
                        init.Add(varInit);
                }
            }

            // Transform the parameters.
            init.Add(Expression.ClearDebugInfo(GlobalParent.Document));

            locals.Add(TotemAst._globalContext);
            init.Add(Expression.Assign(TotemAst._globalContext, new GetGlobalContextExpression(_parentContext)));
            if (IsClosure)
            {
                locals.Add(LocalClosureTuple);
                init.Add(
                    Expression.Assign(
                        LocalClosureTuple,
                        Utils.Convert(
                            _localClosure,
                            LocalClosureTupleType
                        )
                    )
                );
            }

            GlobalParent.PrepareScope(locals, init);

            // Create variables and references. Since references refer to
            // parameters, do this after parameters have been created.

            CreateFunctionVariables(locals, init);

            // Initialize parameters - unpack tuples.
            // Since tuples unpack into locals, this must be done after locals have been created.
            InitializeParameters(init, needsWrapperMethod, parameters);

            List<Expression> statements = new List<Expression>();
            // Add beginning sequence point
            var start = GlobalParent.IndexToLocation(StartIndex);
            statements.Add(
                GlobalParent.AddDebugInfo(
                    Utils.Empty(),
                    new SourceSpan(
                        new SourceLocation(0, start.Line, start.Column),
                        new SourceLocation(0, start.Line, Int32.MaxValue)
                    )
                )
            );

            // For generators, we need to do a check before the first statement for Generator.Throw / Generator.Close.
            // The exception traceback needs to come from the generator's method body, and so we must do the check and throw
            // from inside the generator.
            if (IsGenerator)
            {
                //Expression s1 = YieldExpr.CreateCheckThrowExpression(SourceSpan.None);
                //statements.Add(s1);
                throw new NotImplementedException("Generators");
            }

            if (_body.CanThrow && !(_body is BlockStmt) && _body.StartIndex != -1)
            {
                statements.Add(
                    UpdateLineNumber(
                        GlobalParent.IndexToLocation(_body.StartIndex).Line
                    )
                );
            }

            statements.Add(Body);
            Expression body = Expression.Block(statements);

            body = AddProfiling(body);
            body = WrapScopeStatements(body, _body.CanThrow);
            body = Expression.Block(body, Utils.Empty());
            body = AddReturnTarget(body);

            Expression bodyStmt = body;
            init.Add(bodyStmt);
            bodyStmt = Expression.Block(init);

            // wrap a scope if needed
            bodyStmt = Expression.Block(locals.ToReadOnlyCollection(), bodyStmt);

            return Utils.LightLambda(
//.........这里部分代码省略.........
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:101,代码来源:FunctionDefinition.cs

示例9: CreateFunctionLambda


//.........这里部分代码省略.........
            // Create variables and references. Since references refer to
            // parameters, do this after parameters have been created.

            CreateFunctionVariables(locals, init);

            // Initialize parameters - unpack tuples.
            // Since tuples unpack into locals, this must be done after locals have been created.
            InitializeParameters(init, needsWrapperMethod, parameters);

            List<MSAst.Expression> statements = new List<MSAst.Expression>();
            // add beginning sequence point
            statements.Add(GlobalParent.AddDebugInfo(
                AstUtils.Empty(),
                new SourceSpan(new SourceLocation(0, Start.Line, Start.Column), new SourceLocation(0, Start.Line, Int32.MaxValue))));


            // For generators, we need to do a check before the first statement for Generator.Throw() / Generator.Close().
            // The exception traceback needs to come from the generator's method body, and so we must do the check and throw
            // from inside the generator.
            if (IsGenerator) {
                MSAst.Expression s1 = YieldExpression.CreateCheckThrowExpression(SourceSpan.None);
                statements.Add(s1);
            }

            MSAst.ParameterExpression extracted = null;
            if (!IsGenerator && _canSetSysExcInfo) {
                // need to allocate the exception here so we don't share w/ exceptions made & freed
                // during the body.
                extracted = Ast.Parameter(typeof(Exception), "$ex");
                locals.Add(extracted);
            }

            if (_body.CanThrow && !(_body is SuiteStatement) && _body.Start.IsValid) {
                statements.Add(UpdateLineNumber(_body.Start.Line));
            }

            statements.Add(Body);
            MSAst.Expression body = Ast.Block(statements);

            // If this function can modify sys.exc_info() (_canSetSysExcInfo), then it must restore the result on finish.
            // 
            // Wrap in 
            //   $temp = PythonOps.SaveCurrentException()
            //   <body>
            //   PythonOps.RestoreCurrentException($temp)
            // Skip this if we're a generator. For generators, the try finally is handled by the PythonGenerator class 
            //  before it's invoked. This is because the restoration must occur at every place the function returns from 
            //  a yield point. That's different than the finally semantics in a generator.
            if (extracted != null) {
                MSAst.Expression s = AstUtils.Try(
                    Ast.Assign(
                        extracted,
                        Ast.Call(AstMethods.SaveCurrentException)
                    ),
                    body
                ).Finally(
                    Ast.Call(
                        AstMethods.RestoreCurrentException, extracted
                    )
                );
                body = s;
            }

            if (_body.CanThrow && GlobalParent.PyContext.PythonOptions.Frames) {
                body = AddFrame(LocalContext, Ast.Property(_functionParam, typeof(PythonFunction).GetProperty("__code__")), body);
                locals.Add(FunctionStackVariable);
            }

            body = AddProfiling(body);
            body = WrapScopeStatements(body, _body.CanThrow);
            body = Ast.Block(body, AstUtils.Empty());
            body = AddReturnTarget(body);


            MSAst.Expression bodyStmt = body;
            if (localContext != null) {
                var createLocal = CreateLocalContext(_parentContext);

                init.Add(
                    Ast.Assign(
                        localContext,
                        createLocal
                    )
                );
            }

            init.Add(bodyStmt);

            bodyStmt = Ast.Block(init);

            // wrap a scope if needed
            bodyStmt = Ast.Block(locals.ToReadOnlyCollection(), bodyStmt);

            return Ast.Lambda(
                delegateType,
                AddDefaultReturn(bodyStmt, typeof(object)),
                Name + "$" + Interlocked.Increment(ref _lambdaId),
                parameters
            );
        }
开发者ID:mstram,项目名称:ironruby,代码行数:101,代码来源:FunctionDefinition.cs

示例10: ReduceWorker

        internal MSAst.Expression ReduceWorker() {
            var retStmt = _body as ReturnStatement;
            
            if (retStmt != null && 
                (_languageFeatures == ModuleOptions.None || 
                _languageFeatures == (ModuleOptions.ExecOrEvalCode | ModuleOptions.Interpret) ||
                _languageFeatures == (ModuleOptions.ExecOrEvalCode | ModuleOptions.Interpret | ModuleOptions.LightThrow))) {
                // for simple eval's we can construct a simple tree which just
                // leaves the value on the stack.  Return's can't exist in modules
                // so this is always safe.
                Debug.Assert(!_isModule);

                var ret = (ReturnStatement)_body;
                Ast simpleBody;
                if ((_languageFeatures & ModuleOptions.LightThrow) != 0) {
                    simpleBody = LightExceptions.Rewrite(retStmt.Expression.Reduce());
                } else {
                    simpleBody = retStmt.Expression.Reduce();
                }

                var start = IndexToLocation(ret.Expression.StartIndex);
                var end = IndexToLocation(ret.Expression.EndIndex);

                return Ast.Block(
                    Ast.DebugInfo(
                        _document,
                        start.Line,
                        start.Column,
                        end.Line,
                        end.Column
                    ),
                    AstUtils.Convert(simpleBody, typeof(object))
                );
            }

            ReadOnlyCollectionBuilder<MSAst.Expression> block = new ReadOnlyCollectionBuilder<MSAst.Expression>();
            AddInitialiation(block);

            if (_isModule) {
                block.Add(AssignValue(GetVariableExpression(_docVariable), Ast.Constant(GetDocumentation(_body))));
            }

            if (!(_body is SuiteStatement) && _body.CanThrow) {
                // we only initialize line numbers in suite statements but if we don't generate a SuiteStatement
                // at the top level we can miss some line number updates.  
                block.Add(UpdateLineNumber(_body.Start.Line));
            }

            block.Add(_body);

            MSAst.Expression body = Ast.Block(block.ToReadOnlyCollection());
            
            body = WrapScopeStatements(body, Body.CanThrow);   // new ComboActionRewriter().VisitNode(Transform(ag))

            body = AddModulePublishing(body);

            body = AddProfiling(body);

            if ((((PythonCompilerOptions)_compilerContext.Options).Module & ModuleOptions.LightThrow) != 0) {
                body = LightExceptions.Rewrite(body);
            }

            body = Ast.Label(FunctionDefinition._returnLabel, AstUtils.Convert(body, typeof(object)));
            if (body.Type == typeof(void)) {
                body = Ast.Block(body, Ast.Constant(null));
            }

            return body;
        }
开发者ID:Xiaoqing,项目名称:main,代码行数:69,代码来源:PythonAst.cs

示例11: Transform

        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.Expression destination = ag.TransformAsObject(_dest);

            if (_expressions.Length == 0) {
                MSAst.Expression result;
                if (destination != null) {
                    result = Ast.Call(
                        AstGenerator.GetHelperMethod("PrintNewlineWithDest"),
                        ag.LocalContext,
                        destination
                    );
                } else {
                    result = Ast.Call(
                        AstGenerator.GetHelperMethod("PrintNewline"),
                        ag.LocalContext
                    );
                }
                return ag.AddDebugInfo(result, Span);
            } else {
                // Create list for the individual statements
                ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();

                // Store destination in a temp, if we have one
                if (destination != null) {
                    MSAst.ParameterExpression temp = ag.GetTemporary("destination");

                    statements.Add(
                        AstGenerator.MakeAssignment(temp, destination)
                    );

                    destination = temp;
                }
                for (int i = 0; i < _expressions.Length; i++) {
                    string method = (i < _expressions.Length - 1 || _trailingComma) ? "PrintComma" : "Print";
                    Expression current = _expressions[i];
                    MSAst.MethodCallExpression mce;

                    if (destination != null) {
                        mce = Ast.Call(
                            AstGenerator.GetHelperMethod(method + "WithDest"),
                            ag.LocalContext,
                            destination,
                            ag.TransformAsObject(current)
                        );
                    } else {
                        mce = Ast.Call(
                            AstGenerator.GetHelperMethod(method),
                            ag.LocalContext,
                            ag.TransformAsObject(current)
                        );
                    }

                    statements.Add(mce);
                }

                statements.Add(AstUtils.Empty());
                return ag.AddDebugInfo(Ast.Block(statements.ToReadOnlyCollection()), Span);
            }
        }
开发者ID:techarch,项目名称:ironruby,代码行数:59,代码来源:PrintStatement.cs

示例12: ReduceWorker

        internal MSAst.Expression ReduceWorker()
        {
            var retStmt = _body as ReturnStatement;

            if (retStmt != null)
            {
                var ret = (ReturnStatement)_body;
                Ast simpleBody;
                simpleBody = retStmt.Expression.Reduce();

                var start = IndexToLocation(ret.Expression.StartIndex);
                var end = IndexToLocation(ret.Expression.EndIndex);

                return Ast.Block(
                    Ast.DebugInfo(
                        _document,
                        start.Line,
                        start.Column,
                        end.Line,
                        end.Column
                    ),
                    AstUtils.Convert(simpleBody, typeof(object))
                );
            }

            ReadOnlyCollectionBuilder<MSAst.Expression> block = new ReadOnlyCollectionBuilder<MSAst.Expression>();

            if (!(_body is SuiteStatement) && _body.CanThrow)
            {
                // we only initialize line numbers in suite statements but if we don't generate a SuiteStatement
                // at the top level we can miss some line number updates.
                block.Add(UpdateLineNumber(_body.Start.Line));
            }

            block.Add(_body);

            MSAst.Expression body = Ast.Block(block.ToReadOnlyCollection());

            body = WrapScopeStatements(body, Body.CanThrow);   // new ComboActionRewriter().VisitNode(Transform(ag))

            body = AddProfiling(body);

            body = Ast.Label(FunctionDefinition._returnLabel, AstUtils.Convert(body, typeof(object)));

            if (body.Type == typeof(void))
            {
                body = Ast.Block(body, Ast.Constant(null));
            }

            return body;
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:51,代码来源:TotemAst.cs

示例13: CreateFunctionLambda


//.........这里部分代码省略.........
            }

            MSAst.ParameterExpression[] parameters = CreateParameters(locals);

            List<MSAst.Expression> init = new List<Ast>();

            foreach (var param in _parameters)
            {
                ITotemVariableExpression toVar = GetVariableExpression(param.TotemVariable) as ITotemVariableExpression;
                if (toVar != null)
                {
                    var varInit = toVar.Create();
                    if (varInit != null)
                        init.Add(varInit);
                }
            }

            // Transform the parameters.
            init.Add(Ast.ClearDebugInfo(GlobalParent.Document));

            locals.Add(TotemAst._globalContext);
            init.Add(Ast.Assign(TotemAst._globalContext, new GetGlobalContextExpression(_parentContext)));

            GlobalParent.PrepareScope(locals, init);

            // Create variables and references. Since references refer to
            // parameters, do this after parameters have been created.
            CreateFunctionVariables(locals, init);

            // Initialize parameters - unpack tuples.
            // Since tuples unpack into locals, this must be done after locals have been created.
            InitializeParameters(init, parameters);

            List<MSAst.Expression> statements = new List<MSAst.Expression>();
            // add beginning sequence point
            var start = GlobalParent.IndexToLocation(StartIndex);
            statements.Add(
                GlobalParent.AddDebugInfo(
                    AstUtils.Empty(),
                    new SourceSpan(new SourceLocation(0, start.Line, start.Column), new SourceLocation(0, start.Line, Int32.MaxValue)) // TODO: augment, not correct for totem
                )
            );

            // For generators, we need to do a check before the first statement for Generator.Throw() / Generator.Close().
            // The exception traceback needs to come from the generator's method body, and so we must do the check and throw
            // from inside the generator.
            if (IsGenerator)
            {
                //throw new NotImplementedException();
                //MSAst.Expression s1 = YieldExpression.CreateCheckThrowExpression(SourceSpan.None);
                //statements.Add(s1);
            }

            if (_body.CanThrow && !(_body is SuiteStatement) && _body.StartIndex != -1)
            {
                statements.Add(UpdateLineNumber(GlobalParent.IndexToLocation(_body.StartIndex).Line));
            }

            statements.Add(Body);
            MSAst.Expression body = Ast.Block(statements);

            if (_body.CanThrow && GlobalParent.TotemContext.TotemOptions.Frames)
            {
                //body = AddFrame(LocalContext, Ast.Property(_functionParam, typeof(TotemFunction).GetProperty("Code")), body);
                locals.Add(FunctionStackVariable);
            }

            body = AddProfiling(body);
            body = WrapScopeStatements(body, _body.CanThrow);
            body = Ast.Block(body, Ast.Empty());
            body = AddReturnTarget(body);

            MSAst.Expression bodyStmt = body;
            if (localContext != null)
            {
                var createLocal = CreateLocalContext(_parentContext);

                init.Add(
                    Ast.Assign(
                        localContext,
                        createLocal
                    )
                );
            }

            init.Add(bodyStmt);

            bodyStmt = Ast.Block(init);

            // wrap a scope if needed
            bodyStmt = Ast.Block(locals.ToReadOnlyCollection(), bodyStmt);

            return AstUtils.LightLambda(
                typeof(object),
                delegateType,
                AddDefaultReturn(bodyStmt, typeof(object)),
                Name + "$" + Interlocked.Increment(ref _lambdaId),
                parameters
            );
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:101,代码来源:FunctionDefinition.cs

示例14: Transform

        internal ReadOnlyCollection<MSAst.Expression> Transform(Statement/*!*/[]/*!*/ from) {
            Debug.Assert(from != null);
            var to = new ReadOnlyCollectionBuilder<MSAst.Expression>(from.Length + 1);

            SourceLocation start = SourceLocation.Invalid;

            for (int i = 0; i < from.Length; i++) {
                Debug.Assert(from[i] != null);

                to.Add(TransformMaybeSingleLineSuite(from[i], start));
                start = from[i].Start;
            }
            to.Add(AstUtils.Empty());
            return to.ToReadOnlyCollection();
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:15,代码来源:AstGenerator.cs

示例15: ReduceWorker

        internal MSAst.Expression ReduceWorker() {
            ReadOnlyCollectionBuilder<MSAst.Expression> block = new ReadOnlyCollectionBuilder<MSAst.Expression>();

            if (_body is ReturnStatement && (_languageFeatures == ModuleOptions.None || _languageFeatures == ModuleOptions.Interpret)) {
                // for simple eval's we can construct a simple tree which just
                // leaves the value on the stack.  Return's can't exist in modules
                // so this is always safe.
                Debug.Assert(!_isModule);

                return AstUtils.Convert(((ReturnStatement)_body).Expression.Reduce(), typeof(object));
            }

            AddInitialiation(block);

            if (_isModule) {
                block.Add(AssignValue(GetVariableExpression(_docVariable), Ast.Constant(GetDocumentation(_body))));
            }

            block.Add(_body);

            MSAst.Expression body = Ast.Block(block.ToReadOnlyCollection());
            
            body = WrapScopeStatements(body, Body.CanThrow);   // new ComboActionRewriter().VisitNode(Transform(ag))

            body = AddModulePublishing(body);

            body = AddProfiling(body);

            body = Ast.Label(FunctionDefinition._returnLabel, AstUtils.Convert(body, typeof(object)));
            if (body.Type == typeof(void)) {
                body = Ast.Block(body, Ast.Constant(null));
            }

            return body;
        }
开发者ID:atczyc,项目名称:ironruby,代码行数:35,代码来源:PythonAst.cs


注:本文中的ReadOnlyCollectionBuilder.ToReadOnlyCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。