Example #1
0
 public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable<Tuple<ExpressionAst, StatementBlockAst>> clauses, StatementBlockAst @default)
     : base(extent, label, condition)
 {
     this.Flags = flags;
     this.Clauses = clauses.ToReadOnlyCollection();
     this.Default = @default;
 }
Example #2
0
 public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable <Tuple <ExpressionAst, StatementBlockAst> > clauses, StatementBlockAst @default)
     : base(extent, label, condition)
 {
     this.Flags   = flags;
     this.Clauses = clauses.ToReadOnlyCollection();
     this.Default = @default;
 }
Example #3
0
 public WhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body)
 {
     if (condition == null)
     {
         throw PSTraceSource.NewArgumentNullException("condition");
     }
 }
Example #4
0
 public DoUntilStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition, body)
 {
     if (condition == null)
     {
         throw PSTraceSource.NewArgumentNullException("condition");
     }
 }
Example #5
0
 public ReturnStatementAst(IScriptExtent extent, PipelineBaseAst pipeline) : base(extent)
 {
     if (pipeline != null)
     {
         this.Pipeline = pipeline;
         base.SetParent(pipeline);
     }
 }
Example #6
0
 public ExitStatementAst(IScriptExtent extent, PipelineBaseAst pipeline) : base(extent)
 {
     if (pipeline != null)
     {
         this.Pipeline = pipeline;
         base.SetParent(pipeline);
     }
 }
Example #7
0
 public ParenExpressionAst(IScriptExtent extent, PipelineBaseAst pipeline) : base(extent)
 {
     if (pipeline == null)
     {
         throw PSTraceSource.NewArgumentNullException("pipeline");
     }
     this.Pipeline = pipeline;
     base.SetParent(pipeline);
 }
Example #8
0
 public ParenExpressionAst(IScriptExtent extent, PipelineBaseAst pipeline) : base(extent)
 {
     if (pipeline == null)
     {
         throw PSTraceSource.NewArgumentNullException("pipeline");
     }
     this.Pipeline = pipeline;
     base.SetParent(pipeline);
 }
Example #9
0
 private void ControlFlowStatement(PipelineBaseAst pipelineAst)
 {
     if (pipelineAst != null)
     {
         pipelineAst.Accept(this);
     }
     this._currentBlock.FlowsTo(this._exitBlock);
     this._currentBlock = new Block();
 }
Example #10
0
 protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition)
 {
     if (body == null)
     {
         throw PSTraceSource.NewArgumentNullException("body");
     }
     this.Body = body;
     base.SetParent(body);
 }
Example #11
0
 protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body) : base(extent, label, condition)
 {
     if (body == null)
     {
         throw PSTraceSource.NewArgumentNullException("body");
     }
     this.Body = body;
     base.SetParent(body);
 }
Example #12
0
 public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body) : base(extent, label, expression, body)
 {
     if ((expression == null) || (variable == null))
     {
         throw PSTraceSource.NewArgumentNullException((expression == null) ? "expression" : "variablePath");
     }
     this.Flags = flags;
     this.Variable = variable;
     base.SetParent(variable);
 }
Example #13
0
 public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body) : base(extent, label, condition, body)
 {
     if (initializer != null)
     {
         this.Initializer = initializer;
         base.SetParent(initializer);
     }
     if (iterator != null)
     {
         this.Iterator = iterator;
         base.SetParent(iterator);
     }
 }
Example #14
0
 protected LabeledStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition) : base(extent)
 {
     if (string.IsNullOrWhiteSpace(label))
     {
         label = null;
     }
     this.Label = label;
     if (condition != null)
     {
         this.Condition = condition;
         base.SetParent(condition);
     }
 }
Example #15
0
 protected LabeledStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition) : base(extent)
 {
     if (string.IsNullOrWhiteSpace(label))
     {
         label = null;
     }
     this.Label = label;
     if (condition != null)
     {
         this.Condition = condition;
         base.SetParent(condition);
     }
 }
Example #16
0
 public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body) : base(extent, label, condition, body)
 {
     if (initializer != null)
     {
         this.Initializer = initializer;
         base.SetParent(initializer);
     }
     if (iterator != null)
     {
         this.Iterator = iterator;
         base.SetParent(iterator);
     }
 }
