예제 #1
0
        private static WhileStatementSyntax ExtractExpressionToNestedIf(
            ExpressionSyntax expression,
            WhileStatementSyntax whileStatement,
            WhileStatementSyntax newWhileStatement)
        {
            if (newWhileStatement.Statement.IsKind(SyntaxKind.Block))
            {
                var block = (BlockSyntax)newWhileStatement.Statement;

                IfStatementSyntax nestedIf = IfStatement(
                    expression.WithoutTrivia(),
                    Block(block.Statements));

                return(newWhileStatement.ReplaceNode(
                           block,
                           block.WithStatements(SingletonList <StatementSyntax>(nestedIf))));
            }
            else
            {
                IfStatementSyntax nestedIf = IfStatement(
                    expression.WithoutTrivia(),
                    whileStatement.Statement.WithoutTrivia());

                BlockSyntax block = Block(nestedIf).WithTriviaFrom(whileStatement.Statement);

                return(newWhileStatement.WithStatement(block));
            }
        }
예제 #2
0
        public static WhileStatementSyntax AddBraces(WhileStatementSyntax whileStatement)
        {
            Debug.Assert(whileStatement != null && NeedsBraces(whileStatement));

            return whileStatement
                .WithStatement(SyntaxFactory.Block(whileStatement.Statement))
                .WithAdditionalAnnotations(Formatter.Annotation);
        }
예제 #3
0
        public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
        {
            var blockResumeLocation = GetBlockResumeLocation(node.Statement);

            node = (WhileStatementSyntax)base.VisitWhileStatement(node);

            node = node.WithStatement(InjectedBlock(node.Statement, blockResumeLocation));
            return(node);
        }
        public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
        {
            var body      = node.Statement;
            var bodyBlock = ToBlockSyntax(body);

            if (!bodyBlock.Equals(body))
            {
                node = node.WithStatement(bodyBlock);
            }
            return(node);
        }
예제 #5
0
        public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
        {
            this.loopLevel++;

            var statement = base.VisitWhileStatement(node
                                                     .WithStatement(GetLoopBlock(node.Statement)))
                            .WithAdditionalAnnotations(this.isLoop);

            this.loopLevel--;

            return(statement);
        }
예제 #6
0
        private static SyntaxNode RepeatStatement(RParser.RepeatStatementContext repeatStatement, Func <ParserRuleContext, Scope, SyntaxNode> transform, Scope scope)
        {
            if (!topLevel(repeatStatement))
            {
                throw new NotImplementedException();
            }

            BlockSyntax body = parseBlock(repeatStatement.expr(), transform, scope);

            return(repeat
                   .WithStatement(body));
        }
예제 #7
0
        public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
        {
            WhileStatementSyntax newNode = (WhileStatementSyntax)base.VisitWhileStatement(node);

            if (!(newNode.Statement is BlockSyntax))
            {
                BlockSyntax block = SyntaxFactory.Block(newNode.Statement);
                newNode = node.WithStatement(block);
            }

            return(newNode);
        }
예제 #8
0
        public override void VisitWhileStatement(WhileStatementSyntax node)
        {
            if (!YieldChecker.HasSpecialStatement(node))
            {
                currentState.Add(StateMachineThisFixer.Fix(node));
            }
            else
            {
                MaybeCreateNewState();

                var nextState      = GetNextState(node);
                var iterationState = currentState;
                iterationState.NextState  = nextState;
                iterationState.BreakState = nextState;

                node = node.WithStatement(SyntaxFactory.Block(CaptureState(node.Statement, iterationState, nextState)));
                iterationState.Statements.Add(node);

                Close(iterationState);

                currentState = nextState;
            }
        }
예제 #9
0
        public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
        {
            this.loopLevel++;

            var statement = base.VisitWhileStatement (node
                                .WithStatement (GetLoopBlock (node.Statement)))
                            .WithAdditionalAnnotations (this.isLoop);

            this.loopLevel--;

            return statement;
        }
            public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
            {
                node = (WhileStatementSyntax)base.VisitWhileStatement(node);

                if (!node.Statement.IsKind(SyntaxKind.Block))
                {
                    this.addedAnnotations = true;
                    node = node.WithStatement(SyntaxFactory.Block(node.Statement));
                }

                return node;
            }
        public override void VisitWhileStatement(WhileStatementSyntax node)
        {
            if (!YieldChecker.HasSpecialStatement(node))
            {
                currentState.Add(StateMachineThisFixer.Fix(node));
            }
            else
            {
                MaybeCreateNewState();

                var nextState = GetNextState(node);
                var iterationState = currentState;
                iterationState.NextState = nextState;
                iterationState.BreakState = nextState;

                node = node.WithStatement(SyntaxFactory.Block(CaptureState(node.Statement, iterationState, nextState)));
                iterationState.Statements.Add(node);

                Close(iterationState);

                currentState = nextState;
            }
        }