public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition   = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement   = (BoundStatement)Visit(node.Increment);
            var rewrittenBody        = (BoundStatement)Visit(node.Body);

            // EnC: We need to insert a hidden sequence point to handle function remapping in case
            // the containing method is edited while methods invoked in the condition are being executed.
            if (rewrittenCondition != null && this.Instrument)
            {
                rewrittenCondition = _instrumenter.InstrumentForStatementCondition(node, rewrittenCondition, _factory);
            }

            return(RewriteForStatement(
                       node,
                       node.OuterLocals,
                       rewrittenInitializer,
                       rewrittenCondition,
                       rewrittenIncrement,
                       rewrittenBody,
                       node.BreakLabel,
                       node.ContinueLabel, node.HasErrors));
        }
Example #2
0
 public override BoundStatement InstrumentForStatementConditionalGotoStartOrBreak(
     BoundForStatement original,
     BoundStatement branchBack
     )
 {
     return(Previous.InstrumentForStatementConditionalGotoStartOrBreak(original, branchBack));
 }
Example #3
0
 public virtual BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     Debug.Assert(factory != null);
     return(rewrittenCondition);
 }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement = (BoundStatement)Visit(node.Increment);
            var rewrittenBody = (BoundStatement)Visit(node.Body);

            // EnC: We need to insert a hidden sequence point to handle function remapping in case 
            // the containing method is edited while methods invoked in the condition are being executed.
            if (rewrittenCondition != null && this.Instrument)
            {
                rewrittenCondition = _instrumenter.InstrumentForStatementCondition(node, rewrittenCondition, _factory);
            }

            return RewriteForStatement(
                node,
                node.OuterLocals,
                rewrittenInitializer,
                rewrittenCondition,
                rewrittenIncrement,
                rewrittenBody,
                node.BreakLabel,
                node.ContinueLabel, node.HasErrors);
        }
Example #5
0
 public override BoundExpression InstrumentForStatementCondition(
     BoundForStatement original,
     BoundExpression rewrittenCondition,
     SyntheticBoundNodeFactory factory
     )
 {
     return(Previous.InstrumentForStatementCondition(original, rewrittenCondition, factory));
 }
Example #6
0
        internal override BoundForStatement BindForParts(
            BindingDiagnosticBag diagnostics,
            Binder originalBinder
            )
        {
            BoundForStatement result = BindForParts(_syntax, originalBinder, diagnostics);

            return(result);
        }
Example #7
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     if (IsInside)
     {
         _labelsInside.Add(node.BreakLabel);
         _labelsInside.Add(node.ContinueLabel);
     }
     return(base.VisitForStatement(node));
 }
Example #8
0
 public virtual BoundStatement InstrumentForStatementConditionalGotoStartOrBreak(
     BoundForStatement original,
     BoundStatement branchBack
     )
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return(branchBack);
 }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = VisitStatement(node.Initializer);
            var rewrittenCondition   = VisitExpression(node.Condition);
            var rewrittenIncrement   = VisitStatement(node.Increment);
            var rewrittenBody        = VisitStatement(node.Body);

            Debug.Assert(rewrittenBody is { });
Example #10
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     AddAll(node.OuterLocals);
     this.Visit(node.Initializer);
     AddAll(node.InnerLocals);
     this.Visit(node.Condition);
     this.Visit(node.Increment);
     this.Visit(node.Body);
     RemoveAll(node.InnerLocals);
     RemoveAll(node.OuterLocals);
     return(null);
 }
