Пример #1
0
        private void GenerateDoLoop(LoopStatementAst loopStatement)
        {
            Block continueTarget = new Block();
            Block next           = new Block();
            Block breakTarget    = new Block();
            Block block4         = new Block();

            this._loopTargets.Add(new LoopGotoTargets(loopStatement.Label ?? "", breakTarget, continueTarget));
            this._currentBlock.FlowsTo(next);
            this._currentBlock = next;
            loopStatement.Body.Accept(this);
            this._currentBlock.FlowsTo(continueTarget);
            this._currentBlock = continueTarget;
            loopStatement.Condition.Accept(this);
            this._currentBlock.FlowsTo(breakTarget);
            this._currentBlock.FlowsTo(block4);
            this._currentBlock = block4;
            this._currentBlock.FlowsTo(next);
            this._currentBlock = breakTarget;
            this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
        }
        internal void GenerateDoLoop(LoopStatementAst loopStatement)
        {
            // We model the flow graph like this:
            //    :RepeatTarget
            //       loop body
            //       // break -> goto BreakTarget
            //       // continue -> goto ContinueTarget
            //    :ContinueTarget
            //    if (condition)
            //    {
            //        goto RepeatTarget
            //    }
            //    :BreakTarget

            var continueBlock = new Block();
            var bodyBlock = new Block();
            var breakBlock = new Block();
            var gotoRepeatTargetBlock = new Block();

            _loopTargets.Add(new LoopGotoTargets(loopStatement.Label ?? "", breakBlock, continueBlock));

            _currentBlock.FlowsTo(bodyBlock);
            _currentBlock = bodyBlock;

            loopStatement.Body.Visit(this.Decorator);

            _currentBlock.FlowsTo(continueBlock);
            _currentBlock = continueBlock;

            loopStatement.Condition.Visit(this.Decorator);

            _currentBlock.FlowsTo(breakBlock);
            _currentBlock.FlowsTo(gotoRepeatTargetBlock);

            _currentBlock = gotoRepeatTargetBlock;
            _currentBlock.FlowsTo(bodyBlock);

            _currentBlock = breakBlock;

            _loopTargets.RemoveAt(_loopTargets.Count - 1);
        }
Пример #3
0
        private Expression GenerateDoLoop(LoopStatementAst loopStatement)
        {
            // Generate code like:
            //    :RepeatTarget
            //    try {
            //       loop body
            //       // break -> goto BreakTarget
            //       // continue -> goto TestBlock
            //    } catch (BreakException be) {
            //        if (be.MatchLabel(loopLabel))
            //             goto BreakTarget;
            //        throw;
            //    } catch (ContinueException ce) {
            //        if (ce.MatchLabel(loopLabel))
            //            goto ContinueTarget;
            //        throw;
            //    }
            //    :ContinueTarget
            //    if (condition)
            //    {
            //        goto RepeatTarget
            //    }
            //    :BreakTarget

            int preStmtCount = _stmtCount;

            string loopLabel = loopStatement.Label;
            var exprs = new List<Expression>();
            var repeatLabel = Expression.Label(!string.IsNullOrEmpty(loopLabel) ? loopLabel : null);
            var continueLabel = Expression.Label(!string.IsNullOrEmpty(loopLabel) ? loopLabel + "Continue" : "continue");
            var breakLabel = Expression.Label(!string.IsNullOrEmpty(loopLabel) ? loopLabel + "Break" : "break");
            var enterLoopExpression = new EnterLoopExpression();

            exprs.Add(Expression.Label(repeatLabel));
            exprs.Add(enterLoopExpression);

            _loopTargets.Add(new LoopGotoTargets(loopLabel ?? "", breakLabel, continueLabel));
            _generatingWhileOrDoLoop = true;
            var loopBodyExprs = new List<Expression>
                                    {
                                    s_callCheckForInterrupts,
                                    Compile(loopStatement.Body),
                                    ExpressionCache.Empty
                                };
            _generatingWhileOrDoLoop = false;
            _loopTargets.RemoveAt(_loopTargets.Count - 1);

            exprs.Add(Expression.TryCatch(Expression.Block(loopBodyExprs),
                                          GenerateLoopBreakContinueCatchBlocks(loopLabel, breakLabel, continueLabel)));
            exprs.Add(Expression.Label(continueLabel));
            var test = CaptureStatementResults(loopStatement.Condition, CaptureAstContext.Condition).Convert(typeof(bool));
            if (loopStatement is DoUntilStatementAst)
            {
                test = Expression.Not(test);
            }
            exprs.Add(Expression.IfThen(test, Expression.Goto(repeatLabel)));
            exprs.Add(Expression.Label(breakLabel));

            enterLoopExpression.LoopStatementCount = _stmtCount - preStmtCount;
            return enterLoopExpression.Loop = new PowerShellLoopExpression(exprs);
        }
Пример #4
0
 private void GenerateDoLoop(LoopStatementAst loopStatement)
 {
     Block continueTarget = new Block();
     Block next = new Block();
     Block breakTarget = new Block();
     Block block4 = new Block();
     this._loopTargets.Add(new LoopGotoTargets(loopStatement.Label ?? "", breakTarget, continueTarget));
     this._currentBlock.FlowsTo(next);
     this._currentBlock = next;
     loopStatement.Body.Accept(this);
     this._currentBlock.FlowsTo(continueTarget);
     this._currentBlock = continueTarget;
     loopStatement.Condition.Accept(this);
     this._currentBlock.FlowsTo(breakTarget);
     this._currentBlock.FlowsTo(block4);
     this._currentBlock = block4;
     this._currentBlock.FlowsTo(next);
     this._currentBlock = breakTarget;
     this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
 }
Пример #5
0
 private Expression GenerateDoLoop(LoopStatementAst loopStatement)
 {
     int num = this._stmtCount;
     string label = loopStatement.Label;
     List<Expression> exprs = new List<Expression>();
     LabelTarget target = Expression.Label(!string.IsNullOrEmpty(label) ? label : null);
     LabelTarget continueLabel = Expression.Label(!string.IsNullOrEmpty(label) ? (label + "Continue") : "continue");
     LabelTarget breakLabel = Expression.Label(!string.IsNullOrEmpty(label) ? (label + "Break") : "break");
     EnterLoopExpression item = new EnterLoopExpression();
     exprs.Add(Expression.Label(target));
     exprs.Add(item);
     this._loopTargets.Add(new LoopGotoTargets(label ?? "", breakLabel, continueLabel));
     List<Expression> expressions = new List<Expression> {
         _callCheckForInterrupts,
         this.Compile(loopStatement.Body),
         ExpressionCache.Empty
     };
     this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
     exprs.Add(Expression.TryCatch(Expression.Block(expressions), GenerateLoopBreakContinueCatchBlocks(label, breakLabel, continueLabel)));
     exprs.Add(Expression.Label(continueLabel));
     Expression expression = this.CaptureStatementResults(loopStatement.Condition, CaptureAstContext.Condition, null).Convert(typeof(bool));
     if (loopStatement is DoUntilStatementAst)
     {
         expression = Expression.Not(expression);
     }
     exprs.Add(Expression.IfThen(expression, Expression.Goto(target)));
     exprs.Add(Expression.Label(breakLabel));
     item.LoopStatementCount = this._stmtCount - num;
     return (item.Loop = new PowerShellLoopExpression(exprs));
 }