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


C# ReadOnlyArray.ToReadOnly方法代码示例

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


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

示例1: Perform

        public static BoundProgram Perform(BoundProgram program, IList<BoundExpression> resultExpressions)
        {
            // If the last statement of the program is a return, we don't
            // have to rewrite the program.

            var body = program.Body;
            if (
                body.Body.Nodes.Count > 0 &&
                body.Body.Nodes[body.Body.Nodes.Count - 1] is BoundReturn
            )
                return program;

            // If we don't have any result expressions, we only have to
            // insert a return statement.

            if (resultExpressions == null || resultExpressions.Count == 0)
            {
                // Create a new nodes list with the added return statement.

                var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                nodes.AddRange(body.Body.Nodes);
                nodes.Add(new BoundReturn(
                    null,
                    SourceLocation.Missing
                ));

                // Return the updated program.

                return program.Update(
                    body.Update(
                        body.Body.Update(
                            body.Body.Temporaries,
                            nodes.ToReadOnly(),
                            body.Body.Location
                            ),
                        body.Closure,
                        body.ScopedClosure,
                        body.Arguments,
                        body.Locals,
                        body.MappedArguments,
                        body.Flags,
                        body.TypeManager
                    )
                );
            }

            // Otherwise, we need to do a full rewrite.

            return program.Update(
                (BoundBody)new Rewriter(resultExpressions, body.TypeManager).Visit(program.Body)
            );
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:53,代码来源:ResultRewriterPhase.cs

示例2: GetStatements

            private ReadOnlyArray<SyntaxNode> GetStatements()
            {
                var builder = new ReadOnlyArray<SyntaxNode>.Builder();

                if (_declaredFunctions != null)
                    builder.AddRange(_declaredFunctions);
                if (_statements != null)
                    builder.AddRange(_statements);

                return builder.ToReadOnly();
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:11,代码来源:AstBuilder.Scope.cs

示例3: CommitIdentifiers


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

                foreach (string identifier in _declaredIdentifiers)
                {
                    if (!identifiers.ContainsKey(identifier))
                    {
                        identifiers.Add(
                            identifier,
                            new ResolvedIdentifier(
                                identifier,
                                null,
                                _bodyType == BodyType.Program ? IdentifierType.Global : IdentifierType.Local,
                                true
                            )
                        );
                    }
                }

                // Resolve all identifiers.

                foreach (var identifier in _identifiers)
                {
                    ResolvedIdentifier resolved = null;

                    // First check whether we have a catch variable in scope.

                    if (identifier.CatchScope != null && identifier.CatchScope.Scope == this)
                    {
                        var catchScope = identifier.CatchScope;

                        while (catchScope != null && catchScope.Scope == this)
                        {
                            if (catchScope.Identifier.Name == identifier.Name)
                            {
                                resolved = catchScope.Identifier;
                                break;
                            }

                            catchScope = catchScope.Parent;
                        }

                        if (resolved != null)
                        {
                            identifier.Identifier.ResolvedIdentifier = resolved;

                            if (identifier.Scope != this)
                                _closedOverIdentifiers.Add(resolved);

                            continue;
                        }

                        // We need to change the catch scope of the unresolved
                        // identifier to strip the catch scopes that belong to
                        // us. This way resolving in the parent scope resolves
                        // to a declared variable or to the catch variable of
                        // that scope.

                        identifier.CatchScope = catchScope;
                    }

                    if (identifiers.TryGetValue(identifier.Name, out resolved))
                    {
                        // We have this identifier.

                        identifier.Identifier.ResolvedIdentifier = resolved;

                        // If the identifier does not belong to this scope,
                        // it's being closed over.

                        if (identifier.Scope != this && resolved.Type != IdentifierType.Global)
                            _closedOverIdentifiers.Add(resolved);
                    }
                    else if (Parent == null)
                    {
                        // It's an undeclared global identifier.

                        resolved = new ResolvedIdentifier(
                            identifier.Name,
                            null,
                            IdentifierType.Global,
                            false
                        );

                        identifiers.Add(identifier.Name, resolved);
                        identifier.Identifier.ResolvedIdentifier = resolved;
                    }
                    else
                    {
                        // Else, push it to the parent and let that figure it out.

                        Parent._identifiers.Add(identifier);
                    }
                }

                var builder = new ReadOnlyArray<IIdentifier>.Builder();

                builder.AddRange(identifiers.Select(p => p.Value));
                builder.AddRange(_resolvedIdentifiers);

                return builder.ToReadOnly();
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:101,代码来源:AstBuilder.Scope.cs

示例4: VisitBody

            public override BoundNode VisitBody(BoundBody node)
            {
                node = (BoundBody)base.VisitBody(node);

                // Add the initialization of the result temporary and the
                // return statement.

                var nodes = new ReadOnlyArray<BoundStatement>.Builder(node.Body.Nodes.Count + 2);

                // We always add the default value. The reason for this is that
                // we're already passed the definite assignment phase, so it won't
                // be inserted for us automatically.

                nodes.Add(new BoundSetVariable(
                    _resultTemporary,
                    new BoundGetVariable(BoundMagicVariable.Undefined),
                    SourceLocation.Missing
                ));

                nodes.AddRange(node.Body.Nodes);

                nodes.Add(new BoundReturn(
                    new BoundGetVariable(_resultTemporary),
                    SourceLocation.Missing
                ));

                return node.Update(
                    node.Body.Update(
                        node.Body.Temporaries,
                        nodes.ToReadOnly(),
                        node.Body.Location
                    ),
                    node.Closure,
                    node.ScopedClosure,
                    node.Arguments,
                    node.Locals,
                    node.MappedArguments,
                    node.Flags,
                    node.TypeManager
                );
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:41,代码来源:ResultRewriterPhase.cs

示例5: Visit

            public override BoundNode Visit(BoundNode node)
            {
                var expression = node as BoundExpression;
                if (expression != null && _resultExpressions.Contains(expression))
                {
                    // Create a temporary to hold the result.

                    var temporary = new BoundTemporary(
                        --_lastTemporaryIndex,
                        _typeManager.CreateType(null, BoundTypeKind.Temporary)
                    );

                    var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                    // Initialize the temporary with the expression.

                    nodes.Add(new BoundSetVariable(
                        temporary,
                        expression,
                        SourceLocation.Missing
                    ));

                    // Copy the temporary to the result.

                    nodes.Add(new BoundSetVariable(
                        _resultTemporary,
                        new BoundGetVariable(temporary),
                        SourceLocation.Missing
                    ));

                    // Return an expression block.

                    return new BoundExpressionBlock(
                        temporary,
                        new BoundBlock(
                            ReadOnlyArray<BoundTemporary>.CreateFrom(temporary),
                            nodes.ToReadOnly(),
                            SourceLocation.Missing
                        )
                    );
                }

                return base.Visit(node);
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:44,代码来源:ResultRewriterPhase.cs

示例6: GetProperties

        public ReadOnlyArray<JsonProperty> GetProperties()
        {
            var builder = new ReadOnlyArray<JsonProperty>.Builder();

            foreach (var assignment in _assignments)
            {
                if (assignment.Value.Mode == PropertyExpressionType.Data)
                {
                    builder.Add(new JsonDataProperty(
                        assignment.Key,
                        assignment.Value.Expression
                    ));
                }
                else
                {
                    builder.Add(new JsonAccessorProperty(
                        assignment.Key,
                        assignment.Value.GetExpression,
                        assignment.Value.SetExpression
                    ));
                }
            }

            return builder.ToReadOnly();
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:25,代码来源:JsonPropertyBuilder.cs

示例7: VisitBlock

            public override BoundNode VisitBlock(BoundBlock node)
            {
                // First check whether we have work.

                bool haveWork = false;

                foreach (var temporary in node.Temporaries)
                {
                    if (_statistics[temporary].ShouldReplace)
                    {
                        haveWork = true;
                        break;
                    }
                }

                // If we don't have work, just cascade.
                if (!haveWork)
                    return base.VisitBlock(node);

                // Create a new list of temporaries with the variables to be
                // squelched removed.
                var newTemporaries = new ReadOnlyArray<BoundTemporary>.Builder();
                foreach (var temporary in node.Temporaries)
                {
                    if (_statistics[temporary].ShouldReplace)
                        temporary.Type.MarkUnused();
                    else
                        newTemporaries.Add(temporary);
                }
                var temporaries = newTemporaries.ToReadOnly();

                // Rebuild the nodes with the new rules applied.
                var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                foreach (var statement in node.Nodes)
                {
                    var setVariable = statement as BoundSetVariable;
                    if (setVariable != null)
                    {
                        setVariable = (BoundSetVariable)Visit(setVariable);

                        // If the set variable reduced to an assignment to itself,
                        // remove the set variable. This happens when the variable
                        // of the set variable is replaced.

                        var getVariable = setVariable.Value as BoundGetVariable;
                        if (getVariable != null && setVariable.Variable == getVariable.Variable)
                            continue;

                        // If we're going to squelch this local, remove the
                        // set variable for it.

                        var temporary = setVariable.Variable as BoundTemporary;
                        if (temporary != null && _statistics[temporary].ShouldRemove)
                            continue;
                    }

                    nodes.Add((BoundStatement)Visit(statement));
                }

                // Return the new block.

                return new BoundBlock(temporaries, nodes.ToReadOnly(), node.Location);
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:64,代码来源:SquelchPhase.cs

示例8: BuildBlock

            public BoundBlock BuildBlock(SourceLocation location)
            {
                if (_nodes == null)
                {
                    Debug.Assert(_temporaries == null);

                    return new BoundBlock(
                        ReadOnlyArray<BoundTemporary>.Empty,
                        ReadOnlyArray<BoundStatement>.Empty,
                        location
                    );
                }

                var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                foreach (var node in _nodes.ToReadOnly())
                {
                    // Flatten blocks. Nested blocks have no use, so we flatten
                    // them into this block. First we try to see whether the node
                    // is a block. If not, we try to see whether the node is an
                    // expression statement that has an expression block
                    // as its expression. In that case, we're taking the value of
                    // an expression block without doing anything with it.

                    var block = node as BoundBlock;
                    if (block != null)
                    {
                        if (_temporaries == null)
                            _temporaries = new ReadOnlyArray<BoundTemporary>.Builder();

                        _temporaries.AddRange(block.Temporaries);
                        if (block.Location != SourceLocation.Missing)
                            nodes.Add(new BoundEmpty(block.Location));
                        nodes.AddRange(block.Nodes);
                        continue;
                    }

                    // Otherwise, we keep the node unchanged.
                    nodes.Add(node);
                }

                return new BoundBlock(
                    _temporaries == null ? ReadOnlyArray<BoundTemporary>.Empty : _temporaries.ToReadOnly(),
                    nodes.ToReadOnly(),
                    location
                );
            }
开发者ID:pvginkel,项目名称:Jint2,代码行数:47,代码来源:BindingVisitor.Builders.cs

示例9: BuildThrow

        private BoundStatement BuildThrow(string @class, string message)
        {
            var arguments = new ReadOnlyArray<BoundCallArgument>.Builder();

            if (message != null)
            {
                arguments.Add(new BoundCallArgument(
                    BoundConstant.Create(message),
                    false
                ));
            }

            _scope.IsGlobalScopeReferenced = true;

            // Build the throw.
            return new BoundThrow(
                // Instantiate the new error class.
                new BoundNew(
                    // Get the error class.
                    new BoundGetMember(
                        new BoundGetVariable(BoundMagicVariable.Global),
                        BoundConstant.Create(@class)
                    ),
                    // Pass the arguments (the message).
                    arguments.ToReadOnly(),
                    ReadOnlyArray<BoundExpression>.Empty
                ),
                SourceLocation.Missing
            );
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:30,代码来源:BindingVisitor.Builders.cs


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