Example #1
0
    public System.Object VisitForStatement(System.Management.Automation.Language.ForStatementAst forStatementAst)
    {
        IScriptExtent mappedExtent = MapExtent(forStatementAst.Extent);

        PipelineBaseAst   mappedInitializer = _VisitPipelineBase(forStatementAst.Initializer);
        PipelineBaseAst   mappedCondition   = _VisitPipelineBase(forStatementAst.Condition);
        PipelineBaseAst   mappedIterator    = _VisitPipelineBase(forStatementAst.Iterator);
        StatementBlockAst mappedBody        = (StatementBlockAst)VisitStatementBlock(forStatementAst.Body);


        return(new ForStatementAst(mappedExtent, forStatementAst.Label, mappedInitializer, mappedCondition, mappedIterator, mappedBody));
    }
Example #2
0
        public object VisitForStatement(ForStatementAst forStatementAst)
        {
            if (forStatementAst.Initializer != null)
            {
                forStatementAst.Initializer.Accept(this);
            }
            Action generateCondition = null;

            if (forStatementAst.Condition != null)
            {
                generateCondition = delegate
                {
                    forStatementAst.Condition.Accept(this);
                };
            }
            this.GenerateWhileLoop(forStatementAst.Label, generateCondition, delegate {
                forStatementAst.Body.Accept(this);
            }, forStatementAst.Iterator);
            return(null);
        }
Example #3
0
 public override AstVisitAction VisitForStatement(ForStatementAst ast) { return CheckParent(ast); }
Example #4
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     return(false);
 }
Example #5
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Example #6
0
 public override AstVisitAction VisitForStatement(ForStatementAst ast)
 {
     return(Check(ast));
 }
Example #7
0
        public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
        {
            /*
             * The controlling expression for-condition must have type bool or
             * be implicitly convertible to that type. The loop body, which
             * consists of statement-block, is executed repeatedly while the
             * controlling expression tests True. The controlling expression
             * is evaluated before each execution of the loop body.
             *
             * Expression for-initializer is evaluated before the first
             * evaluation of the controlling expression. Expression
             * for-initializer is evaluated for its side effects only; any
             * value it produces is discarded and is not written to the
             * pipeline.
             *
             * Expression for-iterator is evaluated after each execution of
             * the loop body. Expression for-iterator is evaluated for its
             * side effects only; any value it produces is discarded and is
             * not written to the pipeline.
             *
             * If expression for-condition is omitted, the controlling
             * expression tests True.
             */

            EvaluateAst(forStatementAst.Initializer);

            while ((bool)((PSObject)EvaluateAst(forStatementAst.Condition)).BaseObject)
            {
                this._pipelineCommandRuntime.WriteObject(EvaluateAst(forStatementAst.Body), true);
                EvaluateAst(forStatementAst.Iterator);
            }

            return AstVisitAction.SkipChildren;
        }
Example #8
0
        public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
        {
            /*
             * The controlling expression for-condition must have type bool or 
             * be implicitly convertible to that type. The loop body, which 
             * consists of statement-block, is executed repeatedly while the 
             * controlling expression tests True. The controlling expression 
             * is evaluated before each execution of the loop body.
             * 
             * Expression for-initializer is evaluated before the first 
             * evaluation of the controlling expression. Expression 
             * for-initializer is evaluated for its side effects only; any 
             * value it produces is discarded and is not written to the 
             * pipeline.
             * 
             * Expression for-iterator is evaluated after each execution of 
             * the loop body. Expression for-iterator is evaluated for its 
             * side effects only; any value it produces is discarded and is 
             * not written to the pipeline.
             * 
             * If expression for-condition is omitted, the controlling 
             * expression tests True.
             */

            if (forStatementAst.Initializer != null)
            {
                EvaluateAst(forStatementAst.Initializer);
            }

            while (forStatementAst.Condition != null ?
                      LanguagePrimitives.ConvertTo<bool>(EvaluateAst(forStatementAst.Condition))
                    : true)
            {
                // TODO: pass loop label
                if (!EvaluateLoopBodyAst(forStatementAst.Body, null))
                {
                    break;
                }
                if (forStatementAst.Iterator != null)
                {
                    EvaluateAst(forStatementAst.Iterator);
                }
            }

            return AstVisitAction.SkipChildren;
        }
 public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
 {
     this.ReportError(forStatementAst, () => ParserStrings.ForWhileStatementNotSupportedInDataSection, new object[0]);
     return(AstVisitAction.Continue);
 }
 public object VisitForStatement(ForStatementAst forStatementAst) { throw new UnexpectedElementException(); }
Example #11
0
 /// <summary/>
 public virtual AstVisitAction VisitForStatement(ForStatementAst forStatementAst) => DefaultVisit(forStatementAst);
Example #12
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     Expression expression = (forStatementAst.Initializer != null) ? this.CaptureStatementResults(forStatementAst.Initializer, CaptureAstContext.Assignment, null) : null;
     Func<Expression> generateCondition = null;
     if (forStatementAst.Condition != null)
     {
         generateCondition = () => Expression.Block(this.UpdatePosition(forStatementAst.Condition), this.CaptureStatementResults(forStatementAst.Condition, CaptureAstContext.Condition, null));
     }
     Expression expression2 = this.GenerateWhileLoop(forStatementAst.Label, generateCondition, delegate (List<Expression> loopBody, LabelTarget breakTarget, LabelTarget continueTarget) {
         loopBody.Add(this.Compile(forStatementAst.Body));
     }, forStatementAst.Iterator);
     if (expression != null)
     {
         return Expression.Block(expression, expression2);
     }
     return expression2;
 }
Example #13
0
 public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst) { return AstVisitAction.SkipChildren; }
Example #14
0
 /// <summary/>
 public virtual object VisitForStatement(ForStatementAst forStatementAst) { return null; }
        /// <summary>
        /// Visit for statement
        /// </summary>
        /// <param name="forStatementAst"></param>
        /// <returns></returns>
        public object VisitForStatement(ForStatementAst forStatementAst)
        {
            if (forStatementAst == null) return null;

            if (forStatementAst.Initializer != null)
            {
                forStatementAst.Initializer.Visit(this.Decorator);
            }

            var generateCondition = forStatementAst.Condition != null
                ? () => forStatementAst.Condition.Visit(this.Decorator)
                : (Action)null;

            GenerateWhileLoop(forStatementAst.Label, generateCondition, () => forStatementAst.Body.Visit(this.Decorator),
                              forStatementAst.Iterator);
            return null;
        }
 /// <summary/>
 public virtual object VisitForStatement(ForStatementAst forStatementAst)
 {
     return _decorated.VisitForStatement(forStatementAst);
 }
Example #17
0
 public override AstVisitAction VisitForStatement(ForStatementAst ast)
 {
     return this.Check(ast);
 }
Example #18
0
 public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
 {
     throw new NotImplementedException(); //VisitForStatement(forStatementAst);
 }
Example #19
0
 public object VisitForStatement(ForStatementAst forStatementAst) { return AutomationNull.Value; }
Example #20
0
 public virtual AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
 {
     return AstVisitAction.Continue;
 }
Example #21
0
 public object VisitForStatement(ForStatementAst forStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
Example #22
0
 /// <summary/>
 public virtual object VisitForStatement(ForStatementAst forStatementAst)
 {
     return(null);
 }
Example #23
0
        public object VisitForStatement(ForStatementAst forStatementAst)
        {
            // We should not preserve the partial output if exception is thrown when evaluating the initializer.
            var init = (forStatementAst.Initializer != null)
                           ? CaptureStatementResults(forStatementAst.Initializer, CaptureAstContext.AssignmentWithoutResultPreservation)
                           : null;

            var generateCondition = forStatementAst.Condition != null
                ? () => Expression.Block(UpdatePosition(forStatementAst.Condition),
                                         CaptureStatementResults(forStatementAst.Condition, CaptureAstContext.Condition))
                : (Func<Expression>)null;

            var loop = GenerateWhileLoop(forStatementAst.Label, generateCondition,
                                         (loopBody, breakTarget, continueTarget) => loopBody.Add(Compile(forStatementAst.Body)),
                                         forStatementAst.Iterator);

            if (init != null)
            {
                return Expression.Block(init, loop);
            }
            return loop;
        }
Example #24
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     return false;
 }
 public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
 {
     this.ReportError(forStatementAst, () => ParserStrings.ForWhileStatementNotSupportedInDataSection, new object[0]);
     return AstVisitAction.Continue;
 }
Example #26
0
 /// <summary/>
 public virtual AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
 {
     return(AstVisitAction.Continue);
 }
Example #27
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     if (forStatementAst.Initializer != null)
     {
         forStatementAst.Initializer.Accept(this);
     }
     Action generateCondition = null;
     if (forStatementAst.Condition != null) 
     {
         generateCondition = delegate
         {
             forStatementAst.Condition.Accept(this);
         };
     }
     this.GenerateWhileLoop(forStatementAst.Label, generateCondition, delegate {
         forStatementAst.Body.Accept(this);
     }, forStatementAst.Iterator);
     return null;
 }
Example #28
0
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     return(AutomationNull.Value);
 }
 public object VisitForStatement(ForStatementAst forStatementAst)
 {
     throw new NotImplementedException();
 }