Example #17
0
 public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable <Tuple <ExpressionAst, StatementBlockAst> > clauses, StatementBlockAst @default) : base(extent, label, condition)
 {
     if (((clauses == null) || !clauses.Any <Tuple <ExpressionAst, StatementBlockAst> >()) && (@default == null))
     {
         throw PSTraceSource.NewArgumentException("clauses");
     }
     this.Flags   = flags;
     this.Clauses = new ReadOnlyCollection <Tuple <ExpressionAst, StatementBlockAst> >(((clauses != null) && clauses.Any <Tuple <ExpressionAst, StatementBlockAst> >()) ? ((IList <Tuple <ExpressionAst, StatementBlockAst> >)clauses.ToArray <Tuple <ExpressionAst, StatementBlockAst> >()) : ((IList <Tuple <ExpressionAst, StatementBlockAst> >)EmptyClauseArray));
     base.SetParents <ExpressionAst, StatementBlockAst>(this.Clauses);
     if (@default != null)
     {
         this.Default = @default;
         base.SetParent(@default);
     }
 }
Example #18
0
 public SwitchStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, SwitchFlags flags, IEnumerable<Tuple<ExpressionAst, StatementBlockAst>> clauses, StatementBlockAst @default) : base(extent, label, condition)
 {
     if (((clauses == null) || !clauses.Any<Tuple<ExpressionAst, StatementBlockAst>>()) && (@default == null))
     {
         throw PSTraceSource.NewArgumentException("clauses");
     }
     this.Flags = flags;
     this.Clauses = new ReadOnlyCollection<Tuple<ExpressionAst, StatementBlockAst>>(((clauses != null) && clauses.Any<Tuple<ExpressionAst, StatementBlockAst>>()) ? ((IList<Tuple<ExpressionAst, StatementBlockAst>>) clauses.ToArray<Tuple<ExpressionAst, StatementBlockAst>>()) : ((IList<Tuple<ExpressionAst, StatementBlockAst>>) EmptyClauseArray));
     base.SetParents<ExpressionAst, StatementBlockAst>(this.Clauses);
     if (@default != null)
     {
         this.Default = @default;
         base.SetParent(@default);
     }
 }
Example #19
0
 protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body)
     : base(extent, label, condition)
 {
     this.Body = body;
 }
Example #20
0
 public WhileStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body)
     : base(extent, label, condition, body)
 {
 }
Example #21
0
 protected LoopStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body)
     : base(extent, label, condition)
 {
     this.Body = body;
 }
Example #22
0
        private Block ControlFlowStatement(PipelineBaseAst pipelineAst)
        {
            if (pipelineAst != null)
            {
                pipelineAst.Accept(this);
            }
            _currentBlock.FlowsTo(_exitBlock);
            var lastBlockInStatement = _currentBlock;

            _currentBlock = new Block();

            return lastBlockInStatement;
        }
Example #23
0
 private Expression GenerateWhileLoop(string loopLabel, Func<Expression> generateCondition, Action<List<Expression>, LabelTarget, LabelTarget> generateLoopBody, PipelineBaseAst continueAst = null)
 {
     string str;
     string str1;
     string str2;
     LabelTarget labelTarget;
     int num = this._stmtCount;
     List<Expression> expressions = new List<Expression>();
     if (!string.IsNullOrEmpty(loopLabel))
     {
         str = string.Concat(loopLabel, "Continue");
     }
     else
     {
         str = "continue";
     }
     LabelTarget labelTarget1 = Expression.Label(str);
     if (!string.IsNullOrEmpty(loopLabel))
     {
         str1 = string.Concat(loopLabel, "Break");
     }
     else
     {
         str1 = "break";
     }
     LabelTarget labelTarget2 = Expression.Label(str1);
     EnterLoopExpression enterLoopExpression = new EnterLoopExpression();
     if (continueAst != null)
     {
         if (!string.IsNullOrEmpty(loopLabel))
         {
             str2 = string.Concat(loopLabel, "LoopTop");
         }
         else
         {
             str2 = "looptop";
         }
         labelTarget = Expression.Label(str2);
     }
     else
     {
         labelTarget = labelTarget1;
     }
     LabelTarget labelTarget3 = labelTarget;
     expressions.Add(Expression.Label(labelTarget3));
     expressions.Add(enterLoopExpression);
     List<Expression> expressions1 = new List<Expression>();
     expressions1.Add(Compiler._callCheckForInterrupts);
     List<Compiler.LoopGotoTargets> loopGotoTargets = this._loopTargets;
     string str3 = loopLabel;
     string str4 = str3;
     if (str3 == null)
     {
         str4 = "";
     }
     loopGotoTargets.Add(new Compiler.LoopGotoTargets(str4, labelTarget2, labelTarget1));
     generateLoopBody(expressions1, labelTarget2, labelTarget1);
     if (continueAst == null)
     {
         expressions1.Add(Expression.Goto(labelTarget3));
     }
     this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
     Expression expression = Expression.TryCatch(Expression.Block(expressions1), Compiler.GenerateLoopBreakContinueCatchBlocks(loopLabel, labelTarget2, labelTarget1));
     if (continueAst != null)
     {
         List<Expression> expressions2 = new List<Expression>();
         expressions2.Add(expression);
         expressions2.Add(Expression.Label(labelTarget1));
         if (continueAst.GetPureExpression() != null)
         {
             expressions2.Add(this.UpdatePosition(continueAst));
         }
         expressions2.Add(this.CaptureStatementResults(continueAst, Compiler.CaptureAstContext.Assignment, null));
         expressions2.Add(Expression.Goto(labelTarget3));
         expression = Expression.Block(expressions2);
     }
     if (generateCondition == null)
     {
         expressions.Add(expression);
     }
     else
     {
         expressions.Add(Expression.IfThen(generateCondition().Convert(typeof(bool)), expression));
     }
     expressions.Add(Expression.Label(labelTarget2));
     enterLoopExpression.LoopStatementCount = this._stmtCount - num;
     PowerShellLoopExpression powerShellLoopExpression = new PowerShellLoopExpression(expressions);
     PowerShellLoopExpression powerShellLoopExpression1 = powerShellLoopExpression;
     enterLoopExpression.Loop = powerShellLoopExpression;
     return powerShellLoopExpression1;
 }