Example #11
0
        internal override BoundForStatement BindForParts(DiagnosticBag diagnostics)
        {
            BoundForStatement result = BindForParts(syntax, diagnostics);

            var initializationBinder = (ForLoopInitializationBinder)this.Next;

            if (!initializationBinder.Locals.IsDefaultOrEmpty)
            {
                result = result.Update(initializationBinder.Locals,
                                       result.Initializer,
                                       result.InnerLocals,
                                       result.Condition,
                                       result.Increment,
                                       result.Body,
                                       result.BreakLabel,
                                       result.ContinueLabel);
            }

            return(result);
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition   = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement   = (BoundStatement)Visit(node.Increment);
            var rewrittenBody        = (BoundStatement)Visit(node.Body);

            return(RewriteForStatement(
                       node.Syntax,
                       node.OuterLocals,
                       rewrittenInitializer,
                       AddConditionSequencePoint(rewrittenCondition, node),
                       node.Condition?.Syntax,
                       default(TextSpan),
                       rewrittenIncrement,
                       rewrittenBody,
                       node.BreakLabel,
                       node.ContinueLabel, node.HasErrors));
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement = (BoundStatement)Visit(node.Increment);
            var rewrittenBody = (BoundStatement)Visit(node.Body);

            return RewriteForStatement(
                node.Syntax,
                node.OuterLocals,
                rewrittenInitializer,
                AddConditionSequencePoint(rewrittenCondition, node),
                node.Condition?.Syntax,
                default(TextSpan),
                rewrittenIncrement,
                rewrittenBody,
                node.BreakLabel,
                node.ContinueLabel, node.HasErrors);
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement = (BoundStatement)Visit(node.Increment);
            var rewrittenBody = (BoundStatement)Visit(node.Body);

            SyntaxNodeOrToken conditionSyntax = ((BoundNode)rewrittenCondition ?? node).Syntax;

            return RewriteForStatement(
                node.Syntax,
                node.Locals,
                rewrittenInitializer,
                rewrittenCondition,
                conditionSyntax,
                rewrittenIncrement,
                rewrittenBody,
                node.BreakLabel,
                node.ContinueLabel, node.HasErrors);
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition   = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement   = (BoundStatement)Visit(node.Increment);
            var rewrittenBody        = (BoundStatement)Visit(node.Body);

            SyntaxNodeOrToken conditionSyntax = ((BoundNode)rewrittenCondition ?? node).Syntax;

            return(RewriteForStatement(
                       node.Syntax,
                       node.Locals,
                       rewrittenInitializer,
                       rewrittenCondition,
                       conditionSyntax,
                       rewrittenIncrement,
                       rewrittenBody,
                       node.BreakLabel,
                       node.ContinueLabel, node.HasErrors));
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement = (BoundStatement)Visit(node.Increment);
            var rewrittenBody = (BoundStatement)Visit(node.Body);

            // EnC: We need to insert a hidden sequence point to handle function remapping in case 
            // the containing method is edited while methods invoked in the condition are being executed.
            return RewriteForStatement(
                node.Syntax,
                node.OuterLocals,
                rewrittenInitializer,
                AddConditionSequencePoint(rewrittenCondition, node),
                node.Condition?.Syntax,
                default(TextSpan),
                rewrittenIncrement,
                rewrittenBody,
                node.BreakLabel,
                node.ContinueLabel, node.HasErrors);
        }
        public override BoundNode VisitForStatement(BoundForStatement node)
        {
            Debug.Assert(node != null);

            var rewrittenInitializer = (BoundStatement)Visit(node.Initializer);
            var rewrittenCondition   = (BoundExpression)Visit(node.Condition);
            var rewrittenIncrement   = (BoundStatement)Visit(node.Increment);
            var rewrittenBody        = (BoundStatement)Visit(node.Body);

            // EnC: We need to insert a hidden sequence point to handle function remapping in case
            // the containing method is edited while methods invoked in the condition are being executed.
            return(RewriteForStatement(
                       node.Syntax,
                       node.OuterLocals,
                       rewrittenInitializer,
                       AddConditionSequencePoint(rewrittenCondition, node),
                       node.Condition?.Syntax,
                       default(TextSpan),
                       rewrittenIncrement,
                       rewrittenBody,
                       node.BreakLabel,
                       node.ContinueLabel, node.HasErrors));
        }
Example #18
0
 public override BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     return Previous.InstrumentForStatementCondition(original, rewrittenCondition, factory);
 }
Example #19
0
 public override BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     // EnC: We need to insert a hidden sequence point to handle function remapping in case 
     // the containing method is edited while methods invoked in the condition are being executed.
     return AddConditionSequencePoint(base.InstrumentForStatementCondition(original, rewrittenCondition, factory), original.Syntax, factory);
 }
Example #20
0
 public override BoundStatement InstrumentForStatementConditionalGotoStart(BoundForStatement original, BoundStatement branchBack)
 {
     // hidden sequence point if there is no condition
     return new BoundSequencePoint(original.Condition?.Syntax, 
                                   base.InstrumentForStatementConditionalGotoStart(original, branchBack));
 }
