Пример #1
0
        public override AstNode VisitWhileStatement(WhileStatement forStatement)
        {
            var visitor = new LambdaVisitor();

            forStatement.EmbeddedStatement.AcceptVisitor(visitor);

            if (visitor.LambdaExpression.Count == 0 && forStatement.EmbeddedStatement is BlockStatement)
            {
                return(base.VisitWhileStatement(forStatement));
            }

            var clonForStatement = (WhileStatement)base.VisitWhileStatement(forStatement);

            if (clonForStatement != null)
            {
                forStatement = clonForStatement;
            }

            if (!(forStatement.EmbeddedStatement is BlockStatement))
            {
                var l     = (WhileStatement)forStatement.Clone();
                var block = new BlockStatement();
                block.Statements.Add(l.EmbeddedStatement.Clone());
                l.EmbeddedStatement = block;

                return(l);
            }

            return(forStatement.Clone());
        }
Пример #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) &&
                (!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();
        }
Пример #3
0
        public override void Emit()
        {
            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;
            }

            this.EmitBlock();
        }
Пример #4
0
        public override void VisitDoWhileStatement(DoWhileStatement whileStatement)
        {
            if (!(whileStatement.EmbeddedStatement is BlockStatement))
            {
                var visitor = new LambdaVisitor();
                whileStatement.EmbeddedStatement.AcceptVisitor(visitor);

                if (visitor.LambdaExpression.Count > 0)
                {
                    this.Found = true;
                }
            }

            base.VisitDoWhileStatement(whileStatement);
        }
Пример #5
0
        public override void VisitForeachStatement(ForeachStatement foreachStatement)
        {
            if (!(foreachStatement.EmbeddedStatement is BlockStatement))
            {
                var visitor = new LambdaVisitor();
                foreachStatement.EmbeddedStatement.AcceptVisitor(visitor);

                if (visitor.LambdaExpression.Count > 0)
                {
                    this.Found = true;
                }
            }

            base.VisitForeachStatement(foreachStatement);
        }
Пример #6
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();
        }
Пример #7
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;
            }

            this.EmitBlock();
        }