Example #1
0
        protected override void DoEmit()
        {
            if ((!this.WrapByFn.HasValue || this.WrapByFn.Value) && (this.BlockStatement.Parent is ForStatement ||
                                                                     this.BlockStatement.Parent is ForeachStatement ||
                                                                     this.BlockStatement.Parent is WhileStatement ||
                                                                     this.BlockStatement.Parent is DoWhileStatement) &&
                (!this.Emitter.IsAsync || this.GetAwaiters(this.BlockStatement.Parent).Length == 0))
            {
                var visitor = new LambdaVisitor(true, this.Emitter);
                this.BlockStatement.AcceptVisitor(visitor);

                this.WrapByFn = visitor.LambdaExpression.Count > 0;

                if (this.WrapByFn.Value)
                {
                    var jumpVisitor = new ContinueBreakVisitor(false);
                    this.BlockStatement.AcceptVisitor(jumpVisitor);
                    this.HandleContinue = jumpVisitor.Continue.Count > 0;
                    this.HandleBreak    = jumpVisitor.Break.Count > 0;

                    jumpVisitor = new ContinueBreakVisitor(true);
                    this.BlockStatement.AcceptVisitor(jumpVisitor);
                    this.HandleReturn = jumpVisitor.Return.Count > 0;
                }

                this.OldReplaceJump      = this.Emitter.ReplaceJump;
                this.Emitter.ReplaceJump = (this.HandleContinue.HasValue && this.HandleContinue.Value) ||
                                           (this.HandleBreak.HasValue && this.HandleBreak.Value) ||
                                           (this.HandleReturn.HasValue && this.HandleReturn.Value);
            }

            this.EmitBlock();
        }
Example #2
0
        protected override void DoEmit()
        {
            if ((!this.WrapByFn.HasValue || this.WrapByFn.Value) && (this.BlockStatement.Parent is ForStatement ||
                     this.BlockStatement.Parent is ForeachStatement ||
                     this.BlockStatement.Parent is WhileStatement ||
                     this.BlockStatement.Parent is DoWhileStatement))
            {
                var visitor = new LambdaVisitor();
                this.BlockStatement.AcceptVisitor(visitor);

                this.WrapByFn = visitor.LambdaExpression.Count > 0;

                if (this.WrapByFn.Value)
                {
                    var jumpVisitor = new ContinueBreakVisitor(false);
                    this.BlockStatement.AcceptVisitor(jumpVisitor);
                    this.HandleContinue = jumpVisitor.Continue.Count > 0;
                    this.HandleBreak = jumpVisitor.Break.Count > 0;

                    jumpVisitor = new ContinueBreakVisitor(true);
                    this.BlockStatement.AcceptVisitor(jumpVisitor);
                    this.HandleReturn = jumpVisitor.Return.Count > 0;
                }

                this.OldReplaceJump = this.Emitter.ReplaceJump;
                this.Emitter.ReplaceJump = (this.HandleContinue.HasValue && this.HandleContinue.Value) ||
                                           (this.HandleBreak.HasValue && this.HandleBreak.Value) ||
                                           (this.HandleReturn.HasValue && this.HandleReturn.Value);
            }

            this.EmitBlock();
        }