Example #21
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return ForStatementCreateGotoEndSequencePoint(base.InstrumentForStatementGotoEnd(original, gotoEnd));
 }
Example #22
0
 public virtual BoundStatement InstrumentForStatementConditionalGotoStart(BoundForStatement original, BoundStatement branchBack)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return branchBack;
 }
Example #23
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     if (IsInside)
     {
         _labelsInside.Add(node.BreakLabel);
         _labelsInside.Add(node.ContinueLabel);
     }
     return base.VisitForStatement(node);
 }
        private BoundStatement RewriteForStatement(
            BoundForStatement node,
            BoundStatement rewrittenInitializer,
            BoundExpression rewrittenCondition,
            BoundStatement rewrittenIncrement,
            BoundStatement rewrittenBody)
        {
            if (node.InnerLocals.IsEmpty)
            {
                return RewriteForStatementWithoutInnerLocals(
                    node,
                    node.OuterLocals,
                    rewrittenInitializer,
                    rewrittenCondition,
                    rewrittenIncrement,
                    rewrittenBody,
                    node.BreakLabel,
                    node.ContinueLabel, node.HasErrors);
            }

            // We need to enter inner_scope-block from the top, that is where an instance of a display class will be created
            // if any local is captured within a lambda.

            // for (initializer; condition; increment)
            //   body;
            //
            // becomes the following (with block added for locals)
            //
            // {
            //   initializer;
            // start:
            //   {
            //     GotoIfFalse condition break;
            //     body;
            // continue:
            //     increment;
            //     goto start;
            //   }
            // break:
            // }

            Debug.Assert(rewrittenBody != null);

            SyntaxNode syntax = node.Syntax;
            var statementBuilder = ArrayBuilder<BoundStatement>.GetInstance();

            //  initializer;
            if (rewrittenInitializer != null)
            {
                statementBuilder.Add(rewrittenInitializer);
            }

            var startLabel = new GeneratedLabelSymbol("start");

            // start:
            BoundStatement startLabelStatement = new BoundLabelStatement(syntax, startLabel);

            if (Instrument)
            {
                startLabelStatement = new BoundSequencePoint(null, startLabelStatement);
            }

            statementBuilder.Add(startLabelStatement);

            var blockBuilder = ArrayBuilder<BoundStatement>.GetInstance();

            // GotoIfFalse condition break;
            if (rewrittenCondition != null)
            {
                BoundStatement ifNotConditionGotoBreak = new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, false, node.BreakLabel);

                if (this.Instrument)
                {
                    ifNotConditionGotoBreak = _instrumenter.InstrumentForStatementConditionalGotoStartOrBreak(node, ifNotConditionGotoBreak);
                }

                blockBuilder.Add(ifNotConditionGotoBreak);
            }

            // body;
            blockBuilder.Add(rewrittenBody);

            // continue:
            //   increment;
            blockBuilder.Add(new BoundLabelStatement(syntax, node.ContinueLabel));
            if (rewrittenIncrement != null)
            {
                blockBuilder.Add(rewrittenIncrement);
            }

            // goto start;
            blockBuilder.Add(new BoundGotoStatement(syntax, startLabel));

            statementBuilder.Add(new BoundBlock(syntax, node.InnerLocals, blockBuilder.ToImmutableAndFree()));

            // break:
            statementBuilder.Add(new BoundLabelStatement(syntax, node.BreakLabel));

            var statements = statementBuilder.ToImmutableAndFree();
            return new BoundBlock(syntax, node.OuterLocals, statements, node.HasErrors);
        }
Example #25
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return(ForStatementCreateGotoEndSequencePoint(base.InstrumentForStatementGotoEnd(original, gotoEnd)));
 }
