예제 #1
0
        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));
        }
예제 #2
0
 public override BoundStatement InstrumentForStatementConditionalGotoStartOrBreak(
     BoundForStatement original,
     BoundStatement branchBack
     )
 {
     return(Previous.InstrumentForStatementConditionalGotoStartOrBreak(original, branchBack));
 }
예제 #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);
 }
예제 #4
0
        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);
        }
예제 #5
0
 public override BoundExpression InstrumentForStatementCondition(
     BoundForStatement original,
     BoundExpression rewrittenCondition,
     SyntheticBoundNodeFactory factory
     )
 {
     return(Previous.InstrumentForStatementCondition(original, rewrittenCondition, factory));
 }
예제 #6
0
        internal override BoundForStatement BindForParts(
            BindingDiagnosticBag diagnostics,
            Binder originalBinder
            )
        {
            BoundForStatement result = BindForParts(_syntax, originalBinder, diagnostics);

            return(result);
        }
예제 #7
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     if (IsInside)
     {
         _labelsInside.Add(node.BreakLabel);
         _labelsInside.Add(node.ContinueLabel);
     }
     return(base.VisitForStatement(node));
 }
예제 #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 { });
예제 #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);
 }
예제 #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);
        }
예제 #12
0
        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);
        }
예제 #14
0
        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);
        }
예제 #17
0
        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));
        }
예제 #18
0
 public override BoundExpression InstrumentForStatementCondition(BoundForStatement original, BoundExpression rewrittenCondition, SyntheticBoundNodeFactory factory)
 {
     return Previous.InstrumentForStatementCondition(original, rewrittenCondition, factory);
 }
예제 #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);
 }
예제 #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));
 }
예제 #21
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return ForStatementCreateGotoEndSequencePoint(base.InstrumentForStatementGotoEnd(original, gotoEnd));
 }
예제 #22
0
 public virtual BoundStatement InstrumentForStatementConditionalGotoStart(BoundForStatement original, BoundStatement branchBack)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return branchBack;
 }
예제 #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);
        }
예제 #25
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return(ForStatementCreateGotoEndSequencePoint(base.InstrumentForStatementGotoEnd(original, gotoEnd)));
 }
예제 #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));
        }
예제 #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));
 }
예제 #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;
 }
예제 #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
 }
예제 #32
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return(Previous.InstrumentForStatementGotoEnd(original, gotoEnd));
 }
예제 #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)));
 }
예제 #34
0
 public virtual BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     Debug.Assert(!original.WasCompilerGenerated);
     Debug.Assert(original.Syntax.Kind() == SyntaxKind.ForStatement);
     return gotoEnd;
 }
예제 #35
0
 public override BoundNode VisitForStatement(BoundForStatement node)
 {
     throw ExceptionUtilities.Unreachable; // for statements have been lowered away by now
 }
예제 #36
0
 public override BoundStatement InstrumentForStatementGotoEnd(BoundForStatement original, BoundStatement gotoEnd)
 {
     return Previous.InstrumentForStatementGotoEnd(original, gotoEnd);
 }