Exemple #1
0
            protected override Expression VisitGoto(GotoExpression node)
            {
                var target = node.Target;

                if (!_labels.Contains(target))
                {
                    var data = default(LeaveLabelData);
                    if (!LeaveLabels.TryGetValue(target, out data))
                    {
                        var parameter = default(ParameterExpression);

                        if (target.Type != typeof(void))
                        {
                            parameter = Expression.Parameter(target.Type, FormattableString.Invariant($"__goto{LeaveLabels.Count}"));
                        }

                        data = new LeaveLabelData
                        {
                            Index  = LeaveLabels.Count + 1,
                            Target = target,
                            Value  = parameter
                        };

                        LeaveLabels.Add(target, data);
                    }

                    var res = default(Expression);

                    if (data.Value != null)
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Assign(data.Value, node.Value),
                                Expression.Goto(_exit, node.Type)
                                );
                    }
                    else
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Goto(_exit, node.Type)
                                );
                    }

                    return(res);
                }

                return(base.VisitGoto(node));
            }
            protected override Expression VisitGoto(GotoExpression node)
            {
                var target = node.Target;

                if (!_labels.Contains(target))
                {
                    var data = default(LeaveLabelData);
                    if (!LeaveLabels.TryGetValue(target, out data))
                    {
                        var parameter = default(ParameterExpression);

                        if (target.Type != typeof(void))
                        {
                            parameter = Expression.Parameter(target.Type, FormattableString.Invariant($"__goto{LeaveLabels.Count}"));
                        }

                        data = new LeaveLabelData
                        {
                            Index = LeaveLabels.Count + 1,
                            Target = target,
                            Value = parameter
                        };

                        LeaveLabels.Add(target, data);
                    }

                    var res = default(Expression);

                    if (data.Value != null)
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Assign(data.Value, node.Value),
                                Expression.Goto(_exit, node.Type)
                            );
                    }
                    else
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Goto(_exit, node.Type)
                            );
                    }

                    return res;
                }

                return base.VisitGoto(node);
            }