Example #26
0
 public override BoundStatement InstrumentForStatementConditionalGotoStart(BoundForStatement original, BoundStatement branchBack)
 {
     return Previous.InstrumentForStatementConditionalGotoStart(original, branchBack);
 }
        private BoundStatement RewriteForStatement(
            BoundForStatement node,
            BoundStatement rewrittenInitializer,
            BoundExpression rewrittenCondition,
            BoundStatement rewrittenIncrement,
            BoundStatement rewrittenBody)
        {
            if (node.InnerLocals.IsEmpty)
            {
                return(RewriteForStatementWithoutInnerLocals(
                           node,
                           node.OuterLocals,
                           rewrittenInitializer,
                           rewrittenCondition,
                           rewrittenIncrement,
                           rewrittenBody,
                           node.BreakLabel,
                           node.ContinueLabel, node.HasErrors));
            }

            // We need to enter inner_scope-block from the top, that is where an instance of a display class will be created
            // if any local is captured within a lambda.

            // for (initializer; condition; increment)
            //   body;
            //
            // becomes the following (with block added for locals)
            //
            // {
            //   initializer;
            // start:
            //   {
            //     GotoIfFalse condition break;
            //     body;
            // continue:
            //     increment;
            //     goto start;
            //   }
            // break:
            // }

            Debug.Assert(rewrittenBody != null);

            SyntaxNode syntax           = node.Syntax;
            var        statementBuilder = ArrayBuilder <BoundStatement> .GetInstance();

            //  initializer;
            if (rewrittenInitializer != null)
            {
                statementBuilder.Add(rewrittenInitializer);
            }

            var startLabel = new GeneratedLabelSymbol("start");

            // start:
            BoundStatement startLabelStatement = new BoundLabelStatement(syntax, startLabel);

            if (Instrument)
            {
                startLabelStatement = new BoundSequencePoint(null, startLabelStatement);
            }

            statementBuilder.Add(startLabelStatement);

            var blockBuilder = ArrayBuilder <BoundStatement> .GetInstance();

            // GotoIfFalse condition break;
            if (rewrittenCondition != null)
            {
                BoundStatement ifNotConditionGotoBreak = new BoundConditionalGoto(rewrittenCondition.Syntax, rewrittenCondition, false, node.BreakLabel);

                if (this.Instrument)
                {
                    ifNotConditionGotoBreak = _instrumenter.InstrumentForStatementConditionalGotoStartOrBreak(node, ifNotConditionGotoBreak);
                }

                blockBuilder.Add(ifNotConditionGotoBreak);
            }

            // body;
            blockBuilder.Add(rewrittenBody);

            // continue:
            //   increment;
            blockBuilder.Add(new BoundLabelStatement(syntax, node.ContinueLabel));
            if (rewrittenIncrement != null)
            {
                blockBuilder.Add(rewrittenIncrement);
            }

            // goto start;
            blockBuilder.Add(new BoundGotoStatement(syntax, startLabel));

            statementBuilder.Add(new BoundBlock(syntax, node.InnerLocals, blockBuilder.ToImmutableAndFree()));

            // break:
            statementBuilder.Add(new BoundLabelStatement(syntax, node.BreakLabel));

            var statements = statementBuilder.ToImmutableAndFree();

            return(new BoundBlock(syntax, node.OuterLocals, statements, node.HasErrors));
        }
Example #28
0
 public override BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     // EnC: We need to insert a hidden sequence point to handle function remapping in case
     // the containing method is edited while methods invoked in the condition are being executed.
     return(AddConditionSequencePoint(base.InstrumentForStatementCondition(original, rewrittenCondition, factory), original.Syntax, factory));
 }
Example #29
0
 public virtual BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     Debug.Assert(factory != null);
     return rewrittenCondition;
 }
Example #30
0
 public virtual BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return(gotoEnd);
 }
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     throw ExceptionUtilities.Unreachable; // for statements have been lowered away by now
 }
Example #32
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return(Previous.InstrumentForStatementGotoEnd(original, gotoEnd));
 }
Example #33
0
 public override BoundStatement InstrumentForStatementConditionalGotoStart(BoundForStatement original, BoundStatement branchBack)
 {
     // hidden sequence point if there is no condition
     return(new BoundSequencePoint(original.Condition?.Syntax,
                                   base.InstrumentForStatementConditionalGotoStart(original, branchBack)));
 }
Example #34
0
 public virtual BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return gotoEnd;
 }
Example #35
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     throw ExceptionUtilities.Unreachable; // for statements have been lowered away by now
 }
Example #36
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return Previous.InstrumentForStatementGotoEnd(original, gotoEnd);
 }