示例#1
0
            /// <summary>
            /// Add a branch in the lowered decision tree to a label for a matched
            /// pattern, and then produce a statement for the target of that branch
            /// that binds the pattern variables.
            /// </summary>
            /// <param name="bindings">The source/destination pairs for the assignments</param>
            /// <param name="addBindings">A builder to which the label and binding assignments are added</param>
            private void AddBindingsForCase(
                ImmutableArray <KeyValuePair <BoundExpression, BoundExpression> > bindings,
                ArrayBuilder <BoundStatement> addBindings)
            {
                var patternMatched = _factory.GenerateLabel("patternMatched");

                _loweredDecisionTree.Add(_factory.Goto(patternMatched));

                // Hide the code that binds pattern variables in a hidden sequence point
                addBindings.Add(_factory.HiddenSequencePoint());
                addBindings.Add(_factory.Label(patternMatched));
                if (!bindings.IsDefaultOrEmpty)
                {
                    foreach (var kv in bindings)
                    {
                        var loweredRight = kv.Key;
                        var loweredLeft  = kv.Value;
                        addBindings.Add(_factory.ExpressionStatement(
                                            _localRewriter.MakeStaticAssignmentOperator(
                                                _factory.Syntax, loweredLeft, loweredRight, RefKind.None, loweredLeft.Type, false)));
                    }
                }
            }