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


C# ImmutableArray.RefKinds方法代码示例

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


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

示例1: BuildStoresToTemps

        // This fills in the arguments, refKinds and storesToTemps arrays.
        private void BuildStoresToTemps(
            bool expanded,
            ImmutableArray<int> argsToParamsOpt,
            ImmutableArray<RefKind> argumentRefKinds,
            ImmutableArray<BoundExpression> rewrittenArguments,
            /* out */ BoundExpression[] arguments,
            /* out */ ArrayBuilder<RefKind> refKinds,
            /* out */ ArrayBuilder<BoundAssignmentOperator> storesToTemps)
        {
            Debug.Assert(refKinds.Count == arguments.Length);
            Debug.Assert(storesToTemps.Count == 0);

            for (int a = 0; a < rewrittenArguments.Length; ++a)
            {
                BoundExpression argument = rewrittenArguments[a];
                int p = (!argsToParamsOpt.IsDefault) ? argsToParamsOpt[a] : a;
                RefKind refKind = argumentRefKinds.RefKinds(a);
                Debug.Assert(arguments[p] == null);

                if (expanded && p == arguments.Length - 1)
                {
                    // Unfortunately, we violate the specification and allow:
                    // M(int q, params int[] x) ... M(x : X(), q : Q());
                    // which means that we cannot bail out just because
                    // an argument of an expanded-form call corresponds to
                    // the parameter array. We need to make sure that the
                    // side effects of X() and Q() continue to happen in the right
                    // order here.
                    //
                    // Fortunately, we do disallow M(x : 123, x : 345, x : 456).
                    // 
                    // Here's what we'll do. If all the remaining arguments
                    // correspond to elements in the parameter array then 
                    // we can bail out here without creating any temporaries.
                    // The next step in the call rewriter will deal with gathering
                    // up the elements. 
                    //
                    // However, if there are other elements after this one
                    // that do not correspond to elements in the parameter array
                    // then we need to create a temporary as usual. The step that
                    // produces the parameter array will need to deal with that
                    // eventuality.

                    bool canBail = true;
                    for (int remainingArgument = a + 1; remainingArgument < rewrittenArguments.Length; ++remainingArgument)
                    {
                        int remainingParameter = (!argsToParamsOpt.IsDefault) ? argsToParamsOpt[remainingArgument] : remainingArgument;
                        if (remainingParameter != arguments.Length - 1)
                        {
                            canBail = false;
                            break;
                        }
                    }
                    if (canBail)
                    {
                        return;
                    }
                }

                if (IsSafeForReordering(argument, refKind))
                {
                    arguments[p] = argument;
                    refKinds[p] = refKind;
                }
                else
                {
                    BoundAssignmentOperator assignment;
                    var temp = _factory.StoreToTemp(argument, out assignment, refKind: refKind);
                    storesToTemps.Add(assignment);
                    arguments[p] = temp;
                }
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:74,代码来源:LocalRewriter_Call.cs


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