Example #24
0
 public ReturnStatementAst(IScriptExtent extent, PipelineBaseAst pipeline)
     : base(extent)
 {
     this.Pipeline = pipeline;
 }
Example #25
0
        private AstVisitAction VisitSimpleLoopStatement(StatementBlockAst body, PipelineBaseAst condition,
                                                    bool preExecuteBody, bool invertCond)
        {
            // TODO: pass loop label
            // preExecuteBody is for do while/until loops
            if (preExecuteBody && !EvaluateLoopBodyAst(body, null))
            {
                return AstVisitAction.SkipChildren;
            }

            // the condition is XORed with invertCond and menas: (true && !invertCond) || (false && invertCond)
            while (LanguagePrimitives.ConvertTo<bool>(EvaluateAst(condition)) ^ invertCond)
            {
                if (!EvaluateLoopBodyAst(body, null))
                {
                    break;
                }
            }
            return AstVisitAction.SkipChildren;
        }
        internal Block ControlFlowStatement(PipelineBaseAst pipelineAst)
        {
            if (pipelineAst != null)
            {
                pipelineAst.Visit(this.Decorator);
            }
            _currentBlock.FlowsTo(_exitBlock);
            var lastBlockInStatement = _currentBlock;

            // The next block is unreachable, but is necessary to keep the flow graph correct.
            _currentBlock = new Block();
            return lastBlockInStatement;
        }
Example #27
0
 public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body) : base(extent, label, expression, body)
 {
     if ((expression == null) || (variable == null))
     {
         throw PSTraceSource.NewArgumentNullException((expression == null) ? "expression" : "variablePath");
     }
     this.Flags    = flags;
     this.Variable = variable;
     base.SetParent(variable);
 }
Example #28
0
 public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body)
     : base(extent, label, expression, body)
 {
     this.Flags = flags;
     this.Variable = variable;
 }
Example #29
0
 protected LabeledStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition)
     : base(extent)
 {
     this.Label     = label;
     this.Condition = condition;
 }
Example #30
0
 protected LabeledStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition)
     : base(extent)
 {
     this.Label = label;
     this.Condition = condition;
 }
Example #31
0
 public ParenExpressionAst(IScriptExtent extent, PipelineBaseAst pipeline)
     : base(extent)
 {
     this.Pipeline = pipeline;
 }
Example #32
0
 public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body)
     : base(extent, label, condition, body)
 {
     this.Initializer = initializer;
     this.Iterator    = iterator;
 }
Example #33
0
 public ThrowStatementAst(IScriptExtent extent, PipelineBaseAst pipeline)
     : base(extent)
 {
     this.Pipeline = pipeline;
 }
Example #34
0
 public ForEachStatementAst(IScriptExtent extent, string label, ForEachFlags flags, VariableExpressionAst variable, PipelineBaseAst expression, StatementBlockAst body)
     : base(extent, label, expression, body)
 {
     this.Flags    = flags;
     this.Variable = variable;
 }
Example #35
0
 public ParenExpressionAst(IScriptExtent extent, PipelineBaseAst pipeline)
     : base(extent)
 {
     this.Pipeline = pipeline;
 }
Example #36
0
 public DoUntilStatementAst(IScriptExtent extent, string label, PipelineBaseAst condition, StatementBlockAst body)
     : base(extent, label, condition, body)
 {
 }
Example #37
0
        private Expression GenerateWhileLoop(string loopLabel,
                                             Func<Expression> generateCondition,
                                             Action<List<Expression>, LabelTarget, LabelTarget> generateLoopBody,
                                             PipelineBaseAst continueAst = null)
        {
            // If continueAst is not null, generate:
            //    LoopTop:
            //    if (condition)
            //    {
            //        try {
            //            loop body
            //            // break -> goto BreakTarget
            //            // continue -> goto ContinueTarget
            //        } catch (BreakException be) {
            //            if (be.MatchLabel(loopLabel)) goto BreakTarget;
            //            throw;
            //        } catch (ContinueException ce) {
            //            if (ce.MatchLabel(loopLabel)) goto ContinueTarget;
            //            throw;
            //        }
            //    ContinueTarget:
            //            continueAction
            //            goto LoopTop:
            //    }
            //    :BreakTarget
            //
            // If continueAst is null, generate:
            //    ContinueTarget:
            //    if (condition)
            //    {
            //        try {
            //            loop body
            //            // break -> goto BreakTarget
            //            // continue -> goto ContinueTarget
            //            goto ContinueTarget
            //        } catch (BreakException be) {
            //            if (be.MatchLabel(loopLabel)) goto BreakTarget;
            //            throw;
            //        } catch (ContinueException ce) {
            //            if (ce.MatchLabel(loopLabel)) goto ContinueTarget;
            //            throw;
            //        }
            //    }
            //    :BreakTarget

            int preStmtCount = _stmtCount;

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

            var loopTop = (continueAst != null)
                              ? Expression.Label(!string.IsNullOrEmpty(loopLabel) ? loopLabel + "LoopTop" : "looptop")
                              : continueLabel;

            exprs.Add(Expression.Label(loopTop));
            exprs.Add(enterLoop);

            var loopBodyExprs = new List<Expression>();
            loopBodyExprs.Add(s_callCheckForInterrupts);

            _loopTargets.Add(new LoopGotoTargets(loopLabel ?? "", breakLabel, continueLabel));
            _generatingWhileOrDoLoop = true;
            generateLoopBody(loopBodyExprs, breakLabel, continueLabel);
            _generatingWhileOrDoLoop = false;
            if (continueAst == null)
            {
                loopBodyExprs.Add(Expression.Goto(loopTop));
            }
            _loopTargets.RemoveAt(_loopTargets.Count - 1);

            Expression loopBody =
                Expression.TryCatch(Expression.Block(loopBodyExprs),
                                    GenerateLoopBreakContinueCatchBlocks(loopLabel, breakLabel, continueLabel));
            if (continueAst != null)
            {
                var x = new List<Expression>();
                x.Add(loopBody);
                x.Add(Expression.Label(continueLabel));
                if (continueAst.GetPureExpression() != null)
                {
                    // Assignments generate the code to update the position automatically,
                    // but pre/post increments don't, so we add it here explicitly.
                    x.Add(UpdatePosition(continueAst));
                }
                // We should not preserve the partial output if exception is thrown when evaluating the continueAst.
                x.Add(CaptureStatementResults(continueAst, CaptureAstContext.AssignmentWithoutResultPreservation));
                x.Add(Expression.Goto(loopTop));
                loopBody = Expression.Block(x);
            }

            if (generateCondition != null)
            {
                exprs.Add(Expression.IfThen(generateCondition().Convert(typeof(bool)), loopBody));
            }
            else
            {
                exprs.Add(loopBody);
            }
            exprs.Add(Expression.Label(breakLabel));
            enterLoop.LoopStatementCount = _stmtCount - preStmtCount;
            return (enterLoop.Loop = new PowerShellLoopExpression(exprs));
        }
Example #38
0
 public ForStatementAst(IScriptExtent extent, string label, PipelineBaseAst initializer, PipelineBaseAst condition, PipelineBaseAst iterator, StatementBlockAst body)
     : base(extent, label, condition, body)
 {
     this.Initializer = initializer;
     this.Iterator = iterator;
 }
Example #39
0
 private void ControlFlowStatement(PipelineBaseAst pipelineAst)
 {
     if (pipelineAst != null)
     {
         pipelineAst.Accept(this);
     }
     this._currentBlock.FlowsTo(this._exitBlock);
     this._currentBlock = new Block();
 }