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


C# ReadOnlyCollectionBuilder.Add方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: Bind

        // Just splat the args and dispatch through a nested site
        public override Expression Bind(object[] args, ReadOnlyCollection<ParameterExpression> parameters, LabelTarget returnLabel) {
            Debug.Assert(args.Length == 2);

            int count = ((object[])args[1]).Length;
            ParameterExpression array = parameters[1];

            var nestedArgs = new ReadOnlyCollectionBuilder<Expression>(count + 1);
            var delegateArgs = new Type[count + 3]; // args + target + returnType + CallSite
            nestedArgs.Add(parameters[0]);
            delegateArgs[0] = typeof(CallSite);
            delegateArgs[1] = typeof(object);
            for (int i = 0; i < count; i++) {
                nestedArgs.Add(Expression.ArrayAccess(array, Expression.Constant(i)));
                delegateArgs[i + 2] = typeof(object).MakeByRefType();
            }
            delegateArgs[delegateArgs.Length - 1] = typeof(object);

            return Expression.IfThen(
                Expression.Equal(Expression.ArrayLength(array), Expression.Constant(count)),
                Expression.Return(
                    returnLabel,
                    Expression.MakeDynamic(
                        Expression.GetDelegateType(delegateArgs),
                        new ComInvokeAction(new CallInfo(count)),
                        nestedArgs
                    )
                )
            );
        }
开发者ID:jschementi,项目名称:iron,代码行数:30,代码来源:ComInvokeAction.cs

示例5: Transform

 internal override MSAst.Expression Transform(AstGenerator ag) {
     // Transform to series of individual del statements.
     ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>(_expressions.Length + 1);
     for (int i = 0; i < _expressions.Length; i++) {
         statements.Add(_expressions[i].TransformDelete(ag));
     }
     statements.Add(AstUtils.Empty());
     return ag.AddDebugInfo(MSAst.Expression.Block(statements), Span);
 }
开发者ID:techarch,项目名称:ironruby,代码行数:9,代码来源:DelStatement.cs

示例6: Reduce

 public override MSAst.Expression Reduce() {
     // Transform to series of individual del statements.
     ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>(_expressions.Length + 1);
     for (int i = 0; i < _expressions.Length; i++) {
         statements.Add(_expressions[i].TransformDelete());
     }
     statements.Add(AstUtils.Empty());
     return GlobalParent.AddDebugInfo(MSAst.Expression.Block(statements), Span);
 }
开发者ID:jschementi,项目名称:iron,代码行数:9,代码来源:DelStatement.cs

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: CreateFunctionLambda

        //internal static Func<TotemFunction, TotemArgs, object> FunctionDelegate = new Func<TotemFunction, TotemArgs, object>((fn, args) =>
        //{
        //    fn.Code.LazyCompileFirstTarget(fn);
        //    return ((Func<TotemFunction, TotemArgs, object>)fn.Code.Target)(fn, args);
        //});
        /// <summary>
        /// Creates the LambdaExpression which implements the body of the function.
        /// 
        /// The functions signature is either "object Function(PythonFunction, ...)"
        /// where there is one object parameter for each user defined parameter or
        /// object Function(PythonFunction, object[]) for functions which take more
        /// than PythonCallTargets.MaxArgs arguments.
        /// </summary>
        private LightLambdaExpression CreateFunctionLambda()
        {
            Type delegateType = typeof(Func<TotemFunction, TotemArgs, object>);

            MSAst.ParameterExpression localContext = null;
            ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals = new ReadOnlyCollectionBuilder<MSAst.ParameterExpression>();
            if (NeedsLocalContext || CanThrow)
            {
                localContext = LocalCodeContextVariable;
                locals.Add(localContext);
            }

            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);

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

示例12: CreateVariables

 internal void CreateVariables(ReadOnlyCollectionBuilder<ParameterExpression> locals, List<Expression> init)
 {
     if (_scopeVars != null)
         foreach (var local in _scopeVars)
         {
             Debug.Assert(local.Kind == VariableKind.Local || local.Kind == VariableKind.Parameter);
             ClosureExpression closure = GetVariableExpression(local) as ClosureExpression;
             if (closure != null)
             {
                 init.Add(closure.Create());
                 locals.Add((ParameterExpression)closure.ClosureCell);
             }
             else if (local.Kind == VariableKind.Local)
             {
                 locals.Add((ParameterExpression)GetVariableExpression(local));
                 if (local.ReadBeforeInitialized)
                 {
                     init.Add(
                         AssignValue(
                             GetVariableExpression(local),
                             Expression.Field(null, typeof(Uninitialized).GetField("Value"))
                         )
                     );
                 }
             }
         }
 }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:27,代码来源:ScopeStmt.cs

示例13: AddVariables

        internal Ast AddVariables(Ast expression) {
            ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals = new ReadOnlyCollectionBuilder<MSAst.ParameterExpression>();
            MSAst.ParameterExpression localContext = null;
            if (NeedsLocalContext) {
                localContext = _compContext;
                locals.Add(_compContext);
            }

            List<MSAst.Expression> body = new List<MSAst.Expression>();
            CreateVariables(locals, body);

            if (localContext != null) {
                var createLocal = CreateLocalContext(_comprehension.Parent.LocalContext);
                body.Add(Ast.Assign(_compContext, createLocal));
                body.Add(expression);
            } else {
                body.Add(expression);
            }

            return Expression.Block(
                locals, 
                body
            );
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:24,代码来源:Comprehension.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: Reduce

        /// <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>
        public override MSAst.Expression Reduce() {
            // Five statements in the result...
            ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>(6);
            ReadOnlyCollectionBuilder<MSAst.ParameterExpression> variables = new ReadOnlyCollectionBuilder<MSAst.ParameterExpression>(6);
            MSAst.ParameterExpression lineUpdated = Ast.Variable(typeof(bool), "$lineUpdated_with");
            variables.Add(lineUpdated);

            //******************************************************************
            // 1. mgr = (EXPR)
            //******************************************************************
            MSAst.ParameterExpression manager = Ast.Variable(typeof(object), "with_manager");
            variables.Add(manager);
            statements.Add(
                GlobalParent.AddDebugInfo(
                    Ast.Assign(
                        manager,
                        _contextManager
                    ),
                    new SourceSpan(Start, _header)
                )
            );

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

            //******************************************************************
            // 3. value = mgr.__enter__()
            //******************************************************************
            MSAst.ParameterExpression value = Ast.Variable(typeof(object), "with_value");
            variables.Add(value);
            statements.Add(
                GlobalParent.AddDebugInfoAndVoid(
                    MakeAssignment(
                        value,
                        Parent.Invoke(
                            new CallSignature(0),
                            Parent.LocalContext,
                            GlobalParent.Get(
                                "__enter__",
                                manager
                            )
                        )
                    ),
                    new SourceSpan(Start, _header)
                )
            );

            //******************************************************************
            // 4. exc = True
            //******************************************************************
            MSAst.ParameterExpression exc = Ast.Variable(typeof(bool), "with_exc");
            variables.Add(exc);
            statements.Add(
                MakeAssignment(
                    exc,
                    AstUtils.Constant(true)
                )
            );

            //******************************************************************
            //  5. The final try statement:
            //
            //  try:
            //      VAR = value  # Only if "as VAR" is present
            //      BLOCK
//.........这里部分代码省略.........
开发者ID:atczyc,项目名称:ironruby,代码行数:101,代码来源:WithStatement.